fix: isolate usercode container

This commit is contained in:
Stijnvandenbroek
2026-03-04 13:40:19 +00:00
parent 26a7271531
commit 46e8e983f1
3 changed files with 40 additions and 16 deletions

View File

@@ -1,8 +1,8 @@
FROM python:3.12-slim # ── Usercode: full application (gRPC server) ─────────────────────────
FROM python:3.12-slim AS usercode
WORKDIR /app WORKDIR /app
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Install dependencies before copying full source (layer caching) # Install dependencies before copying full source (layer caching)
@@ -12,9 +12,23 @@ RUN uv sync --frozen --no-dev 2>/dev/null || uv sync --no-dev
# Copy application source # Copy application source
COPY . . COPY . .
# Make the venv's binaries available on PATH
ENV PATH="/app/.venv/bin:$PATH" ENV PATH="/app/.venv/bin:$PATH"
ENV DAGSTER_HOME=/app/dagster_home ENV DAGSTER_HOME=/app/dagster_home
RUN chmod +x /app/entrypoint.sh RUN chmod +x /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"] ENTRYPOINT ["/app/entrypoint.sh"]
# ── Infrastructure: webserver / daemon (no user code) ────────────────
FROM python:3.12-slim AS dagster-infra
WORKDIR /app
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Only the Dagster packages needed to run webserver / daemon and reach
# the metadata store. No application code is installed.
RUN uv pip install --system dagster dagster-webserver dagster-postgres
COPY dagster_home/ ./dagster_home/
ENV DAGSTER_HOME=/app/dagster_home

View File

@@ -1,10 +1,5 @@
version: "3.9"
# Shared config for all dagster services # Shared config for all dagster services
x-dagster: &dagster-common x-dagster: &dagster-common
build:
context: .
dockerfile: Dockerfile
env_file: .env env_file: .env
environment: environment:
DAGSTER_HOME: /app/dagster_home DAGSTER_HOME: /app/dagster_home
@@ -37,34 +32,49 @@ services:
# User code gRPC server # User code gRPC server
dagster-usercode: dagster-usercode:
<<: *dagster-common <<: *dagster-common
build:
context: .
target: usercode
container_name: dagster-usercode container_name: dagster-usercode
command: ["dagster", "api", "grpc", "-h", "0.0.0.0", "-p", "4000", "-m", "data_platform"] command:
["dagster", "api", "grpc", "-h", "0.0.0.0", "-p", "4000", "-m", "data_platform.definitions"]
volumes: volumes:
- dbt-target:/app/dbt/target - dbt-target:/app/dbt/target
expose: expose:
- "4000" - "4000"
healthcheck:
test: ["CMD", "dagster", "api", "grpc-health-check", "-p", "4000"]
interval: 15s
timeout: 10s
retries: 5
start_period: 30s
# Web UI # Web UI
dagster-webserver: dagster-webserver:
<<: *dagster-common <<: *dagster-common
build:
context: .
target: dagster-infra
container_name: dagster-webserver container_name: dagster-webserver
entrypoint: [] command:
command: ["dagster-webserver", "-h", "0.0.0.0", "-p", "3000"] ["dagster-webserver", "-h", "0.0.0.0", "-p", "3000", "-w", "/app/dagster_home/workspace.yaml"]
ports: ports:
- "3000:3000" - "3000:3000"
depends_on: depends_on:
dagster-usercode: dagster-usercode:
condition: service_started condition: service_healthy
# Schedules, sensors and run queuing # Schedules, sensors and run queuing
dagster-daemon: dagster-daemon:
<<: *dagster-common <<: *dagster-common
build:
context: .
target: dagster-infra
container_name: dagster-daemon container_name: dagster-daemon
entrypoint: [] command: ["dagster-daemon", "run", "-w", "/app/dagster_home/workspace.yaml"]
command: ["dagster-daemon", "run"]
depends_on: depends_on:
dagster-usercode: dagster-usercode:
condition: service_started condition: service_healthy
volumes: volumes:
postgres-data: postgres-data:

View File

@@ -20,7 +20,7 @@ build-backend = "hatchling.build"
packages = ["data_platform"] packages = ["data_platform"]
[tool.dagster] [tool.dagster]
module_name = "data_platform" module_name = "data_platform.definitions"
attribute = "defs" attribute = "defs"
[dependency-groups] [dependency-groups]