This repository was archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
71 lines (51 loc) · 1.33 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
# Dockerfile for Python gRPC SSL Example.
#
# The base stage defines the path to the virtual environment.
# The build stage installs the build dependencies.
# The main stage installs the runtime dependencies.
#
# Base stage
#
# Base Python image version
ARG PYTHON_VERSION=3.8-alpine3.11
FROM python:${PYTHON_VERSION} as base
# Path to virtual environment
ENV VIRTUAL_ENV=/opt/venv
# Disable Python output buffering
ENV PYTHONUNBUFFERED=1
#
# Builder stage
#
FROM base as builder
# Path to virtual environment
ENV VIRTUAL_ENV=/opt/venv
# Install build dependencies
RUN apk add --no-cache --update \
build-base \
linux-headers
# Create virtual environment owned by guest user
RUN python -m venv $VIRTUAL_ENV && \
chown -R guest $VIRTUAL_ENV
# Switch to guest user
USER guest
# Install packages into virtual environment
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
COPY requirements.txt .
RUN pip install -U pip && \
pip install -r requirements.txt
#
# Main stage
#
FROM base
# Install runtime dependencies
RUN apk add --no-cache --update \
libstdc++
# Switch to guest user
USER guest
# Copy virtual environment from builder stage
COPY --from=builder $VIRTUAL_ENV $VIRTUAL_ENV
# Copy application files
COPY . /opt/app
# Activate virtual environment
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
CMD [ "python", "/opt/app/shopping_list_server.py" ]