Skip to content

build: speed up and harden image and Compose - #97

Merged
uniqueg merged 4 commits into
devfrom
chore/docker-compose
Oct 20, 2026
Merged

uniqueg merged 4 commits into
devfrom
chore/docker-compose

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Speeds up and hardens the Docker image and the Compose setup (#77).

  • Dockerfile: dependencies are installed from requirements.txt in their own layer before the app is copied, so code changes no longer reinstall them. The app is copied to /app and run from there (PYTHONPATH=/app) instead of an editable install. Adds a HEALTHCHECK against the Swagger UI.
  • .dockerignore: allow-list. Only cloud_registry/, requirements.txt and update-config-map.sh are sent to the build context, so tests, chart, docs and local files stay out of the image.
  • Compose:
    • drops the version key and the legacy links;
    • stops publishing MongoDB's port (an override for 127.0.0.1 is documented);
    • keeps data in a named volume instead of ../data/cloud-registry/db;
    • starts the app once MongoDB is healthy (mongosh ping);
    • builds cloud-registry:local with pull_policy: build instead of using the stale public name elixircloud/cloud-registry:0.1.0.
  • CI smoke test: docker compose up --wait waits for the health checks, then a single request checks the app.
  • README: Compose v2 commands, the volume, the migration note.

Closes #77

Deviations from the issue

  • The app is not pip-installed (non-editably): the Helm chart mounts the config at /app/cloud_registry/config.yaml, and the config Job runs /app/update-config-map.sh, so the package has to stay at /app. An installed copy would read its own bundled config instead.
  • The health check probes /ga4gh/registry/v1/ui/, not /service-info: every API endpoint requires authentication. The check assumes the default port, base path and Swagger UI setting (noted in the Dockerfile).
  • MongoDB stays at mongo:7.0 (as on dev); aligning the Helm chart's version is Deployment: pin MongoDB, add DB auth, probes #68.

Upgrade notes

Compose users who have data in ../data/cloud-registry/db need to bind-mount it in a docker-compose.override.yaml (see the README); otherwise MongoDB starts with an empty volume.

Verification

  • Docker is not available locally, so this CI run is the first build and start of the image and the Compose setup.
  • Local checks:
    • docker compose config -q passes;
    • both YAML files parse;
    • pre-commit's whitespace and end-of-file hooks pass;
    • gitleaks dir . finds no leaks.
  • Adversarial and quality reviews ran (round 1); all findings were low and have been applied. Among them, the adversarial reviewer checked the image against the Helm chart, the publish job, FOCA's spec path resolution and the namespace package import.
  • CI: all checks pass. The Compose smoke test built the image, docker compose up --wait reported both containers healthy, and the Swagger UI responded.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Harden and streamline the Docker and Compose setup for faster builds, reliable startup, and clearer local deployment guidance.

New Features:

  • Add Docker image and Compose health checks so the service starts only after MongoDB is ready and exposes a healthy application.

Bug Fixes:

  • Prevent Compose from using a stale published image and avoid exposing MongoDB unnecessarily.
  • Preserve application configuration compatibility by running the copied package directly from /app.

Enhancements:

  • Optimize Docker builds by isolating dependency installation from application source changes and restrict the build context to required files.
  • Modernize the Compose setup with named MongoDB storage, service health dependencies, and removal of legacy configuration.
  • Update the README for Docker Compose v2 usage and document migration from the previous MongoDB bind mount.

CI:

  • Simplify the Compose smoke test by waiting for container health checks before making a single application request.

Documentation:

  • Document Compose v2 commands, named-volume behavior, host access to MongoDB, and migration of existing database data.

uniqueg and others added 3 commits October 20, 2026 07:45
Dockerfile: install dependencies in their own layer before copying the
app, run the app from `/app` instead of an editable install (the Helm
chart mounts the config there), and add a health check against the
Swagger UI (all API endpoints require authentication).

.dockerignore: send only the package, `requirements.txt` and
`update-config-map.sh` to the build context.

Compose: drop the `version` key, do not publish MongoDB's port, keep
data in a named volume, start the app once MongoDB is healthy, and
build a local image name instead of a stale public one. CI waits for
the containers to be healthy.

Closes #77

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Note why `PYTHONPATH` is set and that the health check needs the
Swagger UI, move the MongoDB port comment to its service, replace the
redundant CI wait loop with one request, and drop the Docker version
from the README.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Explain how to keep data from the earlier bind mount, name the Compose
volume as Docker shows it, and note the health check assumptions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR makes Docker builds more cacheable and self-contained, runs the application directly from /app with a health check, modernizes Compose around local image builds and health-aware MongoDB startup, and updates CI and documentation for the new workflow and storage migration.

Sequence diagram for health-aware Compose startup

sequenceDiagram
    participant Compose
    participant MongoDB
    participant App
    participant CI
    Compose->>MongoDB: Start container
    Compose->>MongoDB: healthcheck mongosh db.adminCommand('ping').ok
    MongoDB-->>Compose: Healthy
    Compose->>App: Start cloud-registry:local
    App->>App: HEALTHCHECK urllib.request.urlopen(HEALTHCHECK_URL)
    App-->>Compose: Healthy
    CI->>Compose: docker compose up --wait
    CI->>App: curl --fail PROBE_ENDPOINT
    App-->>CI: 200 response
Loading

File-Level Changes

Change Details Files
Reworked the image build for cache efficiency and runtime compatibility.
  • Install system packages and Python requirements before copying application code.
  • Run the package directly from /app using PYTHONPATH, preserving Helm config and script paths.
  • Add a configurable Swagger UI health check and retain required runtime utilities.
Dockerfile
Modernized Compose orchestration, networking, and database persistence.
  • Build and use a local image with Compose v2, removing legacy version and links settings.
  • Gate application startup on a MongoDB mongosh ping health check.
  • Replace host-path database storage with a named volume and document optional host access and migration behavior.
docker-compose.yaml
README.md
Simplified CI service verification by relying on container health checks.
  • Start the stack with docker compose up --wait and a timeout.
  • Replace the custom polling loop with one fail-fast request after startup.
  • Continue collecting Compose logs on failure.
.github/workflows/checks.yaml
Restricted the Docker build context to deployment-relevant files.
  • Allow-list the application package, dependency manifest, and configuration update script.
.dockerignore

Assessment against linked issues

Issue Objective Addressed Explanation
#77 Improve Docker image build performance and reduce its contents by installing dependencies in a cached layer before copying application code, excluding development-only files, and adding an image health check. ✅
#77 Harden and modernize Compose startup by keeping MongoDB off published host ports, using persistent named storage and health-gated app startup, selecting a local image name, and removing obsolete configuration. ✅
#77 Update the README and CI smoke test to match the Compose changes and verify the application starts and responds. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3feb7ef) to head (e728068).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev       #97   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          224       224           
=========================================
  Hits           224       224           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 20, 2026 05:50

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="Dockerfile" line_range="37-38" />
<code_context>
+## All API endpoints require authentication, so probe the Swagger UI instead;
+## assumes the default port, base path and Swagger UI setting of the config
+## (`server.port`, `api.specs[].connexion.options.swagger_ui`)
+HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
+  CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8080/ga4gh/registry/v1/ui/', timeout=4)"]

 CMD ["python", "-m", "cloud_registry.app"]
</code_context>
<issue_to_address>
**Custom configs stay unhealthy**

When a Docker image is run with a non-default port, API base path, or Swagger UI disabled, `urllib.request.urlopen` keeps probing the hard-coded default URL, so Docker marks an otherwise running app unhealthy when its config changes the port, API base path, or Swagger UI setting; Compose `up --wait` then fails. The Helm chart demonstrates that config can be replaced at runtime.

Use a health endpoint whose availability does not depend on those settings, or make the health-check target configurable alongside the app config.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and compose now stores MongoDB data in a new named volume instead of the existing host directory. Reverting will switch back to the old directory, leaving any records written to the named volume out of view until you reconfigure or copy the data; the old data is not deleted, so the change is recoverable.

Blocking findings: Dockerfile:38


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread Dockerfile Resolved
Read the URL probed by the image health check from `HEALTHCHECK_URL`,
so that configs with another port, API base path or Swagger UI setting
can adjust it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg

uniqueg commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@uniqueg
uniqueg merged commit 98d05c6 into dev Oct 20, 2026
10 checks passed
@uniqueg
uniqueg deleted the chore/docker-compose branch October 20, 2026 06:25

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".github/workflows/checks.yaml" line_range="127" />
<code_context>
-          done
-          echo "App did not respond with 200 at ${PROBE_ENDPOINT} (last status: ${status})"
-          exit 1
+          curl --fail --silent --show-error --output /dev/null \
+            --header 'Accept: application/json' "${PROBE_ENDPOINT}"
       - name: Show app logs
</code_context>
<issue_to_address>
**Redirects pass the smoke test**

When the probe endpoint returns a 3xx response, `curl --fail` treats the redirect as success, so the workflow passes without receiving the required 200 response from the Swagger UI.

Make the smoke test fail unless the probe endpoint returns HTTP 200.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and compose now uses a new named volume instead of ../data/cloud-registry/db, so existing users can start with an empty database while their old database files remain on disk. Reverting restores the old mount, but writes made to the named volume will need to be copied or mounted separately to appear there.

Blocking findings: .github/workflows/checks.yaml:127


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

done
echo "App did not respond with 200 at ${PROBE_ENDPOINT} (last status: ${status})"
exit 1
curl --fail --silent --show-error --output /dev/null \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Redirects pass the smoke test

When the probe endpoint returns a 3xx response, curl --fail treats the redirect as success, so the workflow passes without receiving the required 200 response from the Swagger UI.

Make the smoke test fail unless the probe endpoint returns HTTP 200.

Prompt for AI agents
In `.github/workflows/checks.yaml` at line 127:

**Redirects pass the smoke test**

When the probe endpoint returns a 3xx response, `curl --fail` treats the redirect as success, so the workflow passes without receiving the required 200 response from the Swagger UI.

Make the smoke test fail unless the probe endpoint returns HTTP 200.

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.

Docker: faster image builds, safer Compose setup

1 participant