Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 56 additions & 27 deletions monitoring/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Dockerfile for interuss/monitoring
#
# This file should generally be used via `make image` and/or `make image-dev`
# from the repo root.
#
# The image generated by this Dockerfile (via ./build.sh) includes the entire
# `monitoring` folder contents in /app/monitoring and has installed dependencies
# necessary to run any of the monitoring tools. See documentation for any of
Expand All @@ -9,7 +12,31 @@
#
# This image is intended to be built from the repository root context/folder.

FROM ghcr.io/astral-sh/uv:0.12.5-python3.13-trixie-slim AS base
# Stage hierarchy:
# ghcr.io/astral-sh/uv
# │
# ▼
# [base-system]
# • Install system packages (apt)
# • RUN uv sync (base dependencies)
# • CACHED as long as uv.lock does not change
# │
# ┌──────────┴──────────┐
# │ (default) │
# ▼ ▼
# [base-system] [dev-dependencies]
# │ • RUN uv sync --group dev
# │ • CACHED as long as uv.lock does not change
# │ │
# └──────────┬──────────┘
# ▼
# [final] (FROM ${BASE_STAGE})
# • ADD ./monitoring
# • Ready for prod/dev

ARG BASE_STAGE=base-system

FROM ghcr.io/astral-sh/uv:0.12.5-python3.13-trixie-slim AS base-system
# Not -alpine because: https://stackoverflow.com/a/58028091/651139

# Install system tools
Expand All @@ -28,66 +55,68 @@ RUN if [ "$(uname -m)" = "aarch64" ]; then \

RUN mkdir -p /app/

# This image should be built by passing in `version` and `commit_hash` based on information from git (see `make image`)
# This version information becomes available in the environment variables specified below
ARG version
ARG commit_hash
ENV MONITORING_VERSION=$version
ENV GIT_COMMIT_HASH=$commit_hash

# Install dependencies
ENV UV_LINK_MODE=copy
ENV UV_PROJECT_ENVIRONMENT=/venv/
ENV VIRTUAL_ENV=/venv/
ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MONITORING=$version
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=./uv.lock,target=/app/uv.lock \
--mount=type=bind,source=./pyproject.toml,target=/app/pyproject.toml \
cd /app/ && \
uv sync --locked --no-install-project --compile-bytecode

# Ensure UV don't check dependencies or lock file, since we installed everything before
# Ensure UV doesn't check dependencies or lock file (we've already installed everything for the base system above)
ENV UV_FROZEN=1
ENV UV_NO_SYNC=1

# Ensure the cache folder is present and writable by anyone
# (Some command run with limited privileges)
# (Some commands run with limited privileges)
RUN mkdir -p /.cache/uv/ && chmod 777 /.cache/uv/
# Also fix the root folder where python is downloaded
RUN find /root/ -type d -exec chmod a+rx {} +

# Start in this folder
WORKDIR /app/monitoring

# Add core content from repo
ADD ./interfaces /app/interfaces
ADD ./monitoring /app/monitoring

# Add health check to the /app root and make it executable
COPY ./monitoring/health_check.sh /app/health_check.sh
RUN chmod 766 /app/health_check.sh

# Additional preparations for uss_qualifier/webapp
RUN mkdir -p /app/uss-host-files

# This script indicates the status of the container
HEALTHCHECK --interval=3s CMD sh /app/health_check.sh

# Discover `monitoring` module in Python
ENV PYTHONPATH=/app

# Add venv to path
ENV PATH="/venv/bin/:$PATH"


# No entry point maximizes flexibility in the use of this image
ENTRYPOINT []

FROM base AS with-dev-dependencies
FROM base-system AS dev-dependencies

# Install dev dependencies (unsetting flag not to check dependencies)
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=./uv.lock,target=/app/uv.lock \
--mount=type=bind,source=./pyproject.toml,target=/app/pyproject.toml \
cd /app/ && \
unset UV_FROZEN && \
uv sync --locked --no-install-project --compile-bytecode --group dev

FROM ${BASE_STAGE} AS final

# This image should be built by passing in `version` and `commit_hash` based on information from git (see `make image`)
# This version information becomes available in the environment variables specified below
ARG version
ARG commit_hash
ENV MONITORING_VERSION=$version
ENV GIT_COMMIT_HASH=$commit_hash
ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MONITORING=$version

# Add core content from repo
ADD ./interfaces /app/interfaces
ADD ./monitoring /app/monitoring

# Add health check to the /app root and make it executable
COPY ./monitoring/health_check.sh /app/health_check.sh
RUN chmod 766 /app/health_check.sh

# Additional preparations for uss_qualifier/webapp
RUN mkdir -p /app/uss-host-files

# This script indicates the status of the container
HEALTHCHECK --interval=3s CMD sh /app/health_check.sh
1 change: 0 additions & 1 deletion monitoring/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ docker image build \
-t "${TAG}" \
--build-arg version="$(scripts/git/version.sh monitoring --long)" \
--build-arg commit_hash="$(git rev-parse HEAD)" \
--target base \
. \
|| exit 1

Expand Down
2 changes: 1 addition & 1 deletion monitoring/build_dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ TAG="${1:-interuss/monitoring}"
docker image build \
-f monitoring/Dockerfile \
-t "${TAG}-dev" \
--build-arg BASE_STAGE=dev-dependencies \
--build-arg version="$(scripts/git/version.sh monitoring --long)" \
--build-arg commit_hash="$(git rev-parse HEAD)" \
--target with-dev-dependencies \
. \
|| exit 1

Expand Down
Loading