3 Commits
v1.3 ... v1.6

2 changed files with 82 additions and 1 deletions

View File

@@ -50,6 +50,21 @@ on:
description: >
Multiline build args, one per line: KEY=VALUE (values may include spaces)
extra_tags:
description: >
Optional extra tags to apply to each image.
Accepts JSON array (e.g. ["latest", "main"]) or newline-separated list.
required: false
type: string
default: ""
skip_if_tag_exists:
description: >
If true, skip build when all images already have sha-<commit> tags.
required: false
type: string
default: "false"
env:
description: >
Multiline env vars, one per line: KEY=VALUE
@@ -138,6 +153,10 @@ jobs:
env:
IMAGES: ${{ inputs.images }}
BUILD_ARGS: ${{ inputs.build_args }}
EXTRA_TAGS_INPUT: ${{ inputs.extra_tags }}
CHECKOUT_REPO: ${{ inputs.checkout_repo }}
CHECKOUT_PATH: ${{ inputs.checkout_path }}
SKIP_IF_TAG_EXISTS: ${{ inputs.skip_if_tag_exists }}
CI_TOKEN: ${{ secrets.ci_token }}
TRIVY_SEVERITY: ${{ inputs.trivy_severity }}
run: |
@@ -167,8 +186,38 @@ jobs:
RAW_REF="${{ github.ref }}"
SHA_FULL="${{ github.sha }}"
SOURCE_SHA_FULL="$SHA_FULL"
if [ -n "$CHECKOUT_REPO" ] && [ -d "$CHECKOUT_PATH/.git" ]; then
SOURCE_SHA_FULL=$(git -C "$CHECKOUT_PATH" rev-parse HEAD)
fi
SHA_FULL="$SOURCE_SHA_FULL"
SHA_SHORT="${SHA_FULL:0:12}"
truthy() {
case "${1,,}" in
1|true|yes|y|on) return 0;;
*) return 1;;
esac
}
if truthy "$SKIP_IF_TAG_EXISTS"; then
missing=0
while read -r img; do
IMAGE_NAME=$(echo "$img" | jq -r '.name')
FULL_IMAGE="${{ inputs.registry_host }}/$IMAGE_NAME"
if docker manifest inspect "$FULL_IMAGE:sha-$SHA_SHORT" >/dev/null 2>&1; then
echo "==== Found existing tag $FULL_IMAGE:sha-$SHA_SHORT ===="
else
echo "==== Missing tag $FULL_IMAGE:sha-$SHA_SHORT (will build) ===="
missing=1
fi
done < <(echo "$IMAGES" | jq -c '.[]')
if [ "$missing" -eq 0 ]; then
echo "All images already have sha-$SHA_SHORT tag. Skipping build."
exit 0
fi
fi
VERSION_TAGS=()
if [[ "$RAW_REF" =~ ^refs/tags/v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
VERSION_TAGS+=("v${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}")
@@ -177,6 +226,25 @@ jobs:
VERSION_TAGS+=("latest")
fi
EXTRA_TAGS=()
if [ -n "$EXTRA_TAGS_INPUT" ]; then
if echo "$EXTRA_TAGS_INPUT" | jq -e . >/dev/null 2>&1; then
if ! echo "$EXTRA_TAGS_INPUT" | jq -e 'type == "array"' >/dev/null 2>&1; then
echo "inputs.extra_tags must be a JSON array" >&2
exit 1
fi
mapfile -t EXTRA_TAGS < <(echo "$EXTRA_TAGS_INPUT" | jq -r '.[]')
else
while IFS= read -r line; do
trimmed="${line#"${line%%[![:space:]]*}"}"
trimmed="${trimmed%"${trimmed##*[![:space:]]}"}"
[ -z "$trimmed" ] && continue
case "$trimmed" in \#*) continue;; esac
EXTRA_TAGS+=("$trimmed")
done <<< "$EXTRA_TAGS_INPUT"
fi
fi
BUILD_ARG_FLAGS=()
BUILD_ARGS_JSON="{}"
if [ -n "$BUILD_ARGS" ]; then
@@ -256,6 +324,9 @@ jobs:
for ver in "${VERSION_TAGS[@]}"; do
TAGS+=("$FULL_IMAGE:$ver")
done
for extra in "${EXTRA_TAGS[@]}"; do
TAGS+=("$FULL_IMAGE:$extra")
done
TAGS_JSON=$(printf '%s\n' "${TAGS[@]}" | jq -R . | jq -s .)
TARGET_NAME="img_${IDX}"
@@ -315,6 +386,9 @@ jobs:
for ver in "${VERSION_TAGS[@]}"; do
TAGS+=("$FULL_IMAGE:$ver")
done
for extra in "${EXTRA_TAGS[@]}"; do
TAGS+=("$FULL_IMAGE:$extra")
done
TAG_ARGS=()
for tag in "${TAGS[@]}"; do

View File

@@ -101,7 +101,7 @@ jobs:
POSTGRES_PASSWORD: ${{ inputs.postgres_password }}
POSTGRES_DB: ${{ inputs.postgres_db }}
ports:
- 5432:5432
- 5432
options: >-
--health-cmd="${{ inputs.postgres_health_cmd }}"
--health-interval=${{ inputs.postgres_health_interval }}
@@ -114,6 +114,13 @@ jobs:
--health-interval=${{ inputs.redis_health_interval }}
--health-timeout=${{ inputs.redis_health_timeout }}
--health-retries=${{ inputs.redis_health_retries }}
env:
POSTGRES_HOST: 127.0.0.1
POSTGRES_PORT: ${{ job.services.postgres.ports['5432'] }}
POSTGRES_USER: ${{ inputs.postgres_user }}
POSTGRES_PASSWORD: ${{ inputs.postgres_password }}
POSTGRES_DB: ${{ inputs.postgres_db }}
DATABASE_URL: postgres://${{ inputs.postgres_user }}:${{ inputs.postgres_password }}@127.0.0.1:${{ job.services.postgres.ports['5432'] }}/${{ inputs.postgres_db }}
permissions:
contents: read
defaults: