Merge pull request #1 from cloudsmithy/main #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Docker Image | |
| # ✅ 任何 push 都触发(如果只想 main 分支触发,就把 branches 列表写出来) | |
| on: | |
| push: # ← 去掉 tags 过滤器 | |
| branches: [main] # 想限定就取消注释 | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@v4 | |
| - name: Check DockerHub secrets | |
| run: | | |
| if [ -z "${{ secrets.DOCKER_USERNAME }}" ] || [ -z "${{ secrets.DOCKER_PASSWORD }}" ]; then | |
| echo "❌ ERROR: DOCKER_USERNAME or DOCKER_PASSWORD is missing" | |
| exit 1 | |
| fi | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| install: true | |
| - name: Docker login | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| # --- ① 生成镜像 tag:用提交短 SHA(7 位) --- | |
| - name: Set image tag | |
| run: echo "TAG=${GITHUB_SHA::7}" >> "$GITHUB_ENV" | |
| - name: Build & push multi-arch image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: | | |
| ${{ secrets.DOCKER_USERNAME }}/smart-shopping-app:latest | |
| # --- 若你只想保留 latest,可以直接去掉 TAG 相关步骤 --- |