Skip to content

Commit aaf2f87

Browse files
diahmetb
authored andcommitted
Simplify package management for python services (GoogleCloudPlatform#120)
This PR does a few things: 1. **Removes unnecessary Python dependencies currently being installed for `emailservice`** There are quite a few packages being installed that aren't actual dependencies. 2. **Removes a number of related, also unnecessary system-level dependencies for `emailservice`** These were a result of the Python dependencies that are unnecessary. 3. **Pins all of the sub-dependencies for `loadgenerator`** This is good practice to ensure that things don't break one day in the future when a newer version of an unpinned sub-dependenency is released. 4. **Compile all Python dependencies from `requirements.in` files** This is mostly bookkeeping. It allows us to only specify the top-level dependencies we care about in the requirements.in files, which are then compiled to frozen dependencies in the requirements.txt files. This ensures that we only install the dependencies we need, and that we're not missing any unpinned sub-dependencies. It also makes it more clear where our sub-dependencies are coming from. 5. **Switch to -slim images from -alpine** Python's built distribution format (wheel) is incompatible with alpine-based images, causing dependencies like `grpcio` to be compiled from scratch, rather than from a pre-built wheel. This should improve or possibly fi​x GoogleCloudPlatform#58, while keeping the image size roughly the same: ``` emailservice latest d1b818eabe05 6 seconds ago 286MB loadgenerator latest 4d9b5acbfbbb 6 seconds ago 125MB ```
1 parent 823e993 commit aaf2f87

File tree

6 files changed

+64
-65
lines changed

6 files changed

+64
-65
lines changed

src/emailservice/Dockerfile

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
FROM python:3-alpine as base
1+
FROM python:3-slim as base
22

33
FROM base as builder
44

5-
# gRPC and app deps
6-
RUN apk add --update --no-cache \
7-
gcc \
8-
linux-headers \
9-
make \
10-
musl-dev \
11-
python-dev \
12-
g++ \
13-
# App Deps
14-
cairo-dev \
15-
cairo \
16-
openssl-dev \
17-
gobject-introspection-dev
18-
195
# get packages
206
COPY requirements.txt .
217
RUN pip install -r requirements.txt
@@ -25,6 +11,10 @@ FROM base as final
2511
# Enable unbuffered logging
2612
ENV PYTHONUNBUFFERED=1
2713

14+
RUN apt-get -qq update \
15+
&& apt-get install -y --no-install-recommends \
16+
wget
17+
2818
# Download the grpc health probe
2919
RUN GRPC_HEALTH_PROBE_VERSION=v0.2.0 && \
3020
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
@@ -35,9 +25,6 @@ WORKDIR /email_server
3525
# Grab packages from builder
3626
COPY --from=builder /usr/local/lib/python3.7/ /usr/local/lib/python3.7/
3727

38-
# Need libstdc++ for grpc
39-
RUN apk add --no-cache libstdc++
40-
4128
# Add the application
4229
COPY . .
4330

src/emailservice/requirements.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
google-api-core==1.6.0
2+
grpcio-health-checking==1.12.1
3+
grpcio==1.16.1
4+
jinja2==2.10
5+
opencensus[stackdriver]==0.1.10
6+
python-json-logger==0.1.9

src/emailservice/requirements.txt

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,29 @@
1-
asn1crypto==0.24.0
2-
cachetools==2.1.0
3-
certifi==2018.8.24
4-
cffi==1.11.5
5-
chardet==3.0.4
6-
configparser==3.5.0
7-
cryptography==2.3.1
8-
entrypoints==0.2.3
9-
enum34==1.1.6
10-
futures==3.1.1
11-
google-api-core==1.6.0
12-
google-auth==1.6.1
13-
google-cloud-core==0.29.0
14-
googleapis-common-protos==1.5.3
15-
grpc-google-iam-v1==0.11.4
16-
grpcio==1.16.1
1+
#
2+
# This file is autogenerated by pip-compile
3+
# To update, run:
4+
#
5+
# pip-compile --output-file requirements.txt requirements.in
6+
#
7+
cachetools==3.0.0 # via google-auth
8+
certifi==2018.11.29 # via requests
9+
chardet==3.0.4 # via requests
10+
google-api-core[grpc]==1.6.0
11+
google-auth==1.6.2 # via google-api-core
12+
google-cloud-core==0.29.1 # via google-cloud-trace
13+
google-cloud-trace==0.20.2 # via opencensus
14+
googleapis-common-protos==1.5.5 # via google-api-core
1715
grpcio-health-checking==1.12.1
18-
grpcio-tools==1.12.1
19-
idna==2.7
20-
ipaddress==1.0.22
21-
jeepney==0.4
22-
Jinja2==2.10
23-
keyring==15.1.0
24-
keyrings.alt==3.1
25-
MarkupSafe==1.0
16+
grpcio==1.16.1
17+
idna==2.8 # via requests
18+
jinja2==2.10
19+
markupsafe==1.1.0 # via jinja2
2620
opencensus[stackdriver]==0.1.10
27-
protobuf==3.6.1
28-
pyasn1==0.4.4
29-
pyasn1-modules==0.2.2
30-
pycairo==1.17.1
31-
pycparser==2.19
32-
pycrypto==2.6.1
33-
PyGObject==3.30.1
21+
protobuf==3.6.1 # via google-api-core, googleapis-common-protos, grpcio-health-checking
22+
pyasn1-modules==0.2.3 # via google-auth
23+
pyasn1==0.4.5 # via pyasn1-modules, rsa
3424
python-json-logger==0.1.9
35-
pytz==2018.5
36-
pyxdg==0.26
37-
requests==2.20.0
38-
rsa==4.0
39-
SecretStorage==3.1.0
40-
six==1.11.0
41-
urllib3==1.23
25+
pytz==2018.9 # via google-api-core
26+
requests==2.21.0 # via google-api-core
27+
rsa==4.0 # via google-auth
28+
six==1.12.0 # via google-api-core, google-auth, grpcio, protobuf
29+
urllib3==1.24.1 # via requests

src/loadgenerator/Dockerfile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
FROM python:3-alpine as base
1+
FROM python:3-slim as base
22

33
FROM base as builder
44

5-
RUN apk add --update --no-cache \
6-
gcc \
7-
linux-headers \
8-
make \
9-
musl-dev \
10-
python-dev \
11-
g++
5+
RUN apt-get -qq update \
6+
&& apt-get install -y --no-install-recommends \
7+
g++
128

139
COPY requirements.txt .
1410

src/loadgenerator/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
locustio==0.8.1

src/loadgenerator/requirements.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
1+
#
2+
# This file is autogenerated by pip-compile
3+
# To update, run:
4+
#
5+
# pip-compile --output-file requirements.txt requirements.in
6+
#
7+
certifi==2018.11.29 # via requests
8+
chardet==3.0.4 # via requests
9+
click==7.0 # via flask
10+
flask==1.0.2 # via locustio
11+
gevent==1.4.0 # via locustio
12+
greenlet==0.4.15 # via gevent
13+
idna==2.8 # via requests
14+
itsdangerous==1.1.0 # via flask
15+
jinja2==2.10 # via flask
116
locustio==0.8.1
2-
pyzmq==17.0.0
17+
markupsafe==1.1.0 # via jinja2
18+
msgpack-python==0.5.6 # via locustio
19+
pyzmq==17.0.0 # via locustio
20+
requests==2.21.0 # via locustio
21+
six==1.12.0 # via locustio
22+
urllib3==1.24.1 # via requests
23+
werkzeug==0.14.1 # via flask

0 commit comments

Comments
 (0)