Skip to content

ci: automate Keycloak theme deploys to staging - #6

Merged
saqibmanan merged 6 commits into
devfrom
ci/keycloak-staging-deploy
Aug 27, 2026
Merged

saqibmanan merged 6 commits into
devfrom
ci/keycloak-staging-deploy

Conversation

@saqibmanan

Copy link
Copy Markdown
Contributor

Replaces the manual build-jar / scp / rebuild-on-the-box process for the staging Keycloak with a CI-built image that the box only pulls.

Why

On 2026-08-27 staging was found running a theme jar built 2025-07-14 — seven months stale — scpd from a retired server rather than from current production. Nothing errored: the theme name matched, the jar was in providers/, Keycloak started clean. The only symptom was a wrong-looking login page, and diagnosing it took comparing sha256 sums across three servers.

What

  • Dockerfile — multi-stage. Node + JDK + Maven builds the Keycloakify jar; it is copied by name into keycloak:24.0.0 and registered with kc.sh build.
  • .github/workflows/deploy-keycloak-staging.yml — build → push to GHCR → SSH → docker compose pull && up -d → health gate → auto-rollback. Mirrors deploy-backend.yml in DataSpaceBackend.
  • .dockerignore.

The image carries the source commit and the theme jar sha256 as labels, so "which theme is this box running, from which commit" is one docker inspect.

Verified locally

  • Keycloakify v11 emits exactly two jars; KC 24 takes keycloak-theme-for-kc-all-other-versions.jar (2,358,300 B vs production's 2,351,205 B — right ballpark).
  • kc.sh build succeeds, and a container from this image starts with zero Quarkus augmentation (staging currently pays 16.4s on every start) and is ready in ~9s.
  • /auth/health/ready returns 200 — confirmed on the running staging box too, which already has KC_HEALTH_ENABLED=true.
  • Admin API serverinfo reports keycloakify-starter registered as both a login and an email theme, which is exactly what the DataSpace realm references. No realm-side change needed.

Notes

  • workflow_dispatch only. push: main is deliberately left disabled — main does not yet carry the theme work on fix/login-ui-alignment, so auto-deploying it would regress staging.
  • The stock ci.yaml (version-bump → GitHub Release jars) is untouched.
  • Requires a new keycloak-staging GitHub Environment. Reusing development would deploy Keycloak images onto the backend dev box.
  • The staging box needs a one-time change: image: instead of build: in its compose file. Done separately.

Keeps node_modules, build output and .git out of the build context.
Multi-stage: node+JDK+Maven builds the Keycloakify jar, then it is copied
into quay.io/keycloak/keycloak:24.0.0 and registered with `kc.sh build`.

Three things this settles:

- The jar is copied *by name*. Keycloakify emits one jar per Keycloak
  version range; a glob would put several themes into providers/ and let
  Keycloak pick one.
- `kc.sh build` is required. Providers register at build time, so a jar
  dropped into providers/ on a running server does nothing. Staging has no
  build step today, which is why it re-augments for ~16s on every start.
- KC_DB / KC_HEALTH_ENABLED / KC_METRICS_ENABLED / KC_HTTP_RELATIVE_PATH
  are build-time options in KC 24. Setting them only in compose (as staging
  does) triggers that re-augmentation regardless. Baked in here to match.

The image carries the source commit and the theme jar's sha256 as labels,
so `docker inspect` answers which theme a box is running.
Builds the image in CI, pushes it to GHCR, and has the staging box pull it
-- replacing the manual build-jar/scp/rebuild-on-the-box process that on
2026-08-27 left staging running a seven-month-stale theme copied from a
retired server, with nothing logging an error.

Mirrors deploy-backend.yml in DataSpaceBackend: digest-pinned image,
health gate, automatic rollback to the previously-running image.

workflow_dispatch only for now, taking a ref input. push-to-main is left
disabled because main does not yet carry the theme work on
fix/login-ui-alignment, so auto-deploying it would regress staging.
The deploy job's own GITHUB_TOKEN can authenticate the box's `docker
compose pull`, and it expires with the run. That drops the GHCR_TOKEN
secret entirely and leaves no standing registry credential on the auth
server; a trap logs out on every exit path.
github.repository is CivicDataLab/DataSpaceKeycloakTheme; Docker rejects
uppercase in image references, so the digest-pinned image_ref would have
been invalid on the box.
dev becomes the integration branch for staging -- what is merged there is
what staging runs. A push trigger also means the workflow does not need to
sit on the default branch first, which workflow_dispatch would require.

workflow_dispatch is kept for deploying an arbitrary ref on demand.
@saqibmanan
saqibmanan changed the base branch from main to dev August 27, 2026 13:06
@saqibmanan
saqibmanan merged commit 0a7e89e into dev Aug 27, 2026
1 check passed
@saqibmanan
saqibmanan deleted the ci/keycloak-staging-deploy branch August 27, 2026 13:07
@saqibmanan saqibmanan self-assigned this Sep 8, 2026
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.

1 participant