-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(docker compose): make ports optional #5500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This PR makes Docker Compose port mappings optional by using environment variables, allowing more flexible deployment configurations. The changes include:
- Modified
docker-compose.yml
to use${API_PORT:-}
and${POSTGRES_PORT:-}
for optional port exposure - Updated CI workflows to explicitly set these ports for integration tests
- Ensures services can run with or without external port access
However, the current syntax "${API_PORT:-}"
may cause Docker Compose parsing issues when the variable is empty. The implementation would be more robust with default values like "${API_PORT:-8080:8080}"
.
Confidence Score: 3/5
- This PR has deployment configuration risks due to Docker Compose syntax issues
- Score reflects potential Docker Compose parsing failures with empty environment variables, though the concept is sound and CI tests should catch issues
- Pay close attention to
deployment/docker_compose/docker-compose.yml
for proper environment variable handling
Important Files Changed
File Analysis
Filename | Score | Overview |
---|---|---|
.github/workflows/pr-integration-tests.yml | 5/5 | Added explicit port environment variables for API_PORT and POSTGRES_PORT in CI workflows to ensure proper port mapping |
.github/workflows/pr-mit-integration-tests.yml | 5/5 | Added explicit port environment variables for API_PORT and POSTGRES_PORT in MIT integration tests workflow |
deployment/docker_compose/docker-compose.yml | 4/5 | Made API and Postgres ports optional using environment variables, but empty value syntax may cause issues |
Sequence Diagram
sequenceDiagram
participant Dev as Developer
participant CI as CI Pipeline
participant DC as Docker Compose
participant API as API Server
participant PG as PostgreSQL
Note over Dev,PG: Making Ports Optional Flow
Dev->>DC: Set API_PORT and POSTGRES_PORT env vars
Note right of Dev: API_PORT=8080:8080<br/>POSTGRES_PORT=5432:5432
CI->>DC: Run docker compose with explicit port envs
Note right of CI: Ensures CI tests work properly
DC->>API: Start API server
alt API_PORT is set
DC->>API: Expose port ${API_PORT}
else API_PORT is empty
DC->>API: No port mapping (internal only)
end
DC->>PG: Start PostgreSQL
alt POSTGRES_PORT is set
DC->>PG: Expose port ${POSTGRES_PORT}
else POSTGRES_PORT is empty
DC->>PG: No port mapping (internal only)
end
Note over Dev,PG: Optional port mapping allows<br/>flexibility for different deployments
3 files reviewed, 2 comments
# ports: | ||
# - "8080:8080" | ||
ports: | ||
- "${API_PORT:-}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Empty environment variable expansion may cause Docker Compose parsing issues. Consider using a default empty string or conditional port mapping.
- "${API_PORT:-}" | |
- "${API_PORT:-8080:8080}" |
# ports: | ||
# - "5432:5432" | ||
ports: | ||
- "${POSTGRES_PORT:-}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Same issue with empty environment variable expansion for Postgres port.
- "${POSTGRES_PORT:-}" | |
- "${POSTGRES_PORT:-5432:5432}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 issues found across 3 files
Prompt for AI agents (all 3 issues)
Understand the root cause of the following 3 issues and fix them.
<file name=".github/workflows/pr-mit-integration-tests.yml">
<violation number="1" location=".github/workflows/pr-mit-integration-tests.yml:262">
Unnecessary host port exposure for Postgres; tests use the Docker network (relational_db) and do not require binding 5432 on the host. This can cause port conflicts and increases attack surface in CI.</violation>
</file>
<file name="deployment/docker_compose/docker-compose.yml">
<violation number="1" location="deployment/docker_compose/docker-compose.yml:57">
Interpolating an empty value for API_PORT results in an invalid ports entry and docker-compose parsing failure. Provide a valid default mapping or remove the ports block when not mapping ports.</violation>
<violation number="2" location="deployment/docker_compose/docker-compose.yml:232">
Interpolating an empty value for POSTGRES_PORT results in an invalid ports entry and docker-compose parsing failure. Provide a valid default mapping or remove the ports block when not mapping ports.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai
to give feedback, ask questions, or re-run the review.
IMAGE_TAG=test \ | ||
INTEGRATION_TESTS_MODE=true \ | ||
API_PORT=8080:8080 \ | ||
POSTGRES_PORT=5432:5432 \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary host port exposure for Postgres; tests use the Docker network (relational_db) and do not require binding 5432 on the host. This can cause port conflicts and increases attack surface in CI.
Prompt for AI agents
Address the following comment on .github/workflows/pr-mit-integration-tests.yml at line 262:
<comment>Unnecessary host port exposure for Postgres; tests use the Docker network (relational_db) and do not require binding 5432 on the host. This can cause port conflicts and increases attack surface in CI.</comment>
<file context>
@@ -258,6 +258,8 @@ jobs:
IMAGE_TAG=test \
INTEGRATION_TESTS_MODE=true \
+ API_PORT=8080:8080 \
+ POSTGRES_PORT=5432:5432 \
docker compose up \
relational_db \
</file context>
✅ Addressed in 2fea661
# ports: | ||
# - "5432:5432" | ||
ports: | ||
- "${POSTGRES_PORT:-}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interpolating an empty value for POSTGRES_PORT results in an invalid ports entry and docker-compose parsing failure. Provide a valid default mapping or remove the ports block when not mapping ports.
Prompt for AI agents
Address the following comment on deployment/docker_compose/docker-compose.yml at line 232:
<comment>Interpolating an empty value for POSTGRES_PORT results in an invalid ports entry and docker-compose parsing failure. Provide a valid default mapping or remove the ports block when not mapping ports.</comment>
<file context>
@@ -228,8 +228,8 @@ services:
- # ports:
- # - "5432:5432"
+ ports:
+ - "${POSTGRES_PORT:-}"
volumes:
- db_volume:/var/lib/postgresql/data
</file context>
- "${POSTGRES_PORT:-}" | |
- "${POSTGRES_PORT:-5432:5432}" |
✅ Addressed in 2fea661
# ports: | ||
# - "8080:8080" | ||
ports: | ||
- "${API_PORT:-}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interpolating an empty value for API_PORT results in an invalid ports entry and docker-compose parsing failure. Provide a valid default mapping or remove the ports block when not mapping ports.
Prompt for AI agents
Address the following comment on deployment/docker_compose/docker-compose.yml at line 57:
<comment>Interpolating an empty value for API_PORT results in an invalid ports entry and docker-compose parsing failure. Provide a valid default mapping or remove the ports block when not mapping ports.</comment>
<file context>
@@ -53,8 +53,8 @@ services:
- # ports:
- # - "8080:8080"
+ ports:
+ - "${API_PORT:-}"
environment:
# Auth Settings
</file context>
- "${API_PORT:-}" | |
- "${API_PORT:-8080:8080}" |
✅ Addressed in 2fea661
Description
[Provide a brief description of the changes in this PR]
How Has This Been Tested?
[Describe the tests you ran to verify your changes]
Additional Options