Skip to content

Add shared Docker build and infra-deploy actions#39

Open
mpinter wants to merge 4 commits into
masterfrom
add-setup-docker-build-action
Open

Add shared Docker build and infra-deploy actions#39
mpinter wants to merge 4 commits into
masterfrom
add-setup-docker-build-action

Conversation

@mpinter
Copy link
Copy Markdown
Contributor

@mpinter mpinter commented May 29, 2026

Ports reusable CI building blocks from konto.bratislava.sk and parking-pricing-api into the shared github-actions repo so other repos can consume them centrally.

What's added

  • .github/actions/resolve-cache-refs (composite) — resolves master + branch/PR Docker registry cache refs. Uses docker/metadata-action@v6 and actions/github-script@v9.
  • .github/actions/setup-docker-build (composite) — wraps resolve-cache-refs + Buildx setup + Docker Hub / Harbor login. Registry credentials passed as inputs (composite actions cannot read the secrets context).
  • .github/actions/get-image-tags (composite) — single source of truth for the image tag convention. Always outputs the default image:<short-sha> tag; when a cluster (development/staging/production/aws) is given, also outputs image:<cluster>-<short-sha>. Outputs: default_tag, cluster_tag, and a newline-delimited tags list ready for docker/build-push-action. Composite inputs can't declare enums, so the cluster set is validated at runtime (invalid value fails the step).
  • .github/workflows/trigger-infra-deploy.yml (reusable workflow) — dispatches and awaits a deploy in infrastructure-deployment-configuration. app and dispatch_ref (default master) are inputs; INFRA_DEPLOY_PAT must be available on the calling repo.

Notes

  • Action versions bumped to latest (actions/github-script v8 → v9; metadata v6, buildx v4, login v4 already current).
  • setup-docker-build references resolve-cache-refs by repo ref pinned to this branch (@add-setup-docker-build-action) because cross-repo composite actions can't use local ./ paths. Repoint this to a released tag (@beta/@stable) or SHA after merge — flagged in a comment in the file.

🤖 Generated with Claude Code

Add reusable building blocks ported from konto and parking-pricing-api so
other repos can consume them centrally:

- resolve-cache-refs: composite action resolving master + branch/PR Docker
  registry cache refs (docker/metadata-action@v6, actions/github-script@v9)
- setup-docker-build: composite action wrapping resolve-cache-refs, Buildx
  setup, and Docker Hub / Harbor login (registry creds passed as inputs)
- trigger-infra-deploy: reusable workflow dispatching and awaiting a deploy in
  infrastructure-deployment-configuration; app and dispatch_ref are inputs,
  INFRA_DEPLOY_PAT expected from the caller

Action versions bumped to latest (github-script v8 -> v9).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

mpinter and others added 2 commits May 29, 2026 14:09
Centralizes the Docker image tag convention so a format change is a single
edit. Outputs `image:<short-sha>` when no cluster is given, or
`image:<cluster>-<short-sha>` for cluster development/staging/production/aws.
Composite inputs can't declare enums, so the cluster set is validated at runtime.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Always output the default unprefixed tag (image:<short-sha>); add the
cluster-prefixed tag (image:<cluster>-<short-sha>) when a cluster is given.
Exposes default_tag, cluster_tag, and a newline-delimited `tags` list ready for
docker/build-push-action.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

deploy.yml renamed its workflow_dispatch input app_name -> app; the
trigger still sent app_name, causing GitHub dispatch API to return 422
(unexpected input + missing required app).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
DEFAULT_TAG="${IMAGE}:${SHORT_SHA}"
echo "default_tag=${DEFAULT_TAG}" >> "$GITHUB_OUTPUT"

if [ -z "$CLUSTER" ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so unnecessary convoluted. I would suggest something more lean like

TAGS=("${DEFAULT_TAG}")
CLUSTER_TAG=""

if [[ -n "${CLUSTER:-}" ]]; then
  if [[ ! "$CLUSTER" =~ ^(development|staging|production|aws)$ ]]; then
    echo "::error::Invalid cluster '$CLUSTER'. Allowed: development, staging, production, aws (or empty)."
    exit 1
  fi

  CLUSTER_TAG="${IMAGE}:${CLUSTER}-${SHORT_SHA}"
  TAGS+=("$CLUSTER_TAG")
fi

{
  echo "cluster_tag=${CLUSTER_TAG}"
  echo "tags<<EOF"
  printf '%s\n' "${TAGS[@]}"
  echo "EOF"
} >> "$GITHUB_OUTPUT"

Honest confession. I just wrote this, didn't test it, so leaving it up to the reader (? 🙈)

env:
INPUT_IMAGE: ${{ inputs.image }}
INPUT_SUFFIXES: ${{ inputs.suffixes }}
INPUT_META_JSON: ${{ steps.meta.outputs.json }}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this mean that somewhere here it should also have needs: [meta]? I get that GH probably does this by itself if referenced, but I would still like it to be explicit

INPUT_SUFFIXES: ${{ inputs.suffixes }}
INPUT_META_JSON: ${{ steps.meta.outputs.json }}
with:
script: |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I really dislike that this runs a node script. I don't think that is something we want to do. First of all it takes longer to spin up as just plain runner. You introduce another image/dependency that you need to download to a runner. Not to mention the many issues that nodejs ecosystem had in a last year.

If possible rewrite this into bash. First of all, it is consistent with the rest of the scripts in github-action repo. It lowers the footprint. Make is cleaner and leaner, as this is unnecessary convoluted. We have a javascript function within a very simple step. This can all be avoided with just something like

token=$(jq -er '.["tag-names"][0]' <<< "$INPUT_META_JSON")
if [[ -z "$token" ]]; then
  echo "::error::No metadata-action tag-names value found"
  exit 1
fi

# Strip windows \r and trim
suffixes=$(tr -d '\r' <<<"$INPUT_SUFFIXES" | awk '{$1=$1;print}')
if [[ -z "${suffixes}" ]]; then
  echo "::error::At least one suffix is required"
  exit 1
fi

cache_refs='{}'
for suffix in $suffixes; do
  master="type=registry,ref=${INPUT_IMAGE}:cache-master-${suffix}"
  branch="type=registry,ref=${INPUT_IMAGE}:cache-${token}-${suffix}"

  if [[ "$token" == master ]]; then
    from="$master"
    to="${master},mode=max"
  else
    from="${master}"$'\n'"${branch}"
    to="${branch},mode=max"
  fi

  cache_refs=$(jq -c --arg suf "$suffix" --arg from "$from" --arg to "$to" \
    '.[$suf] = {cache_from: $from, cache_to: $to}' <<< "$cache_refs")
done

echo "cache_refs=$cache_refs" >> "$GITHUB_OUTPUT"

you can probably make it even more leaner, I just wrote this from top of my head.


Moreover, consider if this is even necessary. I don't really know how you plan on using it (at the time of this review), but something like

strategy:
  matrix:
    suffix: ['tag1', 'tag2']
steps:
  - uses: docker/build-push-action@v6
    with:
      cache-from: |
        type=registry,ref=${{ env.IMAGE }}:cache-master-${{ matrix.suffix }}
        type=registry,ref=${{ env.IMAGE }}:cache-${{ github.ref_name }}-${{ matrix.suffix }}
      cache-to: type=registry,ref=${{ env.IMAGE }}:cache-${{ github.ref_name }}-${{ matrix.suffix }},mode=max

directly inline in yaml might be a better option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants