forked from GoSecure/pyrdp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.slim
84 lines (69 loc) · 2.73 KB
/
Dockerfile.slim
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
#
# This is a slimmer version of our docker image without the graphical player
# and notification system integration.
#
# Handles compiling and package installation
FROM ubuntu:20.04 AS compile-image
# Install build dependencies
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 python3-pip \
# Required for local pip install
python3-setuptools \
# Required for venv setup
python3-venv \
# Required to build RLE module
build-essential python3-dev \
# Required for ARM builds (because we need to build cryptography instead of using a prebuilt wheel)
libssl-dev libffi-dev
RUN python3 -m venv /opt/venv
# Make sure we use the virtualenv:
ENV PATH="/opt/venv/bin:$PATH"
# Required for ARM builds
# Building dependencies didn't work without an upgraded pip and wheel on ARM
RUN pip3 --no-cache-dir install -U pip wheel
# Install dependencies only (speeds repetitive builds)
COPY requirements-slim.txt /pyrdp/requirements.txt
# The following allows us to install the cryptography package.
# Eventually we will add rust to our compile-image and build with rust but
# rust's cargo is broken on docker ARM right now and we will wait until
# upstream is fixed.
ENV CRYPTOGRAPHY_DONT_BUILD_RUST=1
RUN cd /pyrdp && pip3 --no-cache-dir install -r requirements.txt
# Compile only our C extension and install
# This way changes to source tree will not trigger full images rebuilds
COPY ext/rle.c /pyrdp/ext/rle.c
COPY setup.py /pyrdp/setup.py
RUN cd /pyrdp \
&& python setup.py build_ext \
&& python setup.py install_lib
# Handles runtime only (minimize size for distribution)
FROM ubuntu:20.04 AS docker-image
# Install runtime dependencies except pre-built venv
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends python3 \
# To generate certificates
openssl \
# Required for the setup.py install
python3-distutils \
&& rm -rf /var/lib/apt/lists/*
# Copy preinstalled dependencies from compile image
COPY --from=compile-image /opt/venv /opt/venv
# Create user
RUN useradd --create-home --home-dir /home/pyrdp pyrdp
# Make sure we use the virtualenv
ENV PATH="/opt/venv/bin:$PATH"
# Install python source and package
# NOTE: we are no longer doing this in the compile image to avoid long image rebuilds in development
COPY --from=compile-image /pyrdp /pyrdp
COPY bin/ /pyrdp/bin/
COPY pyrdp/ /pyrdp/pyrdp/
COPY setup.py /pyrdp/setup.py
RUN cd /pyrdp \
&& python setup.py install
USER pyrdp
# UTF-8 support on the console output (for pyrdp-player)
ENV PYTHONIOENCODING=utf-8
# Make sure we use the virtualenv
ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /home/pyrdp