diff --git a/.git_changerelease.yaml b/.git_changerelease.yaml index 6ec9da7..afef480 100644 --- a/.git_changerelease.yaml +++ b/.git_changerelease.yaml @@ -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 diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..ae15e85 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -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 + +... diff --git a/Dockerfile b/Dockerfile index 32d3bc6..e22b0c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,7 @@ FROM alpine:latest LABEL org.opencontainers.image.authors='Knut Ahlers ' \ 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' diff --git a/Dockerfile.minimal b/Dockerfile.minimal index 1aaf34a..ca99c3b 100644 --- a/Dockerfile.minimal +++ b/Dockerfile.minimal @@ -27,7 +27,7 @@ FROM scratch LABEL org.opencontainers.image.authors='Knut Ahlers ' \ 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' diff --git a/README.md b/README.md index 1db58f8..7c4eee4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/ci/docker-publish.sh b/ci/docker-publish.sh new file mode 100644 index 0000000..b7ea30c --- /dev/null +++ b/ci/docker-publish.sh @@ -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."