Skip to content

Instantly share code, notes, and snippets.

@innat
Created September 18, 2022 06:18
Show Gist options
  • Save innat/4ee9698b6c4872ec78f5fd8e43c4dc6a to your computer and use it in GitHub Desktop.
Save innat/4ee9698b6c4872ec78f5fd8e43c4dc6a to your computer and use it in GitHub Desktop.
# Base Image: Ubuntu + Cuda
FROM nvidia/cuda:11.0.3-devel-ubuntu20.04 AS python_base_cuda
# ENV SET
ENV PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_NO_INTERACTION=1 \
POETRY_HOME="/opt/poetry" \
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv" \
POETRY_VERSION=1.2.0 \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1
# prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
FROM python_base_cuda AS builder-base
# Update system and install wget
RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get -yq install --no-install-recommends -y \
wget=1.20.3-1ubuntu2 \
ffmpeg=7:4.2.7-0ubuntu0.1 \
libpython3.8=3.8.10-0ubuntu1~20.04.5 \
git=1:2.25.1-1ubuntu3.5 \
sudo=1.8.31-1ubuntu1.2 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install dependencies
RUN apt-get update && apt-get install -y \
software-properties-common \
curl \
python3.8 \
python3-pip
# System deps:
RUN curl -sSL https://install.python-poetry.org | python3 - --version $POETRY_VERSION
WORKDIR $PYSETUP_PATH
COPY poetry.lock pyproject.toml ./
# Project initialization
RUN poetry install --only main --no-root --no-ansi
FROM python_base_cuda AS development
ENV ANOMALY_ENV=development
WORKDIR $PYSETUP_PATH
RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get -yq install --no-install-recommends -y \
wget=1.20.3-1ubuntu2 \
ffmpeg=7:4.2.7-0ubuntu0.1 \
libpython3.8=3.8.10-0ubuntu1~20.04.5 \
git=1:2.25.1-1ubuntu3.5 \
sudo=1.8.31-1ubuntu1.2 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install dependencies
RUN apt-get update && apt-get install -y \
software-properties-common \
curl \
python3.8 \
python3-pip
# copy in our built poetry + venv
COPY --from=builder-base $POETRY_HOME $POETRY_HOME
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH
# quicker install as runtime deps are already installed
RUN poetry install
# Moving working files to docker file system.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment