diff --git a/.github/actions/docker-push-variables/action.yml b/.github/actions/docker-push-variables/action.yml index 2e4931c15f..afa6d6b17e 100644 --- a/.github/actions/docker-push-variables/action.yml +++ b/.github/actions/docker-push-variables/action.yml @@ -34,63 +34,10 @@ runs: steps: - name: Generate config id: ev - shell: python + shell: bash + env: + IMAGE_NAME: ${{ inputs.image-name }} + IMAGE_ARCH: ${{ inputs.image-arch }} + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | - """Helper script to get the actual branch name, docker safe""" - import configparser - import os - from time import time - - parser = configparser.ConfigParser() - parser.read(".bumpversion.cfg") - - branch_name = os.environ["GITHUB_REF"] - if os.environ.get("GITHUB_HEAD_REF", "") != "": - branch_name = os.environ["GITHUB_HEAD_REF"] - safe_branch_name = branch_name.replace("refs/heads/", "").replace("/", "-") - - image_names = "${{ inputs.image-name }}".split(",") - image_arch = "${{ inputs.image-arch }}" or None - - is_pull_request = bool("${{ github.event.pull_request.head.sha }}") - is_release = "dev" not in image_names[0] - - sha = os.environ["GITHUB_SHA"] if not is_pull_request else "${{ github.event.pull_request.head.sha }}" - - # 2042.1.0 or 2042.1.0-rc1 - version = parser.get("bumpversion", "current_version") - # 2042.1 - version_family = ".".join(version.split("-", 1)[0].split(".")[:-1]) - prerelease = "-" in version - - image_tags = [] - if is_release: - for name in image_names: - image_tags += [ - f"{name}:{version}", - ] - if not prerelease: - image_tags += [ - f"{name}:latest", - f"{name}:{version_family}", - ] - else: - suffix = "" - if image_arch and image_arch != "amd64": - suffix = f"-{image_arch}" - for name in image_names: - image_tags += [ - f"{name}:gh-{sha}{suffix}", # Used for ArgoCD and PR comments - f"{name}:gh-{safe_branch_name}{suffix}", # For convenience - f"{name}:gh-{safe_branch_name}-{int(time())}-{sha[:7]}{suffix}", # Use by FluxCD - ] - - image_main_tag = image_tags[0] - image_tags_rendered = ",".join(image_tags) - - with open(os.environ["GITHUB_OUTPUT"], "a+", encoding="utf-8") as _output: - print("sha=%s" % sha, file=_output) - print("version=%s" % version, file=_output) - print("prerelease=%s" % prerelease, file=_output) - print("imageTags=%s" % image_tags_rendered, file=_output) - print("imageMainTag=%s" % image_main_tag, file=_output) + python3 ${{ github.action_path }}/push_vars.py diff --git a/.github/actions/docker-push-variables/push_vars.py b/.github/actions/docker-push-variables/push_vars.py new file mode 100644 index 0000000000..f4bbabb8f0 --- /dev/null +++ b/.github/actions/docker-push-variables/push_vars.py @@ -0,0 +1,59 @@ +"""Helper script to get the actual branch name, docker safe""" + +import configparser +import os +from time import time + +parser = configparser.ConfigParser() +parser.read(".bumpversion.cfg") + +branch_name = os.environ["GITHUB_REF"] +if os.environ.get("GITHUB_HEAD_REF", "") != "": + branch_name = os.environ["GITHUB_HEAD_REF"] +safe_branch_name = branch_name.replace("refs/heads/", "").replace("/", "-") + +image_names = os.getenv("IMAGE_NAME").split(",") +image_arch = os.getenv("IMAGE_ARCH") or None + +is_pull_request = bool(os.getenv("PR_HEAD_SHA")) +is_release = "dev" not in image_names[0] + +sha = os.environ["GITHUB_SHA"] if not is_pull_request else os.getenv("PR_HEAD_SHA") + +# 2042.1.0 or 2042.1.0-rc1 +version = parser.get("bumpversion", "current_version") +# 2042.1 +version_family = ".".join(version.split("-", 1)[0].split(".")[:-1]) +prerelease = "-" in version + +image_tags = [] +if is_release: + for name in image_names: + image_tags += [ + f"{name}:{version}", + ] + if not prerelease: + image_tags += [ + f"{name}:latest", + f"{name}:{version_family}", + ] +else: + suffix = "" + if image_arch and image_arch != "amd64": + suffix = f"-{image_arch}" + for name in image_names: + image_tags += [ + f"{name}:gh-{sha}{suffix}", # Used for ArgoCD and PR comments + f"{name}:gh-{safe_branch_name}{suffix}", # For convenience + f"{name}:gh-{safe_branch_name}-{int(time())}-{sha[:7]}{suffix}", # Use by FluxCD + ] + +image_main_tag = image_tags[0] +image_tags_rendered = ",".join(image_tags) + +with open(os.environ["GITHUB_OUTPUT"], "a+", encoding="utf-8") as _output: + print("sha=%s" % sha, file=_output) + print("version=%s" % version, file=_output) + print("prerelease=%s" % prerelease, file=_output) + print("imageTags=%s" % image_tags_rendered, file=_output) + print("imageMainTag=%s" % image_main_tag, file=_output) diff --git a/.github/actions/docker-push-variables/test.sh b/.github/actions/docker-push-variables/test.sh new file mode 100755 index 0000000000..bfb6cca8af --- /dev/null +++ b/.github/actions/docker-push-variables/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash -x +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +GITHUB_OUTPUT=/dev/stdout \ + GITHUB_REF=ref \ + GITHUB_SHA=sha \ + IMAGE_NAME=ghcr.io/goauthentik/server,beryju/authentik \ + python $SCRIPT_DIR/push_vars.py diff --git a/Makefile b/Makefile index 0cffb452af..7c6b2063ef 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ PWD = $(shell pwd) UID = $(shell id -u) GID = $(shell id -g) NPM_VERSION = $(shell python -m scripts.npm_version) -PY_SOURCES = authentik tests scripts lifecycle +PY_SOURCES = authentik tests scripts lifecycle .github DOCKER_IMAGE ?= "authentik:test" GEN_API_TS = "gen-ts-api"