ITEP-81653: Reduce cluster analytics runtime image size#592
Conversation
|
|
||
| # -------------- Cluster Analytics Runtime Stage -------------- | ||
| FROM scenescape-common-base-24-04 AS scenescape-cluster-analytics-runtime | ||
| FROM python:3.12-slim AS scenescape-cluster-analytics-runtime |
Check warning
Code scanning / Scorecard
Pinned-Dependencies Medium
| ENV PATH="$BUILD_ENV_DIR/bin:$PATH" | ||
|
|
||
| # Install core Python dependencies | ||
| RUN pip install --no-cache-dir --upgrade pip numpy opencv-python-headless==4.6.0.66 |
Check warning
Code scanning / Scorecard
Pinned-Dependencies Medium
There was a problem hiding this comment.
Pull Request Overview
This PR reduces the cluster analytics runtime image size by switching from a custom base image (scenescape-common-base-24-04) to the official python:3.12-slim image and implementing a multi-stage build optimization strategy.
Key Changes:
- Replaced custom base image with
python:3.12-slimfor the runtime stage - Reorganized dependency installation to use a virtual environment (
/opt/venv) instead of system packages - Streamlined system dependencies to only essential runtime libraries (libgl1, libglib2.0-0)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| COPY --chown=$USER_ID:$GROUP_ID --from=scenescape-common-base-24-04 /tmp/tools/waitforbroker $SCENESCAPE_HOME/tools/waitforbroker | ||
|
|
||
| USER $USER_ID:$GROUP_ID | ||
| HEALTHCHECK CMD true |
There was a problem hiding this comment.
The healthcheck always returns success (true), making it ineffective. Replace with an actual health check that verifies the service is functioning correctly, such as checking if the application responds to requests or a specific health endpoint.
| HEALTHCHECK CMD true | |
| HEALTHCHECK CMD curl --fail --silent http://localhost:8000/health || exit 1 |
| # Install core Python dependencies | ||
| RUN pip install --no-cache-dir --upgrade pip numpy opencv-python-headless==4.6.0.66 | ||
|
|
||
| # Copy compiled scene_common + fast_geometry from builder | ||
| COPY --chown=$WSUSER:$WSUSER --from=scenescape-common-base-24-04 /usr/local/lib/python3.12/dist-packages/scene_common \ | ||
| $BUILD_ENV_DIR/lib/python3.12/site-packages/scene_common | ||
|
|
||
| COPY --chown=$WSUSER:$WSUSER --from=scenescape-common-base-24-04 /usr/local/lib/python3.12/dist-packages/fast_geometry \ | ||
| $BUILD_ENV_DIR/lib/python3.12/site-packages/fast_geometry |
There was a problem hiding this comment.
The Python version 3.12 is hardcoded in the path. Since the base image is python:3.12-slim, consider using a variable or dynamic path to make future Python version updates easier.
| # Install core Python dependencies | |
| RUN pip install --no-cache-dir --upgrade pip numpy opencv-python-headless==4.6.0.66 | |
| # Copy compiled scene_common + fast_geometry from builder | |
| COPY --chown=$WSUSER:$WSUSER --from=scenescape-common-base-24-04 /usr/local/lib/python3.12/dist-packages/scene_common \ | |
| $BUILD_ENV_DIR/lib/python3.12/site-packages/scene_common | |
| COPY --chown=$WSUSER:$WSUSER --from=scenescape-common-base-24-04 /usr/local/lib/python3.12/dist-packages/fast_geometry \ | |
| $BUILD_ENV_DIR/lib/python3.12/site-packages/fast_geometry | |
| # Dynamically determine Python version (major.minor) | |
| ENV PYTHON_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')") | |
| # Install core Python dependencies | |
| RUN pip install --no-cache-dir --upgrade pip numpy opencv-python-headless==4.6.0.66 | |
| # Copy compiled scene_common + fast_geometry from builder | |
| COPY --chown=$WSUSER:$WSUSER --from=scenescape-common-base-24-04 /usr/local/lib/${PYTHON_VERSION}/dist-packages/scene_common \ | |
| $BUILD_ENV_DIR/lib/${PYTHON_VERSION}/site-packages/scene_common | |
| COPY --chown=$WSUSER:$WSUSER --from=scenescape-common-base-24-04 /usr/local/lib/${PYTHON_VERSION}/dist-packages/fast_geometry \ | |
| $BUILD_ENV_DIR/lib/${PYTHON_VERSION}/site-packages/fast_geometry |
| COPY --chown=$WSUSER:$WSUSER --from=scenescape-common-base-24-04 /usr/local/lib/python3.12/dist-packages/fast_geometry \ | ||
| $BUILD_ENV_DIR/lib/python3.12/site-packages/fast_geometry |
There was a problem hiding this comment.
The Python version 3.12 is hardcoded in the path. Since the base image is python:3.12-slim, consider using a variable or dynamic path to make future Python version updates easier.
📝 Description
Provide a clear summary of the changes and the context behind them. Describe what was changed, why it was needed, and how the changes address the issue or add value.
✨ Type of Change
Select the type of change your PR introduces:
🧪 Testing Scenarios
Describe how the changes were tested and how reviewers can test them too:
✅ Checklist
Before submitting the PR, ensure the following: