Skip to content

Commit 4e3d248

Browse files
committed
feat(docker): use python:3.7-alpine replace drycc/base
1 parent 26e6dca commit 4e3d248

9 files changed

Lines changed: 65 additions & 117 deletions

File tree

rootfs/Dockerfile

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,30 @@
1-
FROM quay.io/drycc/base:v0.3.6
2-
3-
RUN adduser --system \
4-
--shell /bin/bash \
5-
--disabled-password \
6-
--home /app \
7-
--group \
8-
drycc
1+
FROM python:3.7-alpine
92

103
COPY requirements.txt /app/requirements.txt
114

12-
RUN buildDeps='gcc libffi-dev libpq-dev libldap2-dev libsasl2-dev python3-dev python3-pip python3-wheel python3-setuptools'; \
13-
apt-get update && \
14-
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
15-
$buildDeps \
16-
sudo \
17-
libpq5 \
18-
libldap-2.4 \
19-
python3-minimal \
20-
# cryptography package needs pkg_resources
21-
python3-pkg-resources && \
22-
ln -s /usr/bin/python3 /usr/bin/python && \
23-
mkdir -p /configs && chown -R drycc:drycc /configs && \
24-
pip3 install --disable-pip-version-check --no-cache-dir -r /app/requirements.txt && \
25-
# cleanup
26-
apt-get purge -y --auto-remove $buildDeps && \
27-
apt-get autoremove -y && \
28-
apt-get clean -y && \
29-
rm -rf \
30-
/usr/share/doc \
31-
/usr/share/man \
32-
/usr/share/info \
33-
/usr/share/locale \
34-
/var/lib/apt/lists/* \
35-
/var/log/* \
36-
/var/cache/debconf/* \
37-
/etc/systemd \
38-
/lib/lsb \
39-
/lib/udev \
40-
/usr/lib/x86_64-linux-gnu/gconv/IBM* \
41-
/usr/lib/x86_64-linux-gnu/gconv/EBC* && \
42-
bash -c "mkdir -p /usr/share/man/man{1..8}"
5+
RUN apk add --update --virtual .build-deps \
6+
postgresql-dev \
7+
gcc \
8+
libffi-dev \
9+
musl-dev \
10+
openldap-dev \
11+
&& pip3 install --disable-pip-version-check --no-cache-dir -r /app/requirements.txt \
12+
&& runDeps="$( \
13+
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
14+
| tr ',' '\n' \
15+
| sort -u \
16+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
17+
)" \
18+
&& apk add --update --virtual .controller-rundeps \
19+
$runDeps \
20+
ca-certificates \
21+
su-exec \
22+
bash \
23+
shadow \
24+
&& apk del .build-deps
4325

4426
COPY . /app
4527

46-
# define execution environment
4728
WORKDIR /app
4829
CMD ["/app/bin/boot"]
4930
EXPOSE 8000

rootfs/Dockerfile.test

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,37 @@
1-
FROM quay.io/drycc/base:v0.3.6
2-
3-
RUN adduser --system \
4-
--shell /bin/bash \
5-
--disabled-password \
6-
--home /app \
7-
--group \
8-
drycc
1+
FROM python:3.7-alpine
92

103
COPY requirements.txt /app/requirements.txt
114
COPY dev_requirements.txt /app/dev_requirements.txt
125

13-
RUN buildDeps='gcc libffi-dev libpq-dev libldap2-dev libsasl2-dev python3-dev python3-pip python3-wheel python3-setuptools'; \
14-
apt-get update && \
15-
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
16-
$buildDeps \
17-
sudo \
18-
libpq5 \
19-
libldap-2.4 \
20-
python3-minimal \
21-
# cryptography package needs pkg_resources
22-
python3-pkg-resources && \
23-
ln -s /usr/bin/python3 /usr/bin/python && \
24-
mkdir -p /configs && chown -R drycc:drycc /configs && \
25-
pip3 install --disable-pip-version-check --no-cache-dir -r /app/requirements.txt && \
26-
# cleanup
27-
apt-get purge -y --auto-remove $buildDeps && \
28-
apt-get autoremove -y && \
29-
apt-get clean -y && \
30-
rm -rf \
31-
/usr/share/doc \
32-
/usr/share/man \
33-
/usr/share/info \
34-
/usr/share/locale \
35-
/var/lib/apt/lists/* \
36-
/var/log/* \
37-
/var/cache/debconf/* \
38-
/etc/systemd \
39-
/lib/lsb \
40-
/lib/udev \
41-
/usr/lib/x86_64-linux-gnu/gconv/IBM* \
42-
/usr/lib/x86_64-linux-gnu/gconv/EBC* && \
43-
bash -c "mkdir -p /usr/share/man/man{1..8}"
44-
45-
# define execution environment
46-
WORKDIR /app
6+
ENV PGDATA /var/lib/postgresql/11
7+
RUN mkdir -p /run/postgresql $PGDATA \
8+
&& chown -R postgres:postgres /run/postgresql $PGDATA \
9+
&& apk add --update --virtual .build-deps \
10+
postgresql-dev \
11+
gcc \
12+
libffi-dev \
13+
musl-dev \
14+
openldap-dev \
15+
&& pip3 install --disable-pip-version-check --no-cache-dir -r /app/requirements.txt \
16+
&& pip3 install --disable-pip-version-check --no-cache-dir -r /app/dev_requirements.txt \
17+
&& runDeps="$( \
18+
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
19+
| tr ',' '\n' \
20+
| sort -u \
21+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
22+
)" \
23+
&& apk add --update --virtual .controller-rundeps \
24+
$runDeps \
25+
ca-certificates \
26+
su-exec \
27+
bash \
28+
shadow \
29+
postgresql \
30+
&& apk del .build-deps \
31+
&& su-exec postgres initdb -D $PGDATA
4732

48-
# test-unit additions to the main Dockerfile
49-
ENV PGBIN=/usr/lib/postgresql/9.5/bin PGDATA=/var/lib/postgresql/data
50-
RUN apt-get update && \
51-
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
52-
git \
53-
postgresql \
54-
postgresql-contrib \
55-
python3-pip \
56-
python3-setuptools \
57-
python3-wheel && \
58-
pip3 install --disable-pip-version-check --no-cache-dir -r dev_requirements.txt && \
59-
sudo -u postgres -E $PGBIN/initdb
33+
COPY . /app
6034

61-
CMD ["/app/bin/test-unit"]
35+
WORKDIR /app
36+
CMD ["/app/bin/boot"]
37+
EXPOSE 8000

rootfs/api/tests/test_pods.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
44
Run the tests with "./manage.py test api"
55
"""
6+
import os
67
import json
78

89
from django.contrib.auth.models import User
910
from django.core.cache import cache
1011
from unittest import mock
1112
from rest_framework.authtoken.models import Token
12-
from test.support import EnvironmentVarGuard
1313

1414
from api.models import App, Build, Release
1515
from scheduler import KubeException
@@ -583,8 +583,7 @@ def test_run_not_fail_on_debug(self, mock_requests):
583583
"""
584584
do a run with DRYCC_DEBUG on - https://github.com/drycc/controller/issues/583
585585
"""
586-
env = EnvironmentVarGuard()
587-
env['DRYCC_DEBUG'] = 'true'
586+
os.environ['DRYCC_DEBUG'] = 'true'
588587

589588
app_id = self.create_app()
590589
app = App.objects.get(id=app_id)

rootfs/api/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def async_run(tasks):
154154
return
155155

156156
# start a new async event loop
157-
loop = asyncio.get_event_loop()
157+
loop = asyncio.new_event_loop()
158+
asyncio.set_event_loop(loop)
158159
# https://github.com/python/asyncio/issues/258
159160
executor = concurrent.futures.ThreadPoolExecutor(5)
160161
loop.set_default_executor(executor)

rootfs/bin/boot

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ python --version
1616
mkdir -p /app/data/logs
1717
chmod -R 777 /app/data/logs
1818

19-
# modify drycc user groups to grant access to Docker socket
20-
DOCKER_SOCKET_GID=$(stat -c "%g" /var/run/docker.sock)
21-
DOCKER_SOCKET_GROUP=$(getent group "$DOCKER_SOCKET_GID" | cut -d : -f 1 || :)
22-
if [[ -z "$DOCKER_SOCKET_GROUP" ]]; then
23-
DOCKER_SOCKET_GROUP=docker
24-
groupadd -g "$DOCKER_SOCKET_GID" "$DOCKER_SOCKET_GROUP"
25-
fi
26-
if [[ "$DOCKER_SOCKET_GROUP" != "drycc" ]]; then
27-
usermod -a -G "$DOCKER_SOCKET_GROUP" drycc
28-
fi
29-
30-
echo ""
3119
echo "Django checks:"
3220
python /app/manage.py check --deploy api
3321

@@ -37,12 +25,12 @@ python /app/manage.py healthchecks
3725

3826
echo ""
3927
echo "Database Migrations:"
40-
sudo -E -u drycc python /app/manage.py migrate --noinput
28+
python /app/manage.py migrate --noinput
4129

4230
# spawn a gunicorn server in the background
4331
echo ""
4432
echo "Starting up Gunicorn"
45-
sudo -E -u drycc gunicorn -c /app/drycc/gunicorn/config.py api.wsgi &
33+
gunicorn -c /app/drycc/gunicorn/config.py api.wsgi &
4634

4735
echo ""
4836
echo "Loading database information to Kubernetes in the background"

rootfs/bin/test-unit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# fail hard and fast even on pipelines
77
set -eou pipefail
88

9-
sudo -u postgres "$PGBIN"/pg_ctl -D "$PGDATA" -l /tmp/logfile start
9+
su-exec postgres pg_ctl -D "$PGDATA" start
1010
python3 manage.py check
1111
coverage run manage.py test --settings=api.settings.testing --noinput registry api scheduler.tests
1212
coverage report -m

rootfs/dev_requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# test module
2+
test
13
# Run "make test-unit" for the % of code exercised during tests
24
coverage==4.4.1
35

rootfs/drycc/gunicorn/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import os
21
from os.path import dirname, realpath
2+
from multiprocessing import cpu_count
3+
34
import faulthandler
45
faulthandler.enable()
56

67
bind = '0.0.0.0'
78
workers = 1
8-
threads = os.cpu_count() * 4
9+
threads = cpu_count() * 4 + 1
910

1011
pythonpath = dirname(dirname(dirname(realpath(__file__))))
1112
timeout = 1200

rootfs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ django-cors-middleware==1.3.1
66
django-guardian==1.4.9
77
djangorestframework==3.6.4
88
docker-py==1.10.6
9-
gunicorn==19.7.1
9+
gunicorn==19.9.0
1010
idna==2.6
1111
jmespath==0.9.3
1212
jsonfield==2.0.2

0 commit comments

Comments
 (0)