bookbrainz/bookbrainz-site

View on GitHub
.github/workflows/push-prod-docker-image.yml

Summary

Maintainability
Test Coverage
# This workflow pushes a production image to Docker Hub
# whenever a Github release is published

name: Build and publish production image to Docker Hub

on:
  release:
    types: [published]

jobs:

  deploy:

    runs-on: ubuntu-latest

    steps:
      # Github stores the current tag in an enviroment variable (GITHUB_REF) in the format /refs/tags/TAG_NAME.
      # Using shell parameter expansion, we extract the TAG_NAME. Also, it seems we cannot use shell tricks
      # directly in the with block, so doing it in a separate step and then fetching its output when needed.
    - name: Get the tag name
      id: get_tag
      run: echo ::set-output name=TAG::${GITHUB_REF/refs\/tags\//}
    
    - name: Docker Setup Buildx
      uses: docker/setup-buildx-action@v1.6.0
      
    - name: Docker Login
      uses: docker/login-action@v1.14.1
      with:
        username: ${{ secrets.DOCKER_HUB_USERNAME }}
        password: ${{ secrets.DOCKER_HUB_PASSWORD }}
    
    - uses: satackey/action-docker-layer-caching@v0.0.11
      continue-on-error: true

    - name: Build and push Docker images
      uses: docker/build-push-action@v2.10.0
      with:
        build-args: |
          GIT_COMMIT_SHA=${{ steps.get_tag.outputs.TAG }}
          DEPLOY_ENV=prod
        cache-from: metabrainz/bookbrainz:cache
        cache-to: metabrainz/bookbrainz:cache
        push: true
        tags: metabrainz/bookbrainz:${{ steps.get_tag.outputs.TAG }}
        target: bookbrainz-prod