Skip to content

Commit 1e8fc0f

Browse files
committed
Re-structure code to support multiple python version
1 parent 8d00b4d commit 1e8fc0f

File tree

17 files changed

+375
-24
lines changed

17 files changed

+375
-24
lines changed

.dockerignore

Lines changed: 0 additions & 18 deletions
This file was deleted.

Dockerfile renamed to 2.7/Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
FROM python:2.7
2-
MAINTAINER Inspectorio DevOps <devops@inspectorio.com>
32

43
ARG DEBIAN_FRONTEND=noninteractive
54
ARG PIP_NO_CACHE_DIR=1
@@ -11,19 +10,23 @@ ENV APP_HOME /app
1110
ENV APP_SHELL /bin/bash
1211
ENV NGINX_WORKER 4
1312

14-
ONBUILD ADD . "${APP_HOME}"
15-
ONBUILD ADD config /etc
16-
ONBUILD WORKDIR "${APP_HOME}"
13+
ONBUILD COPY . ${APP_HOME}
14+
ONBUILD COPY config /etc
15+
ONBUILD WORKDIR ${APP_HOME}
16+
ONBUILD RUN chmod a+x "${APP_HOME}/entrypoint.sh"
1717

1818
COPY requirements.txt /tmp/requirements.txt
1919
COPY entrypoint.sh /tmp/entrypoint.sh
2020
COPY config /etc/
2121

22+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
23+
2224
RUN groupadd "${APP_GRP}" \
2325
&& groupadd supervisor \
2426
&& useradd --create-home --home-dir "${APP_HOME}" --shell "${APP_SHELL}" --gid "${APP_GRP}" "${APP_USER}" \
2527
&& usermod -a -G supervisor "${APP_USER}" \
2628
&& mv /tmp/entrypoint.sh "${APP_HOME}/entrypoint.sh" \
29+
&& chmod a+x "${APP_HOME}/entrypoint.sh" \
2730
&& chown -R "${APP_USER}":"${APP_GRP}" "${APP_HOME}" \
2831
&& apt-get -qq -y update \
2932
&& apt-get install -qq -o Dpkg::Options::="--force-confold" \
File renamed without changes.
File renamed without changes.
File renamed without changes.

3.6/Dockerfile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
FROM python:3.6
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
ARG PIP_NO_CACHE_DIR=1
5+
ARG PIP_CACHE_DIR=/tmp/
6+
7+
ENV APP_USER app
8+
ENV APP_GRP app
9+
ENV APP_HOME /app
10+
ENV APP_SHELL /bin/bash
11+
ENV NGINX_WORKER 4
12+
13+
ONBUILD COPY . ${APP_HOME}
14+
ONBUILD COPY config /etc
15+
ONBUILD WORKDIR ${APP_HOME}
16+
ONBUILD RUN chmod a+x "${APP_HOME}/entrypoint.sh"
17+
18+
COPY requirements.txt /tmp/requirements.txt
19+
COPY entrypoint.sh /tmp/entrypoint.sh
20+
COPY config /etc/
21+
22+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
23+
24+
RUN groupadd "${APP_GRP}" \
25+
&& groupadd supervisor \
26+
&& useradd --create-home --home-dir "${APP_HOME}" --shell "${APP_SHELL}" --gid "${APP_GRP}" "${APP_USER}" \
27+
&& usermod -a -G supervisor "${APP_USER}" \
28+
&& mv /tmp/entrypoint.sh "${APP_HOME}/entrypoint.sh" \
29+
&& chmod a+x "${APP_HOME}/entrypoint.sh" \
30+
&& chown -R "${APP_USER}":"${APP_GRP}" "${APP_HOME}" \
31+
&& apt-get -qq -y update \
32+
&& apt-get install -qq -o Dpkg::Options::="--force-confold" \
33+
-y --no-install-recommends \
34+
supervisor curl jq vim-nox openssh-client \
35+
moreutils gettext-base locales tzdata lsb-release \
36+
&& curl -sSL http://nginx.org/keys/nginx_signing.key | apt-key add - \
37+
&& echo "deb http://nginx.org/packages/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ $(lsb_release -cs) nginx" > /etc/apt/sources.list.d/nginx.list \
38+
&& apt-get -qq -y update \
39+
&& apt-get -qq -o Dpkg::Options::="--force-confold" -y install nginx \
40+
&& /bin/rm -f /etc/nginx/nginx.conf.dpkg-dist /etc/supervisor/supervisord.conf.dpkg-dist \
41+
&& ln -sf /dev/stdout /var/log/nginx/access.log \
42+
&& ln -sf /dev/stderr /var/log/nginx/error.log \
43+
&& rm -f /etc/nginx/conf.d/* /etc/nginx/sites-enabled/* \
44+
&& pip install --no-cache-dir -U -r /tmp/requirements.txt \
45+
&& apt-get clean \
46+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
47+
48+
WORKDIR /app
49+
50+
EXPOSE 5000
51+
CMD ["/app/entrypoint.sh"]

3.6/config/nginx/nginx.conf

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
user ${APP_USER};
2+
worker_processes ${NGINX_WORKER};
3+
4+
error_log /dev/stderr warn;
5+
pid /var/run/nginx.pid;
6+
events {
7+
worker_connections 2048;
8+
use epoll;
9+
multi_accept on;
10+
}
11+
12+
worker_rlimit_nofile 8192;
13+
14+
http {
15+
include /etc/nginx/mime.types;
16+
default_type application/octet-stream;
17+
# recursive real ip
18+
set_real_ip_from 10.0.0.0/8;
19+
set_real_ip_from 172.0.0.0/8;
20+
set_real_ip_from 192.0.0.0/8;
21+
set_real_ip_from 127.0.0.1;
22+
real_ip_header X-Forwarded-For;
23+
real_ip_recursive on;
24+
25+
log_format main '$http_host ' '$remote_addr [$time_local] '
26+
'"$request" $status $body_bytes_sent '
27+
'"$http_referer" "$http_user_agent" "$http_x_forwarded_for" '
28+
'$request_time ' '$upstream_response_time ' 'upstream: $upstream_addr';
29+
30+
log_format json '{"@type": "nginx", '
31+
'"http_host": "$http_host", '
32+
'"remote_addr": "$remote_addr", '
33+
'"time_local": "$time_local", '
34+
'"request": "$request", '
35+
'"status": "$status", '
36+
'"body_bytes_sent": "$body_bytes_sent", '
37+
'"http_referer": "$http_referer", '
38+
'"http_user_agent": "$http_user_agent", '
39+
'"http_x_forwarded_for": "$http_x_forwarded_for", '
40+
'"http_x_request_id": "$http_x_request_id", '
41+
'"request_time": "$request_time", '
42+
'"upstream_response_time": "$upstream_response_time", '
43+
'"upstream_addr": "$upstream_addr" }';
44+
45+
access_log /dev/stdout json;
46+
47+
sendfile on;
48+
tcp_nopush on;
49+
50+
keepalive_timeout 75s;
51+
fastcgi_connect_timeout 75s;
52+
53+
lingering_time 75s;
54+
lingering_timeout 15s;
55+
56+
### Buffer Size
57+
## If buffer sizes are low, Nginx write to a temporary file. cause excessive disk I/O
58+
client_body_buffer_size 128k;
59+
client_max_body_size 2m;
60+
client_header_buffer_size 1k;
61+
large_client_header_buffers 4 4k;
62+
## number and size of the buffers used for reading a response from a disk
63+
output_buffers 1 32k;
64+
postpone_output 1460;
65+
## cache 1000 files for 30 seconds, excluding old files not accessed in 20 secs
66+
open_file_cache max=1000 inactive=10s;
67+
open_file_cache_valid 20s;
68+
open_file_cache_min_uses 5;
69+
open_file_cache_errors off;
70+
71+
gzip on;
72+
gzip_comp_level 1;
73+
gzip_min_length 100;
74+
gzip_types application/json application/javascript text/css;
75+
gzip_vary on;
76+
77+
add_header X-Frame-Options SAMEORIGIN;
78+
add_header X-XSS-Protection "1; mode=block";
79+
add_header Strict-Transport-Security "max-age=2592000; includeSubDomains";
80+
server_tokens off;
81+
82+
include /etc/nginx/conf.d/*.conf;
83+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[unix_http_server]
2+
file=/var/run/supervisor.sock
3+
chmod=0770
4+
chown=root:supervisor
5+
6+
[supervisord]
7+
user=root
8+
nodaemon=true
9+
logfile=/dev/null
10+
logfile_maxbytes=0
11+
pidfile=/var/run/supervisord.pid
12+
childlogdir=/var/log/supervisor
13+
14+
[rpcinterface:supervisor]
15+
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
16+
17+
[supervisorctl]
18+
serverurl=unix:///var/run/supervisor.sock
19+
20+
[program:nginx]
21+
command=/usr/sbin/nginx -g 'daemon off;'
22+
autostart=true
23+
autorestart=true
24+
stdout_events_enabled=true
25+
stderr_events_enabled=true
26+
stdout_logfile=/dev/stdout
27+
stdout_logfile_maxbytes=0
28+
stderr_logfile=/dev/stderr
29+
stderr_logfile_maxbytes=0
30+
31+
[include]
32+
files = /etc/supervisor/conf.d/*.conf

3.6/entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
# Filename: entrypoint.sh
3+
# Description: Docker entrypoint script for Inspectorio Python base image
4+
5+
set -euxo pipefail
6+
7+
# shellcheck disable=SC2016
8+
envsubst '${APP_USER} ${NGINX_WORKER}' < /etc/nginx/nginx.conf | sponge /etc/nginx/nginx.conf
9+
10+
exec /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf

0 commit comments

Comments
 (0)