-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
439 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def application(env, start_response): | ||
start_response('200 OK', [('Content-Type', 'text/html')]) | ||
return [b"Hello World from a default Nginx uWSGI Python 3.6 app in a\ | ||
Docker container (default)"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[uwsgi] | ||
wsgi-file=/app/main.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/bin/sh | ||
# | ||
# Note: base alpine Linux image may not include bash shell, | ||
# and we probably want to move to that for service images, | ||
# so just use bourn shell ... | ||
|
||
# | ||
# Update certificate authority index - | ||
# environment may have mounted more authorities | ||
# - ex: /usr/local/share/ca-certificates/cdis-ca.crt into system bundle | ||
# | ||
|
||
GEN3_DEBUG="${GEN3_DEBUG:-False}" | ||
GEN3_DRYRUN="${GEN3_DRYRUN:-False}" | ||
GEN3_UWSGI_TIMEOUT="${GEN3_UWSGI_TIMEOUT:-45s}" | ||
|
||
run() { | ||
if [ "$GEN3_DRYRUN" = True ]; then | ||
echo "DRY RUN - not running: $@" | ||
else | ||
echo "Running $@" | ||
"$@" | ||
fi | ||
} | ||
|
||
help() { | ||
cat - <<EOM | ||
Gen3 base (generic) launch script | ||
Use: | ||
dockkerrun.bash [--help] [--debug=False] [--uwsgiTimeout=45s] [--dryrun=False] | ||
EOM | ||
} | ||
|
||
|
||
while [ $# -gt 0 ]; do | ||
arg="$1" | ||
shift | ||
key="" | ||
value="" | ||
key="$(echo "$arg" | sed -e 's/^-*//' | sed -e 's/=.*$//')" | ||
value="$(echo "$arg" | sed -e 's/^.*=//')" | ||
|
||
if [ "$value" = "$arg" ]; then # =value not given, so use default | ||
value="" | ||
fi | ||
case "$key" in | ||
debug) | ||
GEN3_DEBUG="${value:-True}" | ||
;; | ||
uwsgiTimeout) | ||
GEN3_UWSGI_TIMEOUT="${value:-45s}" | ||
;; | ||
dryrun) | ||
GEN3_DRYRUN="${value:-True}" | ||
;; | ||
help) | ||
help | ||
exit 0 | ||
;; | ||
*) | ||
echo "ERROR: unknown argument $arg - bailing out" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
cat - <<EOM | ||
Got configuration: | ||
GEN3_DEBUG=$GEN3_DEBUG | ||
GEN3_UWSGI_TIMEOUT=$GEN3_UWSGI_TIMEOUT | ||
GEN3_DRYRUN=$GEN3_DRYRUN | ||
EOM | ||
|
||
run update-ca-certificates | ||
run mkdir -p /var/run/gen3 | ||
|
||
# fill in timeout in the uwsgi.conf template | ||
if [ -f /etc/nginx/sites-available/uwsgi.conf ]; then | ||
sed -i -e "s/GEN3_UWSGI_TIMEOUT/$GEN3_UWSGI_TIMEOUT/g" /etc/nginx/sites-available/uwsgi.conf | ||
fi | ||
|
||
# | ||
# Enable debug flag based on GEN3_DEBUG environment | ||
# | ||
if [ -f ./wsgi.py ] && [ "$GEN3_DEBUG" = "True" ]; then | ||
echo -e "\napplication.debug=True\n" >> ./wsgi.py | ||
fi | ||
|
||
( | ||
# Wait for nginx to create uwsgi.sock in a sub-process | ||
count=0 | ||
while [ ! -e /var/run/gen3/uwsgi.sock ] && [ $count -lt 10 ]; do | ||
echo "... waiting for /var/run/gen3/uwsgi.sock to appear" | ||
sleep 2 | ||
count="$(($count+1))" | ||
done | ||
if [ ! -e /var/run/gen3/uwsgi.sock ]; then | ||
echo "WARNING: /var/run/gen3/uwsgi.sock does not exist!!!" | ||
fi | ||
run uwsgi --ini /etc/uwsgi/uwsgi.ini | ||
) & | ||
run nginx -g 'daemon off;' | ||
wait |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env sh | ||
set -e | ||
|
||
# Get the maximum upload file size for Nginx, default to 0: unlimited | ||
USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0} | ||
# Generate Nginx config for maximum upload file size | ||
echo "client_max_body_size $USE_NGINX_MAX_UPLOAD;" > /etc/nginx/conf.d/upload.conf | ||
|
||
# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH | ||
# Otherwise uWSGI can't import Flask | ||
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.6/site-packages:/usr/lib/python3.6/site-packages | ||
|
||
# Get the number of workers for Nginx, default to 1 | ||
USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1} | ||
# Modify the number of worker processes in Nginx config | ||
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf | ||
|
||
# Set the max number of connections per worker for Nginx, if requested | ||
# Cannot exceed worker_rlimit_nofile, see NGINX_WORKER_OPEN_FILES below | ||
if [ -n "$NGINX_WORKER_CONNECTIONS" ] ; then | ||
sed -i "/worker_connections\s/c\ worker_connections ${NGINX_WORKER_CONNECTIONS};" /etc/nginx/nginx.conf | ||
fi | ||
|
||
# Set the max number of open file descriptors for Nginx workers, if requested | ||
if [ -n "$NGINX_WORKER_OPEN_FILES" ] ; then | ||
echo "worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};" >> /etc/nginx/nginx.conf | ||
fi | ||
|
||
# Get the listen port for Nginx, default to 80 | ||
USE_LISTEN_PORT=${LISTEN_PORT:-80} | ||
# Modify Nignx config for listen port | ||
if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/nginx.conf ; then | ||
sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/nginx.conf | ||
fi | ||
exec "$@" |
Oops, something went wrong.