Skip to content

Commit

Permalink
Add GHA to publish docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
trey-stafford committed Dec 16, 2024
1 parent 3fa28b6 commit e0c388a
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Build and publish container image"

on:
push:
branches:
- "main"
# TODO: remove. This is for testing purposes.
- "add-gha-for-docker-image"
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"

jobs:
build-and-release-image:
name: "Build and release container image"
runs-on: "ubuntu-latest"
env:
IMAGE_NAME: "ogdc-runner"
# GitHub Actions expressions don't have great conditional support, so
# writing a ternary expression looks a lot like bash. In Python, this
# would read as:
# github.ref_name if github.ref_type == 'tag' else 'latest'
# https://docs.github.com/en/actions/learn-github-actions/expressions
IMAGE_TAG:
"${{ github.ref_type == 'tag' && github.ref_name || 'latest' }}"
steps:
- name: "Check out repository"
uses: "actions/checkout@v3"

- name: "Build container image"
run: |
docker build --tag "ghcr.io/${IMAGE_NAME}:${IMAGE_TAG}" .
- name: "GHCR login"
uses: "docker/login-action@v2"
with:
registry: "ghcr.io"
username: "${{ github.repository_owner }}"
password: "${{ secrets.GITHUB_TOKEN }}"

- name: "Push to image registries (DockerHub, GHCR)"
run: |
# Push to GHCR
docker push "ghcr.io/${IMAGE_NAME}:${IMAGE_TAG}"
# Re-tag image and push to GHCR
docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "ghcr.io/${IMAGE_NAME}:${IMAGE_TAG}"
docker push "ghcr.io/${IMAGE_NAME}:${IMAGE_TAG}"
# TODO: quay.io?
# docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "quay.io/${IMAGE_NAME}:${IMAGE_TAG}"
# docker push "quay.io/${IMAGE_NAME}:${IMAGE_TAG}"

0 comments on commit e0c388a

Please sign in to comment.