Skip to content
This repository was archived by the owner on Dec 17, 2023. It is now read-only.

Commit 17f1edf

Browse files
committed
Merge branch 'master' into develop
2 parents 4557e50 + 11f49b3 commit 17f1edf

File tree

22 files changed

+304
-337
lines changed

22 files changed

+304
-337
lines changed

.gitignore

Lines changed: 1 addition & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,2 @@
1-
### Python template
2-
# Byte-compiled / optimized / DLL files
3-
__pycache__/
4-
*.py[cod]
5-
*$py.class
6-
7-
# C extensions
8-
*.so
9-
10-
# Distribution / packaging
11-
.Python
12-
env/
13-
build/
14-
develop-eggs/
15-
dist/
16-
downloads/
17-
eggs/
18-
.eggs/
19-
lib/
20-
lib64/
21-
parts/
22-
sdist/
23-
var/
24-
*.egg-info/
25-
.installed.cfg
26-
*.egg
27-
28-
# PyInstaller
29-
# Usually these files are written by a python script from a template
30-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31-
*.manifest
32-
*.spec
33-
34-
# Installer logs
35-
pip-log.txt
36-
pip-delete-this-directory.txt
37-
38-
# Unit test / coverage reports
39-
htmlcov/
40-
.tox/
41-
.coverage
42-
.coverage.*
43-
.cache
44-
nosetests.xml
45-
coverage.xml
46-
*,cover
47-
48-
# Translations
49-
*.mo
50-
*.pot
51-
52-
# Django stuff:
53-
*.log
54-
55-
# Sphinx documentation
56-
docs/_build/
57-
58-
# PyBuilder
59-
target/
60-
### JetBrains template
61-
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
62-
63-
*.iml
64-
65-
## Directory-based project format:
1+
# repo specific gitignore
662
.idea/
67-
# if you remove the above rule, at least ignore the following:
68-
69-
# User-specific stuff:
70-
# .idea/workspace.xml
71-
# .idea/tasks.xml
72-
# .idea/dictionaries
73-
74-
# Sensitive or high-churn files:
75-
# .idea/dataSources.ids
76-
# .idea/dataSources.xml
77-
# .idea/sqlDataSources.xml
78-
# .idea/dynamic.xml
79-
# .idea/uiDesigner.xml
80-
81-
# Gradle:
82-
# .idea/gradle.xml
83-
# .idea/libraries
84-
85-
# Mongo Explorer plugin:
86-
# .idea/mongoSettings.xml
87-
88-
## File-based project format:
89-
*.ipr
90-
*.iws
91-
92-
## Plugin-specific files:
93-
94-
# IntelliJ
95-
/out/
96-
97-
# mpeltonen/sbt-idea plugin
98-
.idea_modules/
99-
100-
# JIRA plugin
101-
atlassian-ide-plugin.xml
102-
103-
# Crashlytics plugin (for Android Studio and IntelliJ)
104-
com_crashlytics_export_strings.xml
105-
crashlytics.properties
106-
crashlytics-build.properties
107-

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2017 Robert Peteuil
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 84 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,96 @@
1-
*NOTE: These images are a fork or the repository [tiangolo/UWSGI-NGINX-DOCKER](https://github.com/tiangolo/uwsgi-nginx-docker). This fork was necessary because of an urgent need for changes and modifications, which are described below.*
2-
31
# Supported tags and `Dockerfile` links
42

5-
- [`python2.7` _(Dockerfile)_](https://github.com/robertpeteuil/docker-nginx-uwsgi/blob/master/python2.7/Dockerfile)
6-
- [`python2.7-alpine` _(Dockerfile)_](https://github.com/robertpeteuil/docker-nginx-uwsgi/blob/master/python2.7-alpine/Dockerfile)
7-
- [`python3.5` _(Dockerfile)_](https://github.com/robertpeteuil/docker-nginx-uwsgi/blob/master/python3.5/Dockerfile)
8-
- [`python3.5-alpine` _(Dockerfile)_](https://github.com/robertpeteuil/docker-nginx-uwsgi/blob/master/python3.5-alpine/Dockerfile)
9-
- [`python3.6` _(Dockerfile)_](https://github.com/robertpeteuil/docker-nginx-uwsgi/blob/master/python3.6/Dockerfile)
10-
- [`python3.6-alpine` _(Dockerfile)_](https://github.com/robertpeteuil/docker-nginx-uwsgi/blob/master/python3.6-alpine/Dockerfile)
3+
- `py2.7`, `python2.7` [_(python2.7/Dockerfile)_](https://github.com/robertpeteuil/docker-nginx-uwsgi/blob/master/python2.7/Dockerfile)
4+
- `py2.7-alpine`, `python2.7-alpine` [_(python2.7-alpine/Dockerfile)_](https://github.com/robertpeteuil/docker-nginx-uwsgi/blob/master/python2.7-alpine/Dockerfile)
5+
- `py3.5`, `python3.5` [_(python3.5/Dockerfile)_](https://github.com/robertpeteuil/docker-nginx-uwsgi/blob/master/python3.5/Dockerfile)
6+
- `py3.5-alpine`, `python3.5-alpine` [_(python3.5-alpine/Dockerfile)_](https://github.com/robertpeteuil/docker-nginx-uwsgi/blob/master/python3.5-alpine/Dockerfile)
7+
- `py3.6`, `python3.6` [_(python3.6/Dockerfile)_](https://github.com/robertpeteuil/docker-nginx-uwsgi/blob/master/python3.6/Dockerfile)
8+
- `py3.6-alpine`, `python3.6-alpine` [_(python3.6-alpine/Dockerfile)_](https://github.com/robertpeteuil/docker-nginx-uwsgi/blob/master/python3.6-alpine/Dockerfile)
9+
10+
**You must explicitly use one of the tags above.** The `latest` tag is not assigned since each tag represents a different variant, not an incremental version.
11+
12+
## NGINX-UWSGI
13+
14+
**Docker** image with **Nginx**, **uWSGI** and **Python** running in a single container to enable running Python Web Apps on NGINX.
15+
16+
**GitHub Repo**: <https://github.com/robertpeteuil/docker-nginx-uwsgi>
17+
18+
**Docker Hub Images**: <https://hub.docker.com/r/robpco/nginx-uwsgi/>
19+
20+
## Overview
21+
22+
This Docker image allow the creation/migration of Python Web Apps to run on Nginx and uWSGI in a single container. It's designed for use as base image for:
23+
24+
- Other images - such as a pre-built image for running Flask Apps [nginx-uwsgi-flask](https://github.com/robertpeteuil/docker-nginx-uwsgi-flask) .
25+
- A development image that can be customized with your unique web-framework, Python libraries and code.
26+
27+
This repo auto-generates images to [Docker-Hub](https://hub.docker.com/r/robpco/nginx-uwsgi/). It includes standard and alpine-based variants for each supported Python version (2.7, 3.5, 3.6).
28+
29+
## Usage
1130

12-
# Overview
31+
The Docker-Hub [repository](https://hub.docker.com/r/robpco/nginx-uwsgi/) contains auto-generated images from this repo. They can be referenced (or pulled) by using the image name `robpco/nginx-uwsgi`, plus a tag for the python version desired (ex: `:python3.6`), and optionally appending `-alpine` to the tag (for alpine variants).
1332

14-
**Docker** image with **Nginx**, **uWSGI** and **Python** running in a single container that enables easy migration of Python Web Apps to production on NGINX. They are designed as a base image, and do not have web-frameworks pre-installed. To use them, add your web-framework of choice (Flask, Django, etc..) and python application.
33+
## Custom Environment Variables
1534

16-
**For detailed information, examples and documentation visit tiangolo's [repo](https://github.com/tiangolo/uwsgi-nginx-docker).**
35+
This image supports the following custom environment variables:
1736

18-
# Changes
37+
- **UWSGI_INI** - the path and file of the configuration info
38+
- default: `/app/uwsgi.ini`
39+
- **NGINX_MAX_UPLOAD** - the maximum file upload size allowed by Nginx
40+
- 0 = unlimited (image default)
41+
- 1m = normal Nginx default
42+
- **LISTEN_PORT** - custom port that Nginx should listen on
43+
- 80 = Nginx default
1944

20-
These images include the following changes from the original repo:
21-
- The addition of alpine-linux variants that are much smaller in size.
22-
- `supervisord` enhancement to reduce CRIT errors
23-
- `supervisord.conf` is explicitly referenced via the Dockerfile CMD statement
24-
- `supervisord.conf` includes an explicitly set user-name (root) (which can be changed).
25-
- Includes an updated version of Nginx (1.13.7) on non-alpine variants
26-
- Includes updated python revisions for each supported version (2.7, 3.5, and 3.6)
27-
- Adds LISTEN_PORT environment var to allow setting custom ports; via docker run, or docker-compose.
45+
## Setting Environment Variables
2846

29-
# Docker Hub Repository
47+
Environment variables can be set in multiple ways. The following examples, demonstrate setting the `LISTEN_PORT` environment variable via three different methods. These methods apply to the other Environment Variables as well.
3048

31-
The docker-hub [repository](https://hub.docker.com/r/robpco/nginx-uwsgi/) contains pre-built images. The images can be pulled by using the python version as a tag (or python version + "-alpine").
49+
### Setting in a `Dockerfile`
3250

33-
```bash
34-
docker pull robpco/nginx-uwsgi:python3.6-alpine
51+
```dockerfile
52+
# ... (snip) ...
53+
ENV LISTEN_PORT 8080
54+
# ... (snip) ...
3555
```
3656

37-
NOTE: They do NOT not support a `latest` tag, because they are different variants, not incremental versions. Using a `latest` tag with images of this sort can potentially lead to catastrophic results.
57+
### Setting during [`docker run`](https://docs.docker.com/engine/reference/commandline/run/#options) with the `-e` option
58+
59+
```shell
60+
docker run -e LISTEN_PORT=8080 -p 8080:8080 myimage
61+
```
62+
63+
### Setting in `docker-compose` file using the `environment:` keyword in a `docker-compose` file
64+
65+
```yml
66+
version: '2.2'
67+
services:
68+
web:
69+
image: myapp
70+
environment:
71+
LISTEN_PORT: 8080
72+
```
73+
74+
Inspired by the project at [tiangolo/UWSGI-NGINX-DOCKER](https://github.com/tiangolo/uwsgi-nginx-docker).
75+
76+
## UPDATES
77+
78+
- 2017-12-11: Added multiple tags per variant: `py3.6` is the same as `python3.6`, and so forth...
79+
- 2017-11-29: Added ability to change port Nginx listens on with new environment variable `LISTEN_PORT`.
80+
- Thanks to github user [tmshn](https://github.com/tmshn)
81+
- 2017-11-29: Alpine variants added
82+
- Thanks to github user [ProgEsteves](https://github.com/ProgEsteves)
83+
- 2017-11-29: Automatic image re-build when Python updates
84+
- 2017-11-28: Updated Nginx version installed on non-Alpine images
85+
86+
## CHANGELOG
87+
88+
- 2017-12-15: Fix to avoid duplicate listen entries in nginx.conf
89+
- 2017-11-30: Alpine images - eliminated uWSGI random build failures
90+
- 2017-11-30: Non-Alpine images - limit build failures caused by GPG key validation failing
91+
- 2017-11-29: Alpine required additional changes:
92+
- Replace default `/etc/nginx/nginx.conf` with an alternate version
93+
- Create `/run/nginx` directory to stop immediate Nginx crash
94+
- 2017-11-28: Fixed console errors from supervisor process:
95+
- Added explicit path reference to `supervisord.conf` in Dockerfile `CMD` statement
96+
- Added explicitly set username in `supervisord.conf`

python2.7-alpine/Dockerfile

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
FROM python:2.7-alpine
22

3-
RUN apk update \
4-
&& apk add --no-cache gcc \
5-
libc-dev \
6-
linux-headers \
7-
bash \
8-
nginx \
9-
supervisor \
10-
&& pip install uwsgi
11-
12-
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
13-
&& ln -sf /dev/stderr /var/log/nginx/error.log
14-
EXPOSE 80 443
3+
RUN set -x && \
4+
apk add --no-cache \
5+
gcc \
6+
libc-dev \
7+
linux-headers \
8+
bash \
9+
nginx \
10+
supervisor \
11+
# protect against uwsgi compile failing randomly
12+
&& (while true; do pip install --no-cache-dir --disable-pip-version-check uwsgi && break; done)
13+
14+
RUN ln -sf /dev/stdout /var/log/nginx/access.log && \
15+
ln -sf /dev/stderr /var/log/nginx/error.log
1516

1617
# Replace Nginx configuration on alpine
17-
RUN rm /etc/nginx/nginx.conf
1818
COPY nginx.main.conf /etc/nginx/nginx.conf
19-
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
20-
RUN mkdir -p /run/nginx
21-
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
19+
RUN mkdir -p /run/nginx && \
20+
echo "daemon off;" >> /etc/nginx/nginx.conf
2221

22+
# copy config files
23+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
2324
COPY nginx.conf /etc/nginx/conf.d/
2425
COPY uwsgi.ini /etc/uwsgi/
2526

27+
# set ENV variables and expose ports
2628
ENV UWSGI_INI /app/uwsgi.ini
27-
# Enable unlimited filesize uploads by setting to 0
28-
ENV NGINX_MAX_UPLOAD 1m
29-
30-
# Change default Nginx port
29+
# Enable limiting maximum filesize upload (nginx default is 1m)
30+
ENV NGINX_MAX_UPLOAD 0
31+
# Enable changing default listening port on Nginx
3132
ENV LISTEN_PORT 80
33+
EXPOSE 80 443
3234

33-
# entrypoint.sh generates additional Nginx configs
35+
# setup entrypoint.sh which generates Nginx configs at runtime
3436
COPY entrypoint.sh /entrypoint.sh
3537
RUN chmod +x /entrypoint.sh
3638

python2.7-alpine/Dockerfile.old

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

python2.7-alpine/app/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
def application(env, start_response):
22
start_response('200 OK', [('Content-Type', 'text/html')])
3-
return ["Hello World from a default Nginx uWSGI Python 2.7 app in an alpine Docker container (default)"]
3+
return ["Hello World from a default uWSGI Python 2.7 app in an\
4+
Alpine-Linux Docker container with Nginx (default)"]

python2.7-alpine/entrypoint.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0}
55
# Generate Nginx config for maximum upload file size
66
echo "client_max_body_size $USE_NGINX_MAX_UPLOAD;" > /etc/nginx/conf.d/upload.conf
77

8+
# Add installed packages to PYTHONPATH to enable uWSGI imports
9+
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages
10+
811
#Get the listen port for Nginx, default to 80
912
USE_LISTEN_PORT=${LISTEN_PORT:-80}
10-
# Modify Nignx config for listen port
11-
sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf
12-
13+
if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then
14+
sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf
15+
fi
1316
exec "$@"

0 commit comments

Comments
 (0)