Skip to content

[WIP] Optimize docker image#628

Draft
kavindasr wants to merge 4 commits into
wso2:masterfrom
kavindasr:master-opt-images
Draft

[WIP] Optimize docker image#628
kavindasr wants to merge 4 commits into
wso2:masterfrom
kavindasr:master-opt-images

Conversation

@kavindasr

Copy link
Copy Markdown
Contributor

Purpose

Remove unnecessary dependencies from APIM docker images. We remove unnecessary packages to reduce the image size, minimize the attack surface, and improve the overall security posture of the Docker images.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Updated Docker and compose configurations to use leaner runtime images and slimmer service checks. The changes remove unused packages across Alpine, Rocky, and Ubuntu Dockerfiles, replace some download steps with simpler tooling, and tighten final cleanup steps to reduce image footprint. Related compose health checks were also simplified to use basic TCP connectivity checks instead of HTTP endpoint probes. Image references were refreshed from the older Docker registry paths to the newer registry locations where applicable.

Walkthrough

Across all image variants (Alpine, Rocky Linux, Ubuntu) and docker-compose configurations, this change removes curl, netcat/nc, libxml2-utils, fontconfig, openssl, and related packages from Dockerfile dependency installation steps. Ubuntu Dockerfiles switch the OpenJDK tarball download from curl to wget. Rocky Linux Dockerfiles add yum clean all to the image-slimming step. Ubuntu Dockerfiles expand the final apt-get purge to include ca-certificates, locales, autoremove, and apt list cleanup. All docker-compose service healthcheck test commands replace HTTP curl or nc -z probes with bash /dev/tcp TCP connectivity probes.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning Only the Purpose section is provided; the required template sections are mostly missing. Fill in the remaining template sections, especially Goals, Approach, Release note, Documentation, tests, security checks, and environment.
Title check ❓ Inconclusive The title is related, but it's too generic to clearly identify the main change. Rename it to something specific, such as "Remove unnecessary dependencies from APIM Docker images".
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kavindasr kavindasr changed the title Optimize docker image [WIP] Optimize docker image Jun 29, 2026
@kavindasr
kavindasr marked this pull request as draft June 29, 2026 08:11

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docker-compose/apim-is-as-km-with-analytics/docker-compose.yml`:
- Line 39: The current healthcheck only verifies that the port is open, which
can mark the service healthy too early. Update the healthcheck for the
`is-as-km` and `api-manager` services to use an application-level HTTP(S)
readiness probe instead of the TCP-only `bash -c "exec 3<>/dev/tcp/..."` check,
so dependent services gated by `service_healthy` wait for the actual endpoints
to be ready. Use the existing healthcheck definitions in the compose file and
keep the readiness logic tied to each service’s protocol-level endpoint.

In `@docker-compose/apim-with-analytics/docker-compose.yml`:
- Line 39: The healthcheck for the API Manager service is only doing a raw TCP
socket check, which is too weak to prove readiness. Update the healthcheck to
use an application-level probe in the relevant docker-compose service definition
so it verifies an HTTP endpoint or similar readiness signal instead of just
connecting to localhost:9763, and keep the change tied to the existing
healthcheck configuration for that service.

In `@docker-compose/apim-with-mi/docker-compose.yml`:
- Line 39: The `api-manager` healthcheck was weakened to a raw TCP port check,
which can report healthy before the service is actually ready. Update the
`healthcheck.test` for `api-manager` in the docker-compose setup to use a real
HTTP readiness probe again, so `micro-integrator` waiting on `service_healthy`
only proceeds when `api-manager` is truly ready.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a7470d26-88f0-40e0-8b74-b2a8a9c3f132

📥 Commits

Reviewing files that changed from the base of the PR and between f8f1ac7 and d5b7804.

📒 Files selected for processing (15)
  • docker-compose/apim-is-as-km-with-analytics/docker-compose.yml
  • docker-compose/apim-with-analytics/docker-compose.yml
  • docker-compose/apim-with-mi/docker-compose.yml
  • dockerfiles/alpine/apim-acp/Dockerfile
  • dockerfiles/alpine/apim-tm/Dockerfile
  • dockerfiles/alpine/apim-universal-gw/Dockerfile
  • dockerfiles/alpine/apim/Dockerfile
  • dockerfiles/rocky/apim-acp/Dockerfile
  • dockerfiles/rocky/apim-tm/Dockerfile
  • dockerfiles/rocky/apim-universal-gw/Dockerfile
  • dockerfiles/rocky/apim/Dockerfile
  • dockerfiles/ubuntu/apim-acp/Dockerfile
  • dockerfiles/ubuntu/apim-tm/Dockerfile
  • dockerfiles/ubuntu/apim-universal-gw/Dockerfile
  • dockerfiles/ubuntu/apim/Dockerfile

build: ./dockerfiles/is-as-km
healthcheck:
test: ["CMD", "curl", "-k", "--fail", "https://localhost:9444/api/health-check/v1.0/health"]
test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/localhost/9444"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Keep application-level readiness checks here.

These probes now only confirm that the port accepts a TCP connection. In this file, service_healthy gates dependent services, so is-as-km and api-manager can be marked healthy before their HTTP(S) endpoints are actually ready. Please keep a protocol-level readiness check for these services.

Also applies to: 53-53

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker-compose/apim-is-as-km-with-analytics/docker-compose.yml` at line 39,
The current healthcheck only verifies that the port is open, which can mark the
service healthy too early. Update the healthcheck for the `is-as-km` and
`api-manager` services to use an application-level HTTP(S) readiness probe
instead of the TCP-only `bash -c "exec 3<>/dev/tcp/..."` check, so dependent
services gated by `service_healthy` wait for the actual endpoints to be ready.
Use the existing healthcheck definitions in the compose file and keep the
readiness logic tied to each service’s protocol-level endpoint.

build: ./dockerfiles/apim
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:9763/services/Version"]
test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/localhost/9763"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

This healthcheck is now too weak for readiness.

A successful TCP connect does not prove the API Manager is ready to serve requests. This can report the container healthy while the HTTP endpoint is still starting up. Please keep an application-level readiness probe instead of a raw socket check.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker-compose/apim-with-analytics/docker-compose.yml` at line 39, The
healthcheck for the API Manager service is only doing a raw TCP socket check,
which is too weak to prove readiness. Update the healthcheck to use an
application-level probe in the relevant docker-compose service definition so it
verifies an HTTP endpoint or similar readiness signal instead of just connecting
to localhost:9763, and keep the change tied to the existing healthcheck
configuration for that service.

build: ./dockerfiles/apim
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:9763/services/Version"]
test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/localhost/9763"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Keep a real readiness probe for api-manager.

This now marks the service healthy as soon as the port is open, which is weaker than the previous HTTP check. Since micro-integrator waits on service_healthy in this file, startup can proceed before api-manager is actually ready.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker-compose/apim-with-mi/docker-compose.yml` at line 39, The `api-manager`
healthcheck was weakened to a raw TCP port check, which can report healthy
before the service is actually ready. Update the `healthcheck.test` for
`api-manager` in the docker-compose setup to use a real HTTP readiness probe
again, so `micro-integrator` waiting on `service_healthy` only proceeds when
`api-manager` is truly ready.

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