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
/
Copy pathDockerfile
68 lines (48 loc) · 2.02 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
ARG MINICONDA_IMAGE_TAG=4.10.3-alpine
FROM continuumio/miniconda3:$MINICONDA_IMAGE_TAG AS base
# add bash, because it's not available by default on alpine
RUN apk add --no-cache bash
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", "cilroy", "/bin/bash", "-c"]
WORKDIR /app/cilroy/
# add poetry files
COPY ./cilroy/pyproject.toml ./cilroy/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 ./cilroy/src/ ./src/
COPY ./cilroy/tests/ ./tests/
COPY ./cilroy/LICENSE ./cilroy/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 cilroy
# 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 ./cilroy/src/ ./src/
COPY ./cilroy/LICENSE ./cilroy/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 cilroy
# add entrypoint
COPY ./entrypoint.sh ./entrypoint.sh
ENTRYPOINT ["./entrypoint.sh", "cilroy"]
CMD []