GitHub Action script to deploy a Docker image to GitHub Packages #1
Workflow file for this run
This file contains 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: Publish Docker image | |
# Building and pushing a new Docker image when: | |
# > commit to master branch: ghcr.io/genomicdatainfrastructure/starter-kit-beacon2-ri-api:master | |
# > tagging with 'v'-prefix: ghcr.io/genomicdatainfrastructure/starter-kit-beacon2-ri-api:<semantic-version> | |
# > pull-request: ghcr.io/genomicdatainfrastructure/starter-kit-beacon2-ri-api:pr-<id> | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- 'master' | |
tags: | |
- 'v*' | |
pull_request: | |
branches: | |
- 'master' | |
jobs: | |
build-and-push-image: | |
name: Push Docker image to Docker Hub | |
runs-on: ubuntu-latest | |
# Needs a permission to write to GitHub Packages: | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ github.repository }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
# Indicates that the Docker build context is the current directory. | |
# Otherwise, it would be a Git URL (doing a separate clean checkout). | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |