Skip to content

Commit

Permalink
[ci] Add GHCR publishing
Browse files Browse the repository at this point in the history
Signed-off-by: Knut Ahlers <[email protected]>
  • Loading branch information
Luzifer committed Mar 2, 2024
1 parent aa30368 commit dd40078
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .git_changerelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ release_commit_message: "Release: OTS {{.Version}}"
# bash inside the commands.
pre_commit_commands:
- |-
yq -iP "(select(.spec.template.spec | has(\"containers\")) | .spec.template.spec.containers[] | select(.name == \"ots\").image) = \"luzifer/ots:v${TAG_VERSION}\"" docs/k8s_example.yml
yq -iP "(select(.spec.template.spec | has(\"containers\")) | .spec.template.spec.containers[] | select(.name == \"ots\").image) = \"ghcr.io/luzifer/ots:v${TAG_VERSION}\"" docs/k8s_example.yml
git add docs/k8s_example.yml
- |-
yq -iP ".services.app.build.context = \"https://github.com/Luzifer/ots.git#v${TAG_VERSION}\"" docker-compose.yml
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---

name: docker-publish
on:
push:
branches: ['master']
tags: ['v*']

permissions:
packages: write

jobs:
docker-publish:
defaults:
run:
shell: bash

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
lfs: true
show-progress: false

- name: Log into registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Build & Publish
run: bash ci/docker-publish.sh

...
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ FROM alpine:latest

LABEL org.opencontainers.image.authors='Knut Ahlers <[email protected]>' \
org.opencontainers.image.version='1.12.0' \
org.opencontainers.image.url='https://hub.docker.com/r/luzifer/ots/' \
org.opencontainers.image.url='https://github.com/Luzifer/ots/pkgs/container/ots' \
org.opencontainers.image.documentation='https://github.com/Luzifer/ots/wiki' \
org.opencontainers.image.source='https://github.com/Luzifer/ots' \
org.opencontainers.image.licenses='Apache-2.0'
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.minimal
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ FROM scratch

LABEL org.opencontainers.image.authors='Knut Ahlers <[email protected]>' \
org.opencontainers.image.version='1.12.0' \
org.opencontainers.image.url='https://hub.docker.com/r/luzifer/ots/' \
org.opencontainers.image.url='https://github.com/Luzifer/ots/pkgs/container/ots' \
org.opencontainers.image.documentation='https://github.com/Luzifer/ots/wiki' \
org.opencontainers.image.source='https://github.com/Luzifer/ots' \
org.opencontainers.image.licenses='Apache-2.0'
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
![](https://badges.fyi/github/license/Luzifer/ots)
![](https://badges.fyi/github/latest-release/Luzifer/ots)
![](https://badges.fyi/github/downloads/Luzifer/ots)
[![Go Report Card](https://goreportcard.com/badge/github.com/Luzifer/ots)](https://goreportcard.com/report/github.com/Luzifer/ots)

# Luzifer / OTS

Expand Down
40 changes: 40 additions & 0 deletions ci/docker-publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -euo pipefail

function log() {
echo "[$(date +%H:%M:%S)] $@" >&2
}

[[ -n $GITHUB_REF_NAME ]] || {
log "ERR: This script is intended to run on a Github Action only."
exit 1
}

repo="ghcr.io/${GITHUB_REPOSITORY,,}"
tags=()

case "${GITHUB_REF_TYPE}" in
branch)
# Generic build to develop: Workflow has to limit branches to master
tags+=(develop)
;;
tag)
# Build to latest & tag: Older tags are not intended to rebuild
tags+=(latest ${GITHUB_REF_NAME})
;;
*)
log "ERR: The ref type ${GITHUB_REF_TYPE} is not handled."
exit 1
;;
esac

log "Building Docker image..."
docker build -t "${repo}:local" .

for ref in "${tags[@]}"; do
log "Pushing Docker image to '${repo}:${ref}'..."
docker tag "${repo}:local" "${repo}:${ref}"
docker push "${repo}:${ref}"
done

log "Publish finished."

0 comments on commit dd40078

Please sign in to comment.