This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
77 lines (56 loc) · 2.52 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
ARG MINICONDA_IMAGE_TAG=4.10.3
FROM continuumio/miniconda3:$MINICONDA_IMAGE_TAG AS base
WORKDIR /app/
# install poetry
COPY ./requirements.txt ./requirements.txt
RUN --mount=type=cache,target=/root/.cache \
python3 -m pip install -r ./requirements.txt
# create new environment
# warning: for some reason conda can hang on "Executing transaction" for a couple of minutes
COPY environment.yaml ./environment.yaml
RUN --mount=type=cache,target=/opt/conda/pkgs \
conda env create -f ./environment.yaml
# "activate" environment for all commands (note: ENTRYPOINT is separate from SHELL)
SHELL ["conda", "run", "--no-capture-output", "-n", "kilroy-face-discord", "/bin/bash", "-c"]
WORKDIR /app/kilroy_face_discord/
# add poetry files
COPY ./kilroy_face_discord/pyproject.toml ./kilroy_face_discord/poetry.lock ./
FROM base AS test
# install dependencies only (notice that no source code is present yet)
RUN --mount=type=cache,target=/root/.cache \
poetry install --no-root --only main,test
# add source, tests and necessary files
COPY ./kilroy_face_discord/src/ ./src/
COPY ./kilroy_face_discord/tests/ ./tests/
COPY ./kilroy_face_discord/LICENSE ./kilroy_face_discord/README.md ./
# build wheel by poetry and install by pip (to force non-editable mode)
RUN poetry build -f wheel && \
python -m pip install --no-deps --no-index --no-cache-dir --find-links=dist kilroy-face-discord
RUN --mount=type=cache,target=/etc/torch-tmp \
TORCH_HOME=/etc/torch-tmp kilroy-face-discord-fetch-models && \
mkdir -p /etc/torch && \
cp -rup /etc/torch-tmp/* /etc/torch
ENV TORCH_HOME=/etc/torch
# add entrypoint
COPY ./entrypoint.sh ./entrypoint.sh
ENTRYPOINT ["./entrypoint.sh", "pytest"]
CMD []
FROM base AS production
# install dependencies only (notice that no source code is present yet)
RUN --mount=type=cache,target=/root/.cache \
poetry install --no-root --only main
# add source and necessary files
COPY ./kilroy_face_discord/src/ ./src/
COPY ./kilroy_face_discord/LICENSE ./kilroy_face_discord/README.md ./
# build wheel by poetry and install by pip (to force non-editable mode)
RUN poetry build -f wheel && \
python -m pip install --no-deps --no-index --no-cache-dir --find-links=dist kilroy-face-discord
RUN --mount=type=cache,target=/etc/torch-tmp \
TORCH_HOME=/etc/torch-tmp kilroy-face-discord-fetch-models && \
mkdir -p /etc/torch && \
cp -rup /etc/torch-tmp/* /etc/torch
ENV TORCH_HOME=/etc/torch
# add entrypoint
COPY ./entrypoint.sh ./entrypoint.sh
ENTRYPOINT ["./entrypoint.sh", "kilroy-face-discord"]
CMD []