bookbrainz/bookbrainz-site

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

Summary

Maintainability
Test Coverage
# This workflow can be used to push an image off a branch to Docker Hub.
# This is useful to deploy changes from any branch/PR to BookBrainz beta or test for testing.
name: Push development Docker image

on:
  workflow_dispatch:
    inputs:
      pr:
        description: 'PR number (if deploying a PR)'
        required: false
        type: string
      tag:
        description: 'Docker Image Tag (Version)'
        required: true
        default: 'beta'

jobs:

  dev:

      runs-on: ubuntu-latest

      steps:
      - uses: actions/checkout@v3
        # empty strings evaluate to 0
        if: ${{ github.event.inputs.pr == 0}}
        
      - uses: actions/checkout@v3
        if: ${{ github.event.inputs.pr != 0}}
        with:
          # The branch, tag or SHA to checkout. When checking out the repository that
          # triggered a workflow, this defaults to the reference or SHA for that event.
          # Otherwise, uses the default branch.
          ref: ${{ format('refs/pull/{0}/head', github.event.inputs.pr) }}

      - name: Login to Docker Hub
        run: echo ${{ secrets.DOCKER_HUB_PASSWORD }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
        continue-on-error: true

      - name: Build development image
        run: |
          docker build \
            --target bookbrainz-prod \
            --tag metabrainz/bookbrainz:"${{ github.event.inputs.tag }}" \
            --build-arg DEPLOY_ENV="${{ github.event.inputs.tag }}" \
            --build-arg GIT_COMMIT_SHA="${{ github.sha }}" .
      - name: Push development image
        run: docker push metabrainz/bookbrainz:"${{ github.event.inputs.tag }}"