|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | + |
| 3 | +# Based on https://gist.githubusercontent.com/usr-ein/c42d98abca3cb4632ab0c2c6aff8c88a/raw/19dcc899f68d0b08c2c137d3fd01715b0c84bac9/Dockerfile |
| 4 | + |
| 5 | +################################ |
| 6 | +# PYTHON-BASE |
| 7 | +# Sets up all our shared environment variables |
| 8 | +################################ |
| 9 | +FROM --platform=$TARGETPLATFORM python:3.11-slim as python-base |
| 10 | + |
| 11 | +ARG TARGETPLATFORM |
| 12 | + |
| 13 | + # python |
| 14 | +ENV PYTHONUNBUFFERED=1 \ |
| 15 | + # prevents python creating .pyc files |
| 16 | + PYTHONDONTWRITEBYTECODE=1 \ |
| 17 | + \ |
| 18 | + # pip |
| 19 | + PIP_DISABLE_PIP_VERSION_CHECK=on \ |
| 20 | + PIP_DEFAULT_TIMEOUT=100 \ |
| 21 | + \ |
| 22 | + # poetry |
| 23 | + # https://python-poetry.org/docs/configuration/#using-environment-variables |
| 24 | + POETRY_VERSION=1.6.1 \ |
| 25 | + # make poetry install to this location |
| 26 | + POETRY_HOME="/opt/poetry" \ |
| 27 | + # make poetry create the virtual environment in the project's root |
| 28 | + # it gets named `.venv` |
| 29 | + POETRY_VIRTUALENVS_IN_PROJECT=true \ |
| 30 | + # do not ask any interactive question |
| 31 | + POETRY_NO_INTERACTION=1 \ |
| 32 | + \ |
| 33 | + # paths |
| 34 | + # this is where our requirements + virtual environment will live |
| 35 | + PYSETUP_PATH="/opt/pysetup" \ |
| 36 | + VENV_PATH="/opt/pysetup/.venv" |
| 37 | + |
| 38 | + |
| 39 | +# prepend poetry and venv to path |
| 40 | +ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH" |
| 41 | + |
| 42 | + |
| 43 | +################################ |
| 44 | +# BUILDER-BASE |
| 45 | +# Used to build deps + create our virtual environment |
| 46 | +################################ |
| 47 | +FROM python-base as builder-base |
| 48 | +RUN apt-get update \ |
| 49 | + && apt-get install --no-install-recommends -y \ |
| 50 | + # deps for installing poetry |
| 51 | + curl \ |
| 52 | + # deps for building python deps |
| 53 | + build-essential |
| 54 | + |
| 55 | +# install poetry - respects $POETRY_VERSION & $POETRY_HOME |
| 56 | +# The --mount will mount the buildx cache directory to where |
| 57 | +# Poetry and Pip store their cache so that they can re-use it |
| 58 | +RUN --mount=type=cache,target=/root/.cache \ |
| 59 | + curl -sSL https://install.python-poetry.org | python3 - |
| 60 | + |
| 61 | +# copy project requirement files here to ensure they will be cached. |
| 62 | +WORKDIR $PYSETUP_PATH |
| 63 | +COPY ../../poetry.lock pyproject.toml ./ |
| 64 | + |
| 65 | +# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally |
| 66 | +RUN --mount=type=cache,target=/root/.cache \ |
| 67 | + poetry install --with dagster-webserver,dagster --without mlflow |
| 68 | + |
| 69 | + |
| 70 | +################################ |
| 71 | +# PRODUCTION |
| 72 | +# Final image used for runtime |
| 73 | +################################ |
| 74 | +FROM python-base as production |
| 75 | +COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH |
| 76 | + |
| 77 | +RUN mkdir -p /opt/dagster/dagster_home /opt/dagster/app |
| 78 | + |
| 79 | +ENV DAGSTER_HOME=/opt/dagster/dagster_home/ |
| 80 | + |
| 81 | +# Copy your workspace to /opt/dagster/app |
| 82 | + |
| 83 | +COPY ./docker/dagster/workspace.yaml /opt/dagster/app/ |
| 84 | +COPY ./docker/dagster/dagster.yaml $DAGSTER_HOME/ |
| 85 | + |
| 86 | + |
| 87 | +WORKDIR /opt/dagster/app |
| 88 | +EXPOSE 3000 |
| 89 | +ENV SHELL="/bin/bash" |
| 90 | + |
| 91 | +ENTRYPOINT ["dagster","dev","-h","0.0.0.0","-p","3000"] |
0 commit comments