-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (45 loc) · 1.45 KB
/
Dockerfile
File metadata and controls
58 lines (45 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# pull official base image
FROM python:3.11-bookworm as base
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DEBIAN_FRONTEND=noninteractive
# install system dependencies
RUN set -eux; \
apt update; \
apt -y upgrade; \
pip install --no-cache-dir --upgrade pip; \
apt autoremove -y; \
apt clean; \
rm -rf /var/lib/apt/lists/*;
FROM base AS python-deps
ENV PATH="${PATH}:/root/.local/bin"
ENV PATH="/root/.cargo/bin:${PATH}"
# Install poetry and rust
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN set -eux; \
apt-get update; \
apt-get install --no-install-recommends curl gcc libc6-dev clang lld -y; \
curl -sSL https://install.python-poetry.org | python3 -; \
curl https://sh.rustup.rs -sSf | sh -s -- -y; \
poetry self update
# Install python dependencies in /.venv and build the Rust extension
COPY pyproject.toml poetry.lock ./
COPY ./rust-pidigits ./rust-pidigits
RUN POETRY_VIRTUALENVS_IN_PROJECT=1 poetry install
RUN poetry run maturin build -m rust-pidigits/Cargo.toml; \
poetry run pip install rust-pidigits/target/wheels/*.whl;
FROM base AS runtime
# set work directory
WORKDIR /app
# Copy virtual env from python-deps stage
COPY --from=python-deps /.venv /.venv
ENV PATH="/.venv/bin:$PATH"
# create the app user
RUN adduser --group --system appuser; \
chown appuser:appuser /app
# copy project
COPY src start.bash ./
# run entrypoint
USER appuser
EXPOSE 8000
ENTRYPOINT ["bash", "start.bash"]