Merge pull request #26 from unmtransinfo/Jack-42-patch-1 #4
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 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| version_tag: | |
| description: "Version tag (e.g., v1.0.0)" | |
| required: true | |
| default: "v1.0.0" | |
| env: | |
| IMAGE_NAME: unmtransinfo/cfchem_api | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract version tag | |
| id: version | |
| run: | | |
| if [ "${{ github.event_name }}" == "release" ]; then | |
| # Use the release tag (e.g., v1.0, 1.0.0, etc.) | |
| echo "VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT | |
| elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| # Use manually provided version | |
| echo "VERSION=${{ github.event.inputs.version_tag }}" >> $GITHUB_OUTPUT | |
| else | |
| # Generate version from date + commit SHA for regular pushes | |
| echo "VERSION=v$(date +%Y%m%d)-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: "{{defaultContext}}:app" | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: | | |
| ${{ env.IMAGE_NAME }}:latest | |
| ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }} | |
| - name: Image digest | |
| run: echo "Image pushed with tags latest and ${{ steps.version.outputs.VERSION }}" |