-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
78 lines (58 loc) · 2.26 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
ARG PYTHON_VER
FROM python:${PYTHON_VER}-slim as labby-base
USER 0
ARG DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1 \
LABBY_ROOT=/opt/labby
# Upgrade and install system's dependencies
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends vim git openssh-client telnet && \
apt-get autoremove -y && \
apt-get clean all && \
rm -rf /var/lib/apt/lists/* && \
pip --no-cache-dir install --upgrade pip wheel
# Generate required dirs for later consumption
RUN mkdir /opt/labby
# -------------------------------------------------------------------------------------
# Development Image
# -------------------------------------------------------------------------------------
FROM python:${PYTHON_VER} as labby-dev
# Upgrade and install system's dependencies
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends gcc gcc-multilib && \
apt-get autoremove -y && \
apt-get clean all && \
rm -rf /var/lib/apt/lists/* && \
pip --no-cache-dir install --upgrade pip wheel
RUN pip install poetry
COPY . /source
# Install dependencies
SHELL ["/bin/bash", "-c"]
RUN cd /source && \
poetry config virtualenvs.create false && \
poetry install --no-interaction --no-ansi && \
mkdir /tmp/dist && \
poetry export --without-hashes -o /tmp/dist/requirements.txt
WORKDIR /source
# Generate labby wheel
RUN poetry build
# -------------------------------------------------------------------------------------
# Final Image
# -------------------------------------------------------------------------------------
FROM labby-base as labby
ARG PYTHON_VER
# Copy necessary dependencies and wheel from dev phase
COPY --from=labby-dev /usr/local/lib/python${PYTHON_VER}/site-packages /usr/local/lib/python${PYTHON_VER}/site-packages
COPY --from=labby-dev /usr/local/bin /opt/labby/.local/bin
COPY --from=labby-dev /source/dist/*.whl /tmp
# Create labby's user to not use root
RUN useradd --system --shell /bin/bash --create-home --home-dir /opt/labby labby && \
chown -R labby:labby /opt/labby /tmp/*.whl
USER labby
WORKDIR /opt/labby
# Install labby
RUN pip install --no-deps --no-cache-dir /tmp/*.whl && \
rm -rf /tmp/*.whl
ENV PATH="/opt/labby/.local/bin:${PATH}"