This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
99 lines (70 loc) · 2.35 KB
/
Dockerfile
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Use Python 3.10 debian
FROM python:3.10-slim as base
ENV PYTHONUNBUFFERED 1
ENV PYTHONFAULTHANDLER 1
# Update global dependencies
RUN apt-get update && \
apt-get upgrade -y
# Build the MJML package
FROM base as mjml-build
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.69.0
RUN apt-get install -y --no-install-recommends curl git build-essential
# Install rust
RUN set -ex; \
curl --proto '=https' --tlsv1.2 -sSf -o ./rustup-init https://sh.rustup.rs; \
chmod +x ./rustup-init; \
./rustup-init --profile minimal --no-modify-path --default-toolchain $RUST_VERSION -y; \
rm rustup-init; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
rustup --version; cargo --version; rustc --version
RUN pip install --no-cache-dir maturin
COPY ./mjml .
RUN maturin build --release --strip
FROM base as export-dependencies
RUN pip install --no-cache-dir poetry
# Export dependencies to requirements.txt format
COPY poetry.lock pyproject.toml ./
RUN poetry export -f requirements.txt -o requirements.txt
# Install dependencies for caching
FROM base as dependencies
# System build dependencies
RUN apt-get install -y --no-install-recommends build-essential git
# Install the depednencies
COPY --from=export-dependencies /requirements.txt ./
COPY --from=mjml-build /target/wheels/*.whl ./
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.txt --prefix=/dependencies --no-warn-script-location && \
pip install --no-cache-dir --prefix=/dependencies *.whl
# Setup the common files
FROM base as common
# Switch to a new user
RUN adduser --disabled-password app
USER app
WORKDIR /application-portal
# Copy over dependencies
COPY --from=dependencies /dependencies /usr/local
# Copy common project files
COPY --chown=app alembic.ini ./alembic.ini
COPY --chown=app common ./common
COPY --chown=app manage.py ./manage.py
# Add commit info
ARG COMMIT_SHA=dev
RUN echo "commit = \"$COMMIT_SHA\"" > common/version.py
###
# API
###
FROM common as api
EXPOSE 8000/tcp
COPY --chown=app api ./api
COPY --chown=app --chmod=775 docker-entrypoints/api.sh ./entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]
###
# Tasks
###
FROM common as tasks
COPY --chown=app tasks ./tasks
COPY --chown=app --chmod=775 docker-entrypoints/tasks.sh ./entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]