Skip to content

ONC-XXXX - Create Docker image on branch push - #2014

Closed
tmy1313 wants to merge 18 commits into
chpladmin:stagingfrom
tmy1313:ONC-XXXX
Closed

ONC-XXXX - Create Docker image on branch push#2014
tmy1313 wants to merge 18 commits into
chpladmin:stagingfrom
tmy1313:ONC-XXXX

Conversation

@tmy1313

@tmy1313 tmy1313 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds automated Docker image builds and publishing to GitHub Container Registry (GHCR), along with all supporting Docker/Tomcat configuration needed to run the API in a container.

Changes

GitHub Actions Workflow (.github/workflows/docker-publish.yml)

  • New workflow that builds and pushes a Docker image to GHCR on every push to development, qa, staging, or production branches, as well as on manual workflow_dispatch
  • Images are tagged with three tags per build:
    • build-<run_number> — immutable, sequential build identifier
    • sha-<short-sha> — immutable, traces back to the exact commit
    • latest-<branch> — floating pointer to the most recent build from that branch (e.g. latest-development)

Dockerfile (docker/Dockerfile)

  • Two-stage build: Stage 1 uses maven:3.9-eclipse-temurin-21-alpine to compile and package the WAR, leveraging Docker layer caching for Maven dependencies; Stage 2 deploys to tomcat:11.0.23-jdk21
  • The image is secret-free — no credentials or sensitive values are baked in at build time; all secrets are supplied as environment variables at docker run time

Entrypoint (docker/entrypoint.sh)

  • Materializes the JWK signing key from the JWK_KEY environment variable into the file path that chpl-api expects, then starts Tomcat

Tomcat Configuration (docker/tomcat-conf/)

  • server.xml — configures the jdbc/openchpl JNDI datasource using EnvironmentPropertySource so DB connection details are resolved from container environment variables at startup (no secrets in the file)
  • catalina.properties — enables EnvironmentPropertySource so ${ENV_VAR} placeholders in server.xml are resolved from the environment
  • context.xml — links the global jdbc/openchpl JNDI resource into the webapp

Documentation (docker/README.md)

  • Documents every environment variable the image requires or accepts, with a quick-start docker run example

.gitattributes

  • Marks docker/entrypoint.sh with eol=lf to ensure the shell script retains LF line endings on all platforms (a CRLF shebang breaks docker build/docker run on Windows checkouts)

Testing

  • Build the image locally: docker build -t chpl-api:local .
  • Run with required environment variables (see docker/README.md for the full list)

tmy1313 and others added 8 commits July 21, 2026 22:18
Templated server.xml/context.xml resolve DB credentials from container
environment variables via Tomcat's EnvironmentPropertySource, and
entrypoint.sh materializes the JWK signing key from an env var at
startup. The image itself contains no secrets and is identical across
every environment.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Manual workflow_dispatch trigger; builds docker/Dockerfile and pushes
to ghcr.io tagged <branch>-<sha> and <branch>-latest. No secrets
required at build time.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
workflow_dispatch only appears in the Actions UI once this file exists
on the default branch. Adding pull_request lets the workflow be
validated on this PR first. Also fixes branch-name resolution for PR
events (github.ref_name is '<pr>/merge' there, not the branch name).

Must be reverted before merging to the default branch.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Replaces <branch>-<sha>/<branch>-latest with:
  build-<run_number> - immutable, sequential build identifier
  sha-<short-sha>     - immutable, traces to the exact commit
  latest-<branch>     - floating pointer to the most recent build from
                        that branch (latest-development, latest-qa,
                        latest-staging, latest-production once
                        triggered from those branches)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Lists every environment variable the secret-free image needs or
accepts (DB/JWK required-to-start vars, filesystem-path vars needing a
volume mount, environment-dependent non-secret vars, and all 31
properties currently marked SECRET in environment.properties/
email.properties, grouped by feature area). Points at
AudaciousInquiry/chpl-build for where real values live today without
reproducing any of them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
docker/build-push-action v6 enables build provenance and SBOM
attestations by default, each pushing an extra untagged manifest to
GHCR per build (2 per run, with no architecture info, cluttering the
package version list). Not needed here, so both are turned off.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds push triggers for development, qa, staging, and production so
merging into any of them builds and pushes an image tagged
latest-<branch>, without needing per-branch copies of the workflow.
push triggers are evaluated per-ref and aren't gated by which branch
is the repo's default, unlike workflow_dispatch.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tmy1313
tmy1313 requested a review from kekey1 July 23, 2026 01:32
tmy1313 added 2 commits July 22, 2026 23:37
No code reads a keyLocation property or local JWK file anymore - JWT
verification goes through Cognito's public JWKS URL. Removing the dead
entrypoint.sh materialization step and its references in the Dockerfile,
README, and server.xml.
.git (177M) and target/ build dirs (chpl-api/target alone is 1.7GB) were
being sent to the Docker daemon as build context on every CI push despite
never being referenced by docker/Dockerfile.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds containerization support for chpl-api and automates building/publishing a Tomcat-based Docker image to GHCR on pushes to environment branches.

Changes:

  • Added a GitHub Actions workflow to build and push a Docker image to GHCR on pushes to development, qa, staging, and production.
  • Added a multi-stage Docker build that packages the WAR and runs it on Tomcat, plus Tomcat config files that resolve DB settings from environment variables.
  • Added Docker runtime documentation, a .dockerignore, and a .gitattributes rule intended to enforce LF line endings for a container entrypoint script.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docker/tomcat-conf/server.xml Defines Tomcat server configuration and a JNDI DataSource wired via env var substitution.
docker/tomcat-conf/context.xml Links the global JNDI resource into the webapp context.
docker/tomcat-conf/catalina.properties Enables EnvironmentPropertySource for ${ENV_VAR} placeholder resolution.
docker/README.md Documents required/optional environment variables for running the image.
docker/Dockerfile Builds the WAR with Maven and deploys it into a Tomcat runtime image.
.github/workflows/docker-publish.yml Builds/pushes the image to GHCR with branch/build/SHA tagging.
.gitattributes Adds an LF-ending rule intended for a Docker entrypoint script.
.dockerignore Excludes git metadata, build outputs, and local tooling directories from the Docker build context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .gitattributes Outdated
Comment thread docker/Dockerfile
Comment thread .github/workflows/docker-publish.yml
tmy1313 added 3 commits July 22, 2026 23:54
docker/entrypoint.sh was deleted (its only job, materializing JWK_KEY,
was dead code) - the eol=lf rule for it is now orphaned.
The workflow publishes a floating latest-<branch> tag; without a
concurrency group, two runs for the same branch could race and let an
older commit's build finish last, overwriting latest-<branch> with a
stale image.
Add a unit-tests job to docker-publish.yml that runs `mvn clean test`
on JDK 21, mirroring the Bamboo chpl-build-dev "Run API Unit Tests"
job. build-and-push now depends on it via needs, so a broken test
suite blocks the image push instead of publishing a broken build.
- development
- qa
- staging
- production

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.

While I think we want to get to PROD eventually, I'd like to make sure we don't touch PROD at all until we're comfortable with the lower environments, so can we take this branch out of the list for now?

tmy1313 added 5 commits July 23, 2026 11:15
Add a compile job that runs `mvn clean package -DskipTests`, the same
command docker/Dockerfile's build stage runs, mirroring the "Build
API"/CompileApiTask job in the chpl-build-dev Bamboo spec.
build-and-push now needs both unit-tests and compile, so a broken
build fails fast instead of partway through the slower Docker build.
Scratch commit for testing docker-publish.yml's unit-tests job -
will be reverted.
Scratch commit for testing docker-publish.yml's compile job (missing
semicolon) - will be reverted.
@tmy1313 tmy1313 closed this Jul 27, 2026
@tmy1313
tmy1313 deleted the ONC-XXXX branch July 27, 2026 13:22
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