[ci] Add GHCR publishing

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2024-03-02 11:09:37 +01:00
parent aa30368612
commit dd40078301
Signed by: luzifer
SSH key fingerprint: SHA256:/xtE5lCgiRDQr8SLxHMS92ZBlACmATUmF1crK16Ks4E
6 changed files with 79 additions and 4 deletions

View file

@ -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

36
.github/workflows/docker-publish.yml vendored Normal file
View file

@ -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
...

View file

@ -27,7 +27,7 @@ FROM alpine:latest
LABEL org.opencontainers.image.authors='Knut Ahlers <knut@ahlers.me>' \
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'

View file

@ -27,7 +27,7 @@ FROM scratch
LABEL org.opencontainers.image.authors='Knut Ahlers <knut@ahlers.me>' \
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'

View file

@ -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

40
ci/docker-publish.sh Normal file
View file

@ -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."