Skip to content

Commit a97b83d

Browse files
author
Jaime Buelta
committed
Update to Alpine:3.6 (and python3.6)
Need to include a hack to solve a problem with running runserver in python3.6. Check for more info: docker-library/python#211
1 parent 36ae254 commit a97b83d

File tree

10 files changed

+61
-12
lines changed

10 files changed

+61
-12
lines changed

Dockerfile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.5
1+
FROM alpine:3.6
22

33
ARG django_secret_key
44
ENV DJANGO_SECRET_KEY $django_secret_key
@@ -9,6 +9,9 @@ RUN apk add --update postgresql-libs
99
RUN apk add --update curl
1010
# Add envsubts
1111
RUN apk add --update gettext
12+
# Add nginx
13+
RUN apk add --update nginx
14+
RUN mkdir -p /run/nginx
1215

1316
RUN mkdir -p /opt/code
1417
WORKDIR /opt/code
@@ -21,11 +24,21 @@ ADD ./deps /opt/deps
2124
# Only install them if there's any
2225
RUN if ls /opt/vendor/*.whl 1> /dev/null 2>&1; then pip3 install /opt/vendor/*.whl; fi
2326

27+
# Add uwsgi and nginx configuration
28+
RUN mkdir -p /opt/server
29+
RUN mkdir -p /opt/static
30+
31+
32+
# Add fix for stack for Python3.6
33+
ADD ./docker/server/stack-fix.c /opt/server
34+
2435
# Some Docker-fu. In one step install the compile packages, install the
2536
# dependencies and then remove them. That skims the image size quite
2637
# sensibly.
2738
RUN apk add --no-cache --virtual .build-deps \
2839
python3-dev build-base linux-headers gcc postgresql-dev \
40+
# Hack to fix the problem with runserver
41+
&& gcc -shared -fPIC /opt/server/stack-fix.c -o /opt/server/stack-fix.so \
2942
# Installing python requirements
3043
&& pip3 install -r requirements.txt \
3144
&& find /usr/local \
@@ -45,11 +58,6 @@ RUN apk add --no-cache --virtual .build-deps \
4558
&& apk del .build-deps
4659

4760

48-
# Add uwsgi and nginx configuration
49-
RUN mkdir -p /opt/server
50-
RUN mkdir -p /opt/static
51-
RUN apk add --update nginx
52-
RUN mkdir -p /run/nginx
5361
ADD ./docker/server/uwsgi.ini.template /opt/server
5462
ADD ./docker/server/nginx.conf.template /opt/server
5563
ADD ./docker/server/start_server.sh /opt/server

docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ services:
4444
command: /opt/copy_deps.sh
4545
dev-server:
4646
env_file: environment.env
47+
environment:
48+
- CONSOLE_LOGS=1
4749
build:
4850
context: .
4951
args:

docker/db/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# FROM rlesouef/alpine-postgres
2-
FROM alpine:3.5
1+
FROM alpine:3.6
32

43
# Add the proper env variables for init the db
54
ARG POSTGRES_DB

docker/deps/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.5
1+
FROM alpine:3.6
22
RUN mkdir -p /opt/vendor
33
WORKDIR /opt/vendor
44
RUN apk update

docker/log/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.5
1+
FROM alpine:3.6
22

33
RUN apk add --update syslog-ng
44

docker/server/stack-fix.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <dlfcn.h>
2+
#include <pthread.h>
3+
#include <stdio.h>
4+
5+
// THIS IS TO AVOID A SIGFAULT WHEN RUNNING python3.6 manage.py runserver
6+
// This should be fixed at some point by Alpine and/or Python
7+
// Check this issue for more info
8+
// https://github.com/docker-library/python/issues/211
9+
typedef int (*func_t)(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg);
10+
11+
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) {
12+
printf("XXX pthread_create override called.\n");
13+
14+
pthread_attr_t local;
15+
int used = 0, ret;
16+
17+
if (!attr) {
18+
used = 1;
19+
pthread_attr_init(&local);
20+
attr = &local;
21+
}
22+
pthread_attr_setstacksize((void*)attr, 2 * 1024 * 1024); // 2 MB
23+
24+
func_t orig = (func_t)dlsym(RTLD_NEXT, "pthread_create");
25+
26+
ret = orig(thread, attr, start_routine, arg);
27+
28+
if (used) {
29+
pthread_attr_destroy(&local);
30+
}
31+
32+
return ret;
33+
}

docker/system-test/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.5
1+
FROM alpine:3.6
22

33
RUN apk add --update python3 py3-pip pytest
44
RUN mkdir -p /opt/system-test

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
uwsgi==2.0.15
2-
Django==1.11
2+
Django==1.11.4
33
pytest-django==3.1.2
44
psycopg2==2.7.3
55
djangorestframework==3.6.3

src/start_dev_server.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#!/bin/sh
22
python3 manage.py migrate -v 3
3+
# Preload hack to avoid sigfault
4+
export LD_PRELOAD=/opt/server/stack-fix.so
35
python3 manage.py runserver 0.0.0.0:80

src/templatesite/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
formatter = logging.Formatter('SETTINGS %(levelname)-8s %(message)s')
2626
handler.setFormatter(formatter)
2727
settings_logger.addHandler(handler)
28+
# Log settings also in stdout
29+
handler = logging.StreamHandler()
30+
handler.setFormatter(formatter)
31+
settings_logger.addHandler(handler)
32+
2833
settings_logger.setLevel(logging.INFO)
2934

3035
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)

0 commit comments

Comments
 (0)