Skip to content

Commit

Permalink
ci: add workflow for automated Docker image build and publish (#61)
Browse files Browse the repository at this point in the history
Introduce a new GitHub Actions workflow to automate the process of
building and publishing Docker images to the GitHub Container Registry.
Configure the workflow to trigger on branch references
(`type=ref,event=branch`) and specific semantic versioning patterns
(`type=semver,pattern={{version}}`,
`type=semver,pattern={{major}}.{{minor}}`). Additionally, include a
commit SHA in long format (`type=sha,format=long`) as part of the
versioning strategy.

---------

Signed-off-by: Valentin Sickert <[email protected]>
  • Loading branch information
Lapotor authored Dec 11, 2023
1 parent 3b95567 commit 0c236f8
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Create and publish a Docker image

on:
push:
branches:
- main
release:
types: [published]
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=long
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit 0c236f8

Please sign in to comment.