Merge pull request #57 from TBosak/main #20
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 Images | |
| on: | |
| push: | |
| branches: [deploy] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Version tag (leave empty to use package.json version and tag as latest)" | |
| required: false | |
| type: string | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: arm64 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: docker.io | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GHCR_TOKEN }} | |
| - name: Determine version and tags | |
| id: vars | |
| run: | | |
| if [ -n "${{ inputs.version }}" ]; then | |
| VERSION="${{ inputs.version }}" | |
| USE_LATEST="false" | |
| else | |
| VERSION=$(node -p "require('./package.json').version") | |
| USE_LATEST="true" | |
| fi | |
| TAGS="docker.io/tbosk/mkfd:${VERSION}"$'\n'"ghcr.io/tbosak/mkfd:${VERSION}" | |
| if [ "${USE_LATEST}" = "true" ]; then | |
| TAGS="$TAGS"$'\n'"docker.io/tbosk/mkfd:latest"$'\n'"ghcr.io/tbosak/mkfd:latest" | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "USE_LATEST=$USE_LATEST" >> $GITHUB_ENV | |
| echo "TAGS<<EOF" >> $GITHUB_ENV | |
| echo "$TAGS" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| echo "Building version: $VERSION (latest tag: $USE_LATEST)" | |
| echo "Docker tags:" | |
| echo "$TAGS" | |
| - name: Build and push multi-arch images to Docker Hub and GHCR | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ env.TAGS }} | |
| provenance: true | |
| network: host | |
| allow: network.host |