build-push-docker #12
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-push-docker | |
| env: | |
| DOCKER_BUILDKIT: 1 | |
| REGISTRY: ghcr.io | |
| on: workflow_dispatch | |
| jobs: | |
| next-build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| actions: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| - name: Check out | |
| uses: actions/checkout@v5 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3.6.0 | |
| - name: Extract version from package.json | |
| id: version | |
| run: | | |
| echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Github Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Check if image exists | |
| id: image-check | |
| run: | | |
| IMAGE_NAME=${{ env.REGISTRY }}/${{ github.repository }}:${{ steps.version.outputs.VERSION }} | |
| if docker manifest inspect $IMAGE_NAME >/dev/null 2>&1; then | |
| echo "portfolio-v2 image ${{ steps.version.outputs.VERSION }} already exists" | |
| echo "EXISTS=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "portfolio-v2 image ${{ steps.version.outputs.VERSION }} does not exist" | |
| echo "EXISTS=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build & Publish Docker Image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| push: true | |
| platforms: linux/amd64 | |
| cache-from: type=gha,scope=portfolio-v2 | |
| cache-to: type=gha,mode=max,scope=portfolio-v2 | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ github.repository }}:latest | |
| ${{ env.REGISTRY }}/${{ github.repository }}:${{ steps.version.outputs.VERSION }} |