From a045f1a3dcb355210c6e0a1e303cdd3d59a951d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 4 May 2020 15:49:50 +0200 Subject: [PATCH 01/10] :heavy_plus_sign: Move from Pipenv to Poetry --- Pipfile | 23 ----------------------- pyproject.toml | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 23 deletions(-) delete mode 100644 Pipfile create mode 100644 pyproject.toml diff --git a/Pipfile b/Pipfile deleted file mode 100644 index b96a25f4..00000000 --- a/Pipfile +++ /dev/null @@ -1,23 +0,0 @@ -[[source]] -name = "pypi" -url = "https://pypi.org/simple" -verify_ssl = true - -[dev-packages] -docker = "*" -pytest = "*" -black = "*" -mypy = "*" -pylint = "*" -jupyter = "*" -flake8 = "*" -autoflake = "*" - -[requires] -python_version = "3.6" - -[pipenv] -allow_prereleases = true - -[packages] -flask = "*" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..b0268915 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[tool.poetry] +name = "uwsgi-nginx-flask-docker" +version = "0.1.0" +description = "Docker image with uWSGI and Nginx for Flask applications in Python 3.6 and above and Python 2.7 running in a single container. Optionally with Alpine Linux." +authors = ["Sebastián Ramírez "] +license = "MIT" + +[tool.poetry.dependencies] +python = "^3.6" +docker = "^4.2.0" +pytest = "^5.4.1" + +[tool.poetry.dev-dependencies] +black = "^19.10b0" +isort = "^4.3.21" +autoflake = "^1.3.1" +mypy = "^0.770" + +[build-system] +requires = ["poetry>=0.12"] +build-backend = "poetry.masonry.api" From 43c3cc2221d11a613aae2dab699893da36d51000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 4 May 2020 15:52:19 +0200 Subject: [PATCH 02/10] :construction_worker: Add GitHub Actions for CI --- .github/workflows/deploy.yml | 48 +++++++++++++++++++ .../workflows/{main.yml => issue-manager.yml} | 2 + .github/workflows/test.yml | 46 ++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 .github/workflows/deploy.yml rename .github/workflows/{main.yml => issue-manager.yml} (96%) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..478f44b7 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,48 @@ +name: Deploy + +on: + push: + branches: + - master + +jobs: + build: + strategy: + matrix: + image: + - name: latest + python_version: "3.7" + - name: python3.7 + python_version: "3.7" + - name: python3.6 + python_version: "3.6" + - name: python3.5 + python_version: "3.5" + - name: python2.7 + python_version: "2.7" + - name: python3.6-alpine3.8 + python_version: "3.6" + - name: python3.6-alpine3.7 + python_version: "3.6" + - name: python2.7-alpine3.8 + python_version: "2.7" + - name: python2.7-alpine3.7 + python_version: "2.7" + fail-fast: true + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: "3.7" + - name: Install Dependencies + run: python3.7 -m pip install docker pytest + - name: Deploy Image + run: bash scripts/build-push.sh + env: + NAME: ${{ matrix.image.name }} + DOCKERFILE: ${{ matrix.image.dockerfile }} + PYTHON_VERSION: ${{ matrix.image.python_version }} + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} diff --git a/.github/workflows/main.yml b/.github/workflows/issue-manager.yml similarity index 96% rename from .github/workflows/main.yml rename to .github/workflows/issue-manager.yml index 0e9450c4..cd5d7a03 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/issue-manager.yml @@ -1,3 +1,5 @@ +name: Issue Manager + on: schedule: - cron: "0 0 * * *" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..28d628ee --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,46 @@ +name: Test + +on: + push: + pull_request: + types: [opened, synchronize] + +jobs: + build: + strategy: + matrix: + image: + - name: latest + python_version: "3.7" + - name: python3.7 + python_version: "3.7" + - name: python3.6 + python_version: "3.6" + - name: python3.5 + python_version: "3.5" + - name: python2.7 + python_version: "2.7" + - name: python3.6-alpine3.8 + python_version: "3.6" + - name: python3.6-alpine3.7 + python_version: "3.6" + - name: python2.7-alpine3.8 + python_version: "2.7" + - name: python2.7-alpine3.7 + python_version: "2.7" + fail-fast: true + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: "3.7" + - name: Install Dependencies + run: python3.7 -m pip install docker pytest + - name: Test Image + run: bash scripts/test.sh + env: + NAME: ${{ matrix.image.name }} + DOCKERFILE: ${{ matrix.image.dockerfile }} + PYTHON_VERSION: ${{ matrix.image.python_version }} From 4fec4b1069ab7bfe96a05e1a0afa1a1a63a7bb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 4 May 2020 15:53:09 +0200 Subject: [PATCH 03/10] :construction_worker: Disable Travis --- .travis.yml => backup.travis.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .travis.yml => backup.travis.yml (100%) diff --git a/.travis.yml b/backup.travis.yml similarity index 100% rename from .travis.yml rename to backup.travis.yml From c2c1b8b088417484c7cbed53c04d0985d38a1fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 4 May 2020 15:54:41 +0200 Subject: [PATCH 04/10] :fire: Centralize and simplify building setup --- {python2.7 => docker-images}/app/main.py | 0 .../app/prestart.sh | 2 +- .../app/uwsgi.ini | 0 .../entrypoint.sh | 11 +++-- .../python2.7-alpine3.7.dockerfile | 0 .../python2.7-alpine3.8.dockerfile | 0 .../python2.7.dockerfile | 0 .../python3.5.dockerfile | 2 +- .../python3.6-alpine3.7.dockerfile | 0 .../python3.6-alpine3.8.dockerfile | 0 .../python3.6.dockerfile | 0 .../python3.7.dockerfile | 0 python2.7-alpine3.7/app/main.py | 18 -------- python2.7-alpine3.7/app/prestart.sh | 12 ------ python2.7-alpine3.7/entrypoint.sh | 43 ------------------- python2.7-alpine3.8/app/main.py | 18 -------- python2.7-alpine3.8/app/prestart.sh | 12 ------ python2.7-alpine3.8/app/uwsgi.ini | 3 -- python2.7-index/Dockerfile | 11 ----- python2.7-index/app/main.py | 23 ---------- python2.7-index/app/static/index.html | 10 ----- python2.7/app/prestart.sh | 12 ------ python2.7/app/uwsgi.ini | 3 -- python2.7/entrypoint.sh | 39 ----------------- python3.5-index/Dockerfile | 11 ----- python3.5-index/app/main.py | 23 ---------- python3.5-index/app/static/index.html | 10 ----- python3.5/app/main.py | 18 -------- python3.5/app/prestart.sh | 12 ------ python3.5/app/uwsgi.ini | 3 -- python3.5/entrypoint.sh | 39 ----------------- python3.6-alpine3.7/app/main.py | 18 -------- python3.6-alpine3.7/app/uwsgi.ini | 3 -- python3.6-alpine3.7/entrypoint.sh | 43 ------------------- python3.6-alpine3.8/app/main.py | 18 -------- python3.6-alpine3.8/app/prestart.sh | 12 ------ python3.6-alpine3.8/app/uwsgi.ini | 3 -- python3.6-alpine3.8/entrypoint.sh | 43 ------------------- python3.6-index/Dockerfile | 11 ----- python3.6-index/app/main.py | 23 ---------- python3.6-index/app/static/index.html | 10 ----- python3.6/app/main.py | 18 -------- python3.6/app/prestart.sh | 12 ------ python3.6/app/uwsgi.ini | 3 -- python3.6/entrypoint.sh | 39 ----------------- python3.7-alpine3.7/Dockerfile | 35 --------------- python3.7-alpine3.7/app/main.py | 18 -------- python3.7-alpine3.7/app/prestart.sh | 12 ------ python3.7-alpine3.7/app/uwsgi.ini | 3 -- python3.7-alpine3.7/entrypoint.sh | 43 ------------------- python3.7-alpine3.8/Dockerfile | 35 --------------- python3.7-alpine3.8/app/main.py | 18 -------- python3.7-alpine3.8/app/prestart.sh | 12 ------ python3.7-alpine3.8/app/uwsgi.ini | 3 -- python3.7-alpine3.8/entrypoint.sh | 43 ------------------- python3.7/app/main.py | 18 -------- python3.7/app/prestart.sh | 12 ------ python3.7/app/uwsgi.ini | 3 -- python3.7/entrypoint.sh | 39 ----------------- 59 files changed, 9 insertions(+), 876 deletions(-) rename {python2.7 => docker-images}/app/main.py (100%) rename {python3.6-alpine3.7 => docker-images}/app/prestart.sh (89%) rename {python2.7-alpine3.7 => docker-images}/app/uwsgi.ini (100%) rename {python2.7-alpine3.8 => docker-images}/entrypoint.sh (91%) rename python2.7-alpine3.7/Dockerfile => docker-images/python2.7-alpine3.7.dockerfile (100%) rename python2.7-alpine3.8/Dockerfile => docker-images/python2.7-alpine3.8.dockerfile (100%) rename python3.5/Dockerfile => docker-images/python2.7.dockerfile (100%) rename python2.7/Dockerfile => docker-images/python3.5.dockerfile (96%) rename python3.6-alpine3.7/Dockerfile => docker-images/python3.6-alpine3.7.dockerfile (100%) rename python3.6-alpine3.8/Dockerfile => docker-images/python3.6-alpine3.8.dockerfile (100%) rename python3.6/Dockerfile => docker-images/python3.6.dockerfile (100%) rename python3.7/Dockerfile => docker-images/python3.7.dockerfile (100%) delete mode 100644 python2.7-alpine3.7/app/main.py delete mode 100644 python2.7-alpine3.7/app/prestart.sh delete mode 100644 python2.7-alpine3.7/entrypoint.sh delete mode 100644 python2.7-alpine3.8/app/main.py delete mode 100644 python2.7-alpine3.8/app/prestart.sh delete mode 100644 python2.7-alpine3.8/app/uwsgi.ini delete mode 100644 python2.7-index/Dockerfile delete mode 100644 python2.7-index/app/main.py delete mode 100644 python2.7-index/app/static/index.html delete mode 100644 python2.7/app/prestart.sh delete mode 100644 python2.7/app/uwsgi.ini delete mode 100644 python2.7/entrypoint.sh delete mode 100644 python3.5-index/Dockerfile delete mode 100644 python3.5-index/app/main.py delete mode 100644 python3.5-index/app/static/index.html delete mode 100644 python3.5/app/main.py delete mode 100644 python3.5/app/prestart.sh delete mode 100644 python3.5/app/uwsgi.ini delete mode 100644 python3.5/entrypoint.sh delete mode 100644 python3.6-alpine3.7/app/main.py delete mode 100644 python3.6-alpine3.7/app/uwsgi.ini delete mode 100644 python3.6-alpine3.7/entrypoint.sh delete mode 100644 python3.6-alpine3.8/app/main.py delete mode 100644 python3.6-alpine3.8/app/prestart.sh delete mode 100644 python3.6-alpine3.8/app/uwsgi.ini delete mode 100644 python3.6-alpine3.8/entrypoint.sh delete mode 100644 python3.6-index/Dockerfile delete mode 100644 python3.6-index/app/main.py delete mode 100644 python3.6-index/app/static/index.html delete mode 100644 python3.6/app/main.py delete mode 100644 python3.6/app/prestart.sh delete mode 100644 python3.6/app/uwsgi.ini delete mode 100644 python3.6/entrypoint.sh delete mode 100644 python3.7-alpine3.7/Dockerfile delete mode 100644 python3.7-alpine3.7/app/main.py delete mode 100644 python3.7-alpine3.7/app/prestart.sh delete mode 100644 python3.7-alpine3.7/app/uwsgi.ini delete mode 100644 python3.7-alpine3.7/entrypoint.sh delete mode 100644 python3.7-alpine3.8/Dockerfile delete mode 100644 python3.7-alpine3.8/app/main.py delete mode 100644 python3.7-alpine3.8/app/prestart.sh delete mode 100644 python3.7-alpine3.8/app/uwsgi.ini delete mode 100644 python3.7-alpine3.8/entrypoint.sh delete mode 100644 python3.7/app/main.py delete mode 100644 python3.7/app/prestart.sh delete mode 100644 python3.7/app/uwsgi.ini delete mode 100644 python3.7/entrypoint.sh diff --git a/python2.7/app/main.py b/docker-images/app/main.py similarity index 100% rename from python2.7/app/main.py rename to docker-images/app/main.py diff --git a/python3.6-alpine3.7/app/prestart.sh b/docker-images/app/prestart.sh similarity index 89% rename from python3.6-alpine3.7/app/prestart.sh rename to docker-images/app/prestart.sh index 9ccb1dab..472d2e44 100644 --- a/python3.6-alpine3.7/app/prestart.sh +++ b/docker-images/app/prestart.sh @@ -3,7 +3,7 @@ echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" echo " -#! /usr/bin/env bash +#! /usr/bin/env sh # Let the DB start sleep 10; diff --git a/python2.7-alpine3.7/app/uwsgi.ini b/docker-images/app/uwsgi.ini similarity index 100% rename from python2.7-alpine3.7/app/uwsgi.ini rename to docker-images/app/uwsgi.ini diff --git a/python2.7-alpine3.8/entrypoint.sh b/docker-images/entrypoint.sh similarity index 91% rename from python2.7-alpine3.8/entrypoint.sh rename to docker-images/entrypoint.sh index 20867bdd..3dddb4b1 100644 --- a/python2.7-alpine3.8/entrypoint.sh +++ b/docker-images/entrypoint.sh @@ -3,10 +3,6 @@ set -e /uwsgi-nginx-entrypoint.sh -# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH -# Otherwise uWSGI can't import Flask -export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages - # Get the URL for static files from the environment variable USE_STATIC_URL=${STATIC_URL:-'/static'} # Get the absolute path of the static files from the environment variable @@ -40,4 +36,11 @@ else printf "$content_server" > /etc/nginx/conf.d/nginx.conf fi +# For Alpine: +# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH +# Otherwise uWSGI can't import Flask +if [ -n "$ALPINEPYTHON" ] ; then + export PYTHONPATH=$PYTHONPATH:/usr/local/lib/$ALPINEPYTHON/site-packages:/usr/lib/$ALPINEPYTHON/site-packages +fi + exec "$@" diff --git a/python2.7-alpine3.7/Dockerfile b/docker-images/python2.7-alpine3.7.dockerfile similarity index 100% rename from python2.7-alpine3.7/Dockerfile rename to docker-images/python2.7-alpine3.7.dockerfile diff --git a/python2.7-alpine3.8/Dockerfile b/docker-images/python2.7-alpine3.8.dockerfile similarity index 100% rename from python2.7-alpine3.8/Dockerfile rename to docker-images/python2.7-alpine3.8.dockerfile diff --git a/python3.5/Dockerfile b/docker-images/python2.7.dockerfile similarity index 100% rename from python3.5/Dockerfile rename to docker-images/python2.7.dockerfile diff --git a/python2.7/Dockerfile b/docker-images/python3.5.dockerfile similarity index 96% rename from python2.7/Dockerfile rename to docker-images/python3.5.dockerfile index 1f3f53d2..4d7e3b6c 100644 --- a/python2.7/Dockerfile +++ b/docker-images/python3.5.dockerfile @@ -1,4 +1,4 @@ -FROM tiangolo/uwsgi-nginx:python2.7 +FROM tiangolo/uwsgi-nginx:python3.5 LABEL maintainer="Sebastian Ramirez " diff --git a/python3.6-alpine3.7/Dockerfile b/docker-images/python3.6-alpine3.7.dockerfile similarity index 100% rename from python3.6-alpine3.7/Dockerfile rename to docker-images/python3.6-alpine3.7.dockerfile diff --git a/python3.6-alpine3.8/Dockerfile b/docker-images/python3.6-alpine3.8.dockerfile similarity index 100% rename from python3.6-alpine3.8/Dockerfile rename to docker-images/python3.6-alpine3.8.dockerfile diff --git a/python3.6/Dockerfile b/docker-images/python3.6.dockerfile similarity index 100% rename from python3.6/Dockerfile rename to docker-images/python3.6.dockerfile diff --git a/python3.7/Dockerfile b/docker-images/python3.7.dockerfile similarity index 100% rename from python3.7/Dockerfile rename to docker-images/python3.7.dockerfile diff --git a/python2.7-alpine3.7/app/main.py b/python2.7-alpine3.7/app/main.py deleted file mode 100644 index 027a3a87..00000000 --- a/python2.7-alpine3.7/app/main.py +++ /dev/null @@ -1,18 +0,0 @@ -import sys - -from flask import Flask - -app = Flask(__name__) - - -@app.route("/") -def hello(): - version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) - message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} on Alpine (default)".format( - version - ) - return message - - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True, port=80) diff --git a/python2.7-alpine3.7/app/prestart.sh b/python2.7-alpine3.7/app/prestart.sh deleted file mode 100644 index 9ccb1dab..00000000 --- a/python2.7-alpine3.7/app/prestart.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env sh - -echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" - -echo " -#! /usr/bin/env bash - -# Let the DB start -sleep 10; -# Run migrations -alembic upgrade head -" diff --git a/python2.7-alpine3.7/entrypoint.sh b/python2.7-alpine3.7/entrypoint.sh deleted file mode 100644 index 20867bdd..00000000 --- a/python2.7-alpine3.7/entrypoint.sh +++ /dev/null @@ -1,43 +0,0 @@ -#! /usr/bin/env sh -set -e - -/uwsgi-nginx-entrypoint.sh - -# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH -# Otherwise uWSGI can't import Flask -export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages - -# Get the URL for static files from the environment variable -USE_STATIC_URL=${STATIC_URL:-'/static'} -# Get the absolute path of the static files from the environment variable -USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} -# Get the listen port for Nginx, default to 80 -USE_LISTEN_PORT=${LISTEN_PORT:-80} - -if [ -f /app/nginx.conf ]; then - cp /app/nginx.conf /etc/nginx/nginx.conf -else - content_server='server {\n' - content_server=$content_server" listen ${USE_LISTEN_PORT};\n" - content_server=$content_server' location / {\n' - content_server=$content_server' try_files $uri @app;\n' - content_server=$content_server' }\n' - content_server=$content_server' location @app {\n' - content_server=$content_server' include uwsgi_params;\n' - content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' - content_server=$content_server' }\n' - content_server=$content_server" location $USE_STATIC_URL {\n" - content_server=$content_server" alias $USE_STATIC_PATH;\n" - content_server=$content_server' }\n' - # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) - if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" - content_server=$content_server' }\n' - fi - content_server=$content_server'}\n' - # Save generated server /etc/nginx/conf.d/nginx.conf - printf "$content_server" > /etc/nginx/conf.d/nginx.conf -fi - -exec "$@" diff --git a/python2.7-alpine3.8/app/main.py b/python2.7-alpine3.8/app/main.py deleted file mode 100644 index 027a3a87..00000000 --- a/python2.7-alpine3.8/app/main.py +++ /dev/null @@ -1,18 +0,0 @@ -import sys - -from flask import Flask - -app = Flask(__name__) - - -@app.route("/") -def hello(): - version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) - message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} on Alpine (default)".format( - version - ) - return message - - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True, port=80) diff --git a/python2.7-alpine3.8/app/prestart.sh b/python2.7-alpine3.8/app/prestart.sh deleted file mode 100644 index 9ccb1dab..00000000 --- a/python2.7-alpine3.8/app/prestart.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env sh - -echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" - -echo " -#! /usr/bin/env bash - -# Let the DB start -sleep 10; -# Run migrations -alembic upgrade head -" diff --git a/python2.7-alpine3.8/app/uwsgi.ini b/python2.7-alpine3.8/app/uwsgi.ini deleted file mode 100644 index 327bbb23..00000000 --- a/python2.7-alpine3.8/app/uwsgi.ini +++ /dev/null @@ -1,3 +0,0 @@ -[uwsgi] -module = main -callable = app diff --git a/python2.7-index/Dockerfile b/python2.7-index/Dockerfile deleted file mode 100644 index 16e84a5e..00000000 --- a/python2.7-index/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python2.7 - -LABEL maintainer="Sebastian Ramirez " - -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -ENV STATIC_INDEX 1 -# ENV STATIC_INDEX 0 - -# Add demo app -COPY ./app /app -WORKDIR /app diff --git a/python2.7-index/app/main.py b/python2.7-index/app/main.py deleted file mode 100644 index b42440e6..00000000 --- a/python2.7-index/app/main.py +++ /dev/null @@ -1,23 +0,0 @@ -import sys - -from flask import Flask, send_file - -app = Flask(__name__) - - -@app.route("/api") -def hello(): - version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) - message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} (default)".format( - version - ) - return message - - -@app.route("/") -def main(): - return send_file("./static/index.html") - - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True, port=80) diff --git a/python2.7-index/app/static/index.html b/python2.7-index/app/static/index.html deleted file mode 100644 index ea056771..00000000 --- a/python2.7-index/app/static/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Index - - -

Hello World from HTML (default)

- - \ No newline at end of file diff --git a/python2.7/app/prestart.sh b/python2.7/app/prestart.sh deleted file mode 100644 index 94631dd4..00000000 --- a/python2.7/app/prestart.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env bash - -echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" - -echo " -#! /usr/bin/env bash - -# Let the DB start -sleep 10; -# Run migrations -alembic upgrade head -" diff --git a/python2.7/app/uwsgi.ini b/python2.7/app/uwsgi.ini deleted file mode 100644 index 1abe35ae..00000000 --- a/python2.7/app/uwsgi.ini +++ /dev/null @@ -1,3 +0,0 @@ -[uwsgi] -module = main -callable = app diff --git a/python2.7/entrypoint.sh b/python2.7/entrypoint.sh deleted file mode 100644 index 0f458269..00000000 --- a/python2.7/entrypoint.sh +++ /dev/null @@ -1,39 +0,0 @@ -#! /usr/bin/env bash -set -e - -/uwsgi-nginx-entrypoint.sh - -# Get the URL for static files from the environment variable -USE_STATIC_URL=${STATIC_URL:-'/static'} -# Get the absolute path of the static files from the environment variable -USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} -# Get the listen port for Nginx, default to 80 -USE_LISTEN_PORT=${LISTEN_PORT:-80} - -if [ -f /app/nginx.conf ]; then - cp /app/nginx.conf /etc/nginx/nginx.conf -else - content_server='server {\n' - content_server=$content_server" listen ${USE_LISTEN_PORT};\n" - content_server=$content_server' location / {\n' - content_server=$content_server' try_files $uri @app;\n' - content_server=$content_server' }\n' - content_server=$content_server' location @app {\n' - content_server=$content_server' include uwsgi_params;\n' - content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' - content_server=$content_server' }\n' - content_server=$content_server" location $USE_STATIC_URL {\n" - content_server=$content_server" alias $USE_STATIC_PATH;\n" - content_server=$content_server' }\n' - # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) - if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" - content_server=$content_server' }\n' - fi - content_server=$content_server'}\n' - # Save generated server /etc/nginx/conf.d/nginx.conf - printf "$content_server" > /etc/nginx/conf.d/nginx.conf -fi - -exec "$@" diff --git a/python3.5-index/Dockerfile b/python3.5-index/Dockerfile deleted file mode 100644 index fd0aa1dd..00000000 --- a/python3.5-index/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.5 - -LABEL maintainer="Sebastian Ramirez " - -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -ENV STATIC_INDEX 1 -# ENV STATIC_INDEX 0 - -# Add demo app -COPY ./app /app -WORKDIR /app diff --git a/python3.5-index/app/main.py b/python3.5-index/app/main.py deleted file mode 100644 index b42440e6..00000000 --- a/python3.5-index/app/main.py +++ /dev/null @@ -1,23 +0,0 @@ -import sys - -from flask import Flask, send_file - -app = Flask(__name__) - - -@app.route("/api") -def hello(): - version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) - message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} (default)".format( - version - ) - return message - - -@app.route("/") -def main(): - return send_file("./static/index.html") - - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True, port=80) diff --git a/python3.5-index/app/static/index.html b/python3.5-index/app/static/index.html deleted file mode 100644 index ea056771..00000000 --- a/python3.5-index/app/static/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Index - - -

Hello World from HTML (default)

- - \ No newline at end of file diff --git a/python3.5/app/main.py b/python3.5/app/main.py deleted file mode 100644 index 4ba40eac..00000000 --- a/python3.5/app/main.py +++ /dev/null @@ -1,18 +0,0 @@ -import sys - -from flask import Flask - -app = Flask(__name__) - - -@app.route("/") -def hello(): - version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) - message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} (default)".format( - version - ) - return message - - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True, port=80) diff --git a/python3.5/app/prestart.sh b/python3.5/app/prestart.sh deleted file mode 100644 index 94631dd4..00000000 --- a/python3.5/app/prestart.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env bash - -echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" - -echo " -#! /usr/bin/env bash - -# Let the DB start -sleep 10; -# Run migrations -alembic upgrade head -" diff --git a/python3.5/app/uwsgi.ini b/python3.5/app/uwsgi.ini deleted file mode 100644 index 1abe35ae..00000000 --- a/python3.5/app/uwsgi.ini +++ /dev/null @@ -1,3 +0,0 @@ -[uwsgi] -module = main -callable = app diff --git a/python3.5/entrypoint.sh b/python3.5/entrypoint.sh deleted file mode 100644 index 3d0372b5..00000000 --- a/python3.5/entrypoint.sh +++ /dev/null @@ -1,39 +0,0 @@ -#! /usr/bin/env sh -set -e - -/uwsgi-nginx-entrypoint.sh - -# Get the URL for static files from the environment variable -USE_STATIC_URL=${STATIC_URL:-'/static'} -# Get the absolute path of the static files from the environment variable -USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} -# Get the listen port for Nginx, default to 80 -USE_LISTEN_PORT=${LISTEN_PORT:-80} - -if [ -f /app/nginx.conf ]; then - cp /app/nginx.conf /etc/nginx/nginx.conf -else - content_server='server {\n' - content_server=$content_server" listen ${USE_LISTEN_PORT};\n" - content_server=$content_server' location / {\n' - content_server=$content_server' try_files $uri @app;\n' - content_server=$content_server' }\n' - content_server=$content_server' location @app {\n' - content_server=$content_server' include uwsgi_params;\n' - content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' - content_server=$content_server' }\n' - content_server=$content_server" location $USE_STATIC_URL {\n" - content_server=$content_server" alias $USE_STATIC_PATH;\n" - content_server=$content_server' }\n' - # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) - if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" - content_server=$content_server' }\n' - fi - content_server=$content_server'}\n' - # Save generated server /etc/nginx/conf.d/nginx.conf - printf "$content_server" > /etc/nginx/conf.d/nginx.conf -fi - -exec "$@" diff --git a/python3.6-alpine3.7/app/main.py b/python3.6-alpine3.7/app/main.py deleted file mode 100644 index 027a3a87..00000000 --- a/python3.6-alpine3.7/app/main.py +++ /dev/null @@ -1,18 +0,0 @@ -import sys - -from flask import Flask - -app = Flask(__name__) - - -@app.route("/") -def hello(): - version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) - message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} on Alpine (default)".format( - version - ) - return message - - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True, port=80) diff --git a/python3.6-alpine3.7/app/uwsgi.ini b/python3.6-alpine3.7/app/uwsgi.ini deleted file mode 100644 index 327bbb23..00000000 --- a/python3.6-alpine3.7/app/uwsgi.ini +++ /dev/null @@ -1,3 +0,0 @@ -[uwsgi] -module = main -callable = app diff --git a/python3.6-alpine3.7/entrypoint.sh b/python3.6-alpine3.7/entrypoint.sh deleted file mode 100644 index e933646a..00000000 --- a/python3.6-alpine3.7/entrypoint.sh +++ /dev/null @@ -1,43 +0,0 @@ -#! /usr/bin/env sh -set -e - -/uwsgi-nginx-entrypoint.sh - -# 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 URL for static files from the environment variable -USE_STATIC_URL=${STATIC_URL:-'/static'} -# Get the absolute path of the static files from the environment variable -USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} -# Get the listen port for Nginx, default to 80 -USE_LISTEN_PORT=${LISTEN_PORT:-80} - -if [ -f /app/nginx.conf ]; then - cp /app/nginx.conf /etc/nginx/nginx.conf -else - content_server='server {\n' - content_server=$content_server" listen ${USE_LISTEN_PORT};\n" - content_server=$content_server' location / {\n' - content_server=$content_server' try_files $uri @app;\n' - content_server=$content_server' }\n' - content_server=$content_server' location @app {\n' - content_server=$content_server' include uwsgi_params;\n' - content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' - content_server=$content_server' }\n' - content_server=$content_server" location $USE_STATIC_URL {\n" - content_server=$content_server" alias $USE_STATIC_PATH;\n" - content_server=$content_server' }\n' - # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) - if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" - content_server=$content_server' }\n' - fi - content_server=$content_server'}\n' - # Save generated server /etc/nginx/conf.d/nginx.conf - printf "$content_server" > /etc/nginx/conf.d/nginx.conf -fi - -exec "$@" diff --git a/python3.6-alpine3.8/app/main.py b/python3.6-alpine3.8/app/main.py deleted file mode 100644 index 027a3a87..00000000 --- a/python3.6-alpine3.8/app/main.py +++ /dev/null @@ -1,18 +0,0 @@ -import sys - -from flask import Flask - -app = Flask(__name__) - - -@app.route("/") -def hello(): - version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) - message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} on Alpine (default)".format( - version - ) - return message - - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True, port=80) diff --git a/python3.6-alpine3.8/app/prestart.sh b/python3.6-alpine3.8/app/prestart.sh deleted file mode 100644 index 9ccb1dab..00000000 --- a/python3.6-alpine3.8/app/prestart.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env sh - -echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" - -echo " -#! /usr/bin/env bash - -# Let the DB start -sleep 10; -# Run migrations -alembic upgrade head -" diff --git a/python3.6-alpine3.8/app/uwsgi.ini b/python3.6-alpine3.8/app/uwsgi.ini deleted file mode 100644 index 327bbb23..00000000 --- a/python3.6-alpine3.8/app/uwsgi.ini +++ /dev/null @@ -1,3 +0,0 @@ -[uwsgi] -module = main -callable = app diff --git a/python3.6-alpine3.8/entrypoint.sh b/python3.6-alpine3.8/entrypoint.sh deleted file mode 100644 index e933646a..00000000 --- a/python3.6-alpine3.8/entrypoint.sh +++ /dev/null @@ -1,43 +0,0 @@ -#! /usr/bin/env sh -set -e - -/uwsgi-nginx-entrypoint.sh - -# 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 URL for static files from the environment variable -USE_STATIC_URL=${STATIC_URL:-'/static'} -# Get the absolute path of the static files from the environment variable -USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} -# Get the listen port for Nginx, default to 80 -USE_LISTEN_PORT=${LISTEN_PORT:-80} - -if [ -f /app/nginx.conf ]; then - cp /app/nginx.conf /etc/nginx/nginx.conf -else - content_server='server {\n' - content_server=$content_server" listen ${USE_LISTEN_PORT};\n" - content_server=$content_server' location / {\n' - content_server=$content_server' try_files $uri @app;\n' - content_server=$content_server' }\n' - content_server=$content_server' location @app {\n' - content_server=$content_server' include uwsgi_params;\n' - content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' - content_server=$content_server' }\n' - content_server=$content_server" location $USE_STATIC_URL {\n" - content_server=$content_server" alias $USE_STATIC_PATH;\n" - content_server=$content_server' }\n' - # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) - if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" - content_server=$content_server' }\n' - fi - content_server=$content_server'}\n' - # Save generated server /etc/nginx/conf.d/nginx.conf - printf "$content_server" > /etc/nginx/conf.d/nginx.conf -fi - -exec "$@" diff --git a/python3.6-index/Dockerfile b/python3.6-index/Dockerfile deleted file mode 100644 index ba38e788..00000000 --- a/python3.6-index/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6 - -LABEL maintainer="Sebastian Ramirez " - -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -ENV STATIC_INDEX 1 -# ENV STATIC_INDEX 0 - -# Add demo app -COPY ./app /app -WORKDIR /app \ No newline at end of file diff --git a/python3.6-index/app/main.py b/python3.6-index/app/main.py deleted file mode 100644 index b42440e6..00000000 --- a/python3.6-index/app/main.py +++ /dev/null @@ -1,23 +0,0 @@ -import sys - -from flask import Flask, send_file - -app = Flask(__name__) - - -@app.route("/api") -def hello(): - version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) - message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} (default)".format( - version - ) - return message - - -@app.route("/") -def main(): - return send_file("./static/index.html") - - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True, port=80) diff --git a/python3.6-index/app/static/index.html b/python3.6-index/app/static/index.html deleted file mode 100644 index ea056771..00000000 --- a/python3.6-index/app/static/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Index - - -

Hello World from HTML (default)

- - \ No newline at end of file diff --git a/python3.6/app/main.py b/python3.6/app/main.py deleted file mode 100644 index 4ba40eac..00000000 --- a/python3.6/app/main.py +++ /dev/null @@ -1,18 +0,0 @@ -import sys - -from flask import Flask - -app = Flask(__name__) - - -@app.route("/") -def hello(): - version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) - message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} (default)".format( - version - ) - return message - - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True, port=80) diff --git a/python3.6/app/prestart.sh b/python3.6/app/prestart.sh deleted file mode 100644 index 94631dd4..00000000 --- a/python3.6/app/prestart.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env bash - -echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" - -echo " -#! /usr/bin/env bash - -# Let the DB start -sleep 10; -# Run migrations -alembic upgrade head -" diff --git a/python3.6/app/uwsgi.ini b/python3.6/app/uwsgi.ini deleted file mode 100644 index 1abe35ae..00000000 --- a/python3.6/app/uwsgi.ini +++ /dev/null @@ -1,3 +0,0 @@ -[uwsgi] -module = main -callable = app diff --git a/python3.6/entrypoint.sh b/python3.6/entrypoint.sh deleted file mode 100644 index 0f458269..00000000 --- a/python3.6/entrypoint.sh +++ /dev/null @@ -1,39 +0,0 @@ -#! /usr/bin/env bash -set -e - -/uwsgi-nginx-entrypoint.sh - -# Get the URL for static files from the environment variable -USE_STATIC_URL=${STATIC_URL:-'/static'} -# Get the absolute path of the static files from the environment variable -USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} -# Get the listen port for Nginx, default to 80 -USE_LISTEN_PORT=${LISTEN_PORT:-80} - -if [ -f /app/nginx.conf ]; then - cp /app/nginx.conf /etc/nginx/nginx.conf -else - content_server='server {\n' - content_server=$content_server" listen ${USE_LISTEN_PORT};\n" - content_server=$content_server' location / {\n' - content_server=$content_server' try_files $uri @app;\n' - content_server=$content_server' }\n' - content_server=$content_server' location @app {\n' - content_server=$content_server' include uwsgi_params;\n' - content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' - content_server=$content_server' }\n' - content_server=$content_server" location $USE_STATIC_URL {\n" - content_server=$content_server" alias $USE_STATIC_PATH;\n" - content_server=$content_server' }\n' - # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) - if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" - content_server=$content_server' }\n' - fi - content_server=$content_server'}\n' - # Save generated server /etc/nginx/conf.d/nginx.conf - printf "$content_server" > /etc/nginx/conf.d/nginx.conf -fi - -exec "$@" diff --git a/python3.7-alpine3.7/Dockerfile b/python3.7-alpine3.7/Dockerfile deleted file mode 100644 index c734f455..00000000 --- a/python3.7-alpine3.7/Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ -FROM tiangolo/uwsgi-nginx:python3.7-alpine3.7 - -LABEL maintainer="Sebastian Ramirez " - -RUN pip install flask - -# URL under which static (not modified by Python) files will be requested -# They will be served by Nginx directly, without being handled by uWSGI -ENV STATIC_URL /static -# Absolute path in where the static files wil be -ENV STATIC_PATH /app/static - -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -# ENV STATIC_INDEX 1 -ENV STATIC_INDEX 0 - -# Add demo app -COPY ./app /app -WORKDIR /app - -# Make /app/* available to be imported by Python globally to better support several use cases like Alembic migrations. -ENV PYTHONPATH=/app - -# Move the base entrypoint to reuse it -RUN mv /entrypoint.sh /uwsgi-nginx-entrypoint.sh -# Copy the entrypoint that will generate Nginx additional configs -COPY entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] - -# Run the start script provided by the parent image tiangolo/uwsgi-nginx. -# It will check for an /app/prestart.sh script (e.g. for migrations) -# And then will start Supervisor, which in turn will start Nginx and uWSGI -CMD ["/start.sh"] diff --git a/python3.7-alpine3.7/app/main.py b/python3.7-alpine3.7/app/main.py deleted file mode 100644 index 027a3a87..00000000 --- a/python3.7-alpine3.7/app/main.py +++ /dev/null @@ -1,18 +0,0 @@ -import sys - -from flask import Flask - -app = Flask(__name__) - - -@app.route("/") -def hello(): - version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) - message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} on Alpine (default)".format( - version - ) - return message - - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True, port=80) diff --git a/python3.7-alpine3.7/app/prestart.sh b/python3.7-alpine3.7/app/prestart.sh deleted file mode 100644 index 9ccb1dab..00000000 --- a/python3.7-alpine3.7/app/prestart.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env sh - -echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" - -echo " -#! /usr/bin/env bash - -# Let the DB start -sleep 10; -# Run migrations -alembic upgrade head -" diff --git a/python3.7-alpine3.7/app/uwsgi.ini b/python3.7-alpine3.7/app/uwsgi.ini deleted file mode 100644 index 327bbb23..00000000 --- a/python3.7-alpine3.7/app/uwsgi.ini +++ /dev/null @@ -1,3 +0,0 @@ -[uwsgi] -module = main -callable = app diff --git a/python3.7-alpine3.7/entrypoint.sh b/python3.7-alpine3.7/entrypoint.sh deleted file mode 100644 index 7ff34758..00000000 --- a/python3.7-alpine3.7/entrypoint.sh +++ /dev/null @@ -1,43 +0,0 @@ -#! /usr/bin/env sh -set -e - -/uwsgi-nginx-entrypoint.sh - -# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH -# Otherwise uWSGI can't import Flask -export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages:/usr/lib/python3.7/site-packages - -# Get the URL for static files from the environment variable -USE_STATIC_URL=${STATIC_URL:-'/static'} -# Get the absolute path of the static files from the environment variable -USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} -# Get the listen port for Nginx, default to 80 -USE_LISTEN_PORT=${LISTEN_PORT:-80} - -if [ -f /app/nginx.conf ]; then - cp /app/nginx.conf /etc/nginx/nginx.conf -else - content_server='server {\n' - content_server=$content_server" listen ${USE_LISTEN_PORT};\n" - content_server=$content_server' location / {\n' - content_server=$content_server' try_files $uri @app;\n' - content_server=$content_server' }\n' - content_server=$content_server' location @app {\n' - content_server=$content_server' include uwsgi_params;\n' - content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' - content_server=$content_server' }\n' - content_server=$content_server" location $USE_STATIC_URL {\n" - content_server=$content_server" alias $USE_STATIC_PATH;\n" - content_server=$content_server' }\n' - # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) - if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" - content_server=$content_server' }\n' - fi - content_server=$content_server'}\n' - # Save generated server /etc/nginx/conf.d/nginx.conf - printf "$content_server" > /etc/nginx/conf.d/nginx.conf -fi - -exec "$@" diff --git a/python3.7-alpine3.8/Dockerfile b/python3.7-alpine3.8/Dockerfile deleted file mode 100644 index 509d8306..00000000 --- a/python3.7-alpine3.8/Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ -FROM tiangolo/uwsgi-nginx:python3.7-alpine3.8 - -LABEL maintainer="Sebastian Ramirez " - -RUN pip install flask - -# URL under which static (not modified by Python) files will be requested -# They will be served by Nginx directly, without being handled by uWSGI -ENV STATIC_URL /static -# Absolute path in where the static files wil be -ENV STATIC_PATH /app/static - -# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) -# ENV STATIC_INDEX 1 -ENV STATIC_INDEX 0 - -# Add demo app -COPY ./app /app -WORKDIR /app - -# Make /app/* available to be imported by Python globally to better support several use cases like Alembic migrations. -ENV PYTHONPATH=/app - -# Move the base entrypoint to reuse it -RUN mv /entrypoint.sh /uwsgi-nginx-entrypoint.sh -# Copy the entrypoint that will generate Nginx additional configs -COPY entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] - -# Run the start script provided by the parent image tiangolo/uwsgi-nginx. -# It will check for an /app/prestart.sh script (e.g. for migrations) -# And then will start Supervisor, which in turn will start Nginx and uWSGI -CMD ["/start.sh"] diff --git a/python3.7-alpine3.8/app/main.py b/python3.7-alpine3.8/app/main.py deleted file mode 100644 index 027a3a87..00000000 --- a/python3.7-alpine3.8/app/main.py +++ /dev/null @@ -1,18 +0,0 @@ -import sys - -from flask import Flask - -app = Flask(__name__) - - -@app.route("/") -def hello(): - version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) - message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} on Alpine (default)".format( - version - ) - return message - - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True, port=80) diff --git a/python3.7-alpine3.8/app/prestart.sh b/python3.7-alpine3.8/app/prestart.sh deleted file mode 100644 index 9ccb1dab..00000000 --- a/python3.7-alpine3.8/app/prestart.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env sh - -echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" - -echo " -#! /usr/bin/env bash - -# Let the DB start -sleep 10; -# Run migrations -alembic upgrade head -" diff --git a/python3.7-alpine3.8/app/uwsgi.ini b/python3.7-alpine3.8/app/uwsgi.ini deleted file mode 100644 index 327bbb23..00000000 --- a/python3.7-alpine3.8/app/uwsgi.ini +++ /dev/null @@ -1,3 +0,0 @@ -[uwsgi] -module = main -callable = app diff --git a/python3.7-alpine3.8/entrypoint.sh b/python3.7-alpine3.8/entrypoint.sh deleted file mode 100644 index 7ff34758..00000000 --- a/python3.7-alpine3.8/entrypoint.sh +++ /dev/null @@ -1,43 +0,0 @@ -#! /usr/bin/env sh -set -e - -/uwsgi-nginx-entrypoint.sh - -# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH -# Otherwise uWSGI can't import Flask -export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages:/usr/lib/python3.7/site-packages - -# Get the URL for static files from the environment variable -USE_STATIC_URL=${STATIC_URL:-'/static'} -# Get the absolute path of the static files from the environment variable -USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} -# Get the listen port for Nginx, default to 80 -USE_LISTEN_PORT=${LISTEN_PORT:-80} - -if [ -f /app/nginx.conf ]; then - cp /app/nginx.conf /etc/nginx/nginx.conf -else - content_server='server {\n' - content_server=$content_server" listen ${USE_LISTEN_PORT};\n" - content_server=$content_server' location / {\n' - content_server=$content_server' try_files $uri @app;\n' - content_server=$content_server' }\n' - content_server=$content_server' location @app {\n' - content_server=$content_server' include uwsgi_params;\n' - content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' - content_server=$content_server' }\n' - content_server=$content_server" location $USE_STATIC_URL {\n" - content_server=$content_server" alias $USE_STATIC_PATH;\n" - content_server=$content_server' }\n' - # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) - if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" - content_server=$content_server' }\n' - fi - content_server=$content_server'}\n' - # Save generated server /etc/nginx/conf.d/nginx.conf - printf "$content_server" > /etc/nginx/conf.d/nginx.conf -fi - -exec "$@" diff --git a/python3.7/app/main.py b/python3.7/app/main.py deleted file mode 100644 index 4ba40eac..00000000 --- a/python3.7/app/main.py +++ /dev/null @@ -1,18 +0,0 @@ -import sys - -from flask import Flask - -app = Flask(__name__) - - -@app.route("/") -def hello(): - version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) - message = "Hello World from Flask in a uWSGI Nginx Docker container with Python {} (default)".format( - version - ) - return message - - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True, port=80) diff --git a/python3.7/app/prestart.sh b/python3.7/app/prestart.sh deleted file mode 100644 index 94631dd4..00000000 --- a/python3.7/app/prestart.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env bash - -echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" - -echo " -#! /usr/bin/env bash - -# Let the DB start -sleep 10; -# Run migrations -alembic upgrade head -" diff --git a/python3.7/app/uwsgi.ini b/python3.7/app/uwsgi.ini deleted file mode 100644 index 327bbb23..00000000 --- a/python3.7/app/uwsgi.ini +++ /dev/null @@ -1,3 +0,0 @@ -[uwsgi] -module = main -callable = app diff --git a/python3.7/entrypoint.sh b/python3.7/entrypoint.sh deleted file mode 100644 index 0f458269..00000000 --- a/python3.7/entrypoint.sh +++ /dev/null @@ -1,39 +0,0 @@ -#! /usr/bin/env bash -set -e - -/uwsgi-nginx-entrypoint.sh - -# Get the URL for static files from the environment variable -USE_STATIC_URL=${STATIC_URL:-'/static'} -# Get the absolute path of the static files from the environment variable -USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} -# Get the listen port for Nginx, default to 80 -USE_LISTEN_PORT=${LISTEN_PORT:-80} - -if [ -f /app/nginx.conf ]; then - cp /app/nginx.conf /etc/nginx/nginx.conf -else - content_server='server {\n' - content_server=$content_server" listen ${USE_LISTEN_PORT};\n" - content_server=$content_server' location / {\n' - content_server=$content_server' try_files $uri @app;\n' - content_server=$content_server' }\n' - content_server=$content_server' location @app {\n' - content_server=$content_server' include uwsgi_params;\n' - content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' - content_server=$content_server' }\n' - content_server=$content_server" location $USE_STATIC_URL {\n" - content_server=$content_server" alias $USE_STATIC_PATH;\n" - content_server=$content_server' }\n' - # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) - if [ "$STATIC_INDEX" = 1 ] ; then - content_server=$content_server' location = / {\n' - content_server=$content_server" index $USE_STATIC_URL/index.html;\n" - content_server=$content_server' }\n' - fi - content_server=$content_server'}\n' - # Save generated server /etc/nginx/conf.d/nginx.conf - printf "$content_server" > /etc/nginx/conf.d/nginx.conf -fi - -exec "$@" From ff3f67a7bd9f20be830969c6cce2d6a3c788046b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 4 May 2020 15:55:54 +0200 Subject: [PATCH 05/10] :wrench: Update scripts and testing setup --- scripts/build-push-all.sh | 2 +- scripts/build-push.sh | 4 +- scripts/build.sh | 12 +++++ scripts/docker-login.sh | 5 ++ scripts/format-imports.sh | 6 +++ scripts/format.sh | 7 +++ scripts/lint.sh | 7 +-- scripts/process_all.py | 105 ++++---------------------------------- scripts/test.sh | 4 +- 9 files changed, 48 insertions(+), 104 deletions(-) create mode 100644 scripts/build.sh create mode 100644 scripts/docker-login.sh create mode 100644 scripts/format-imports.sh create mode 100644 scripts/format.sh diff --git a/scripts/build-push-all.sh b/scripts/build-push-all.sh index e54d3f10..a18cab71 100644 --- a/scripts/build-push-all.sh +++ b/scripts/build-push-all.sh @@ -2,6 +2,6 @@ set -e -echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin +bash scripts/docker-login.sh BUILD_PUSH=1 python scripts/process_all.py diff --git a/scripts/build-push.sh b/scripts/build-push.sh index 72aed823..03e27a33 100644 --- a/scripts/build-push.sh +++ b/scripts/build-push.sh @@ -5,9 +5,11 @@ set -e use_tag="tiangolo/uwsgi-nginx-flask:$NAME" use_dated_tag="${use_tag}-$(date -I)" -docker build -t "$use_tag" "$BUILD_PATH" +bash scripts/build.sh docker tag "$use_tag" "$use_dated_tag" +bash scripts/docker-login.sh + docker push "$use_tag" docker push "$use_dated_tag" diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100644 index 00000000..06368593 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -e + +use_tag="tiangolo/uwsgi-nginx-flask:$NAME" + +DOCKERFILE="$NAME" + +if [ "$NAME" == "latest" ] ; then + DOCKERFILE="python3.7" +fi + +docker build -t "$use_tag" --file "./docker-images/${DOCKERFILE}.dockerfile" "./docker-images/" diff --git a/scripts/docker-login.sh b/scripts/docker-login.sh new file mode 100644 index 00000000..d872c893 --- /dev/null +++ b/scripts/docker-login.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin diff --git a/scripts/format-imports.sh b/scripts/format-imports.sh new file mode 100644 index 00000000..8710c79d --- /dev/null +++ b/scripts/format-imports.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -x + +# Sort imports one per line, so autoflake can remove unused imports +isort --recursive --force-single-line-imports --apply ./ +sh ./scripts/format.sh diff --git a/scripts/format.sh b/scripts/format.sh new file mode 100644 index 00000000..a38f39aa --- /dev/null +++ b/scripts/format.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -x + +autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ./ --exclude=__init__.py +isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --apply ./ +black ./ diff --git a/scripts/lint.sh b/scripts/lint.sh index a38f39aa..8198da08 100644 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash +set -e set -x -autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ./ --exclude=__init__.py -isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --apply ./ -black ./ +mypy ./ +black ./ --check +isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --check-only diff --git a/scripts/process_all.py b/scripts/process_all.py index 8a90f924..08567962 100644 --- a/scripts/process_all.py +++ b/scripts/process_all.py @@ -3,102 +3,15 @@ import sys environments = [ - { - "NAME": "python2.7", - "BUILD_PATH": "python2.7", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 (default)", - "TEST_STR2": "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", - "RUN_TESTS": "1", - }, - { - "NAME": "python2.7-alpine3.7", - "BUILD_PATH": "python2.7-alpine3.7", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 on Alpine (default)", - "TEST_STR2": "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", - "RUN_TESTS": "1", - }, - { - "NAME": "python2.7-alpine3.8", - "BUILD_PATH": "python2.7-alpine3.8", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 on Alpine (default)", - "TEST_STR2": "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", - "RUN_TESTS": "1", - }, - { - "NAME": "python3.5", - "BUILD_PATH": "python3.5", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.5 (default)", - "TEST_STR2": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.5 - testing", - "RUN_TESTS": "1", - }, - { - "NAME": "python3.6", - "BUILD_PATH": "python3.6", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 (default)", - "TEST_STR2": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", - "RUN_TESTS": "1", - }, - { - "NAME": "python3.6-alpine3.7", - "BUILD_PATH": "python3.6-alpine3.7", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 on Alpine (default)", - "TEST_STR2": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", - "RUN_TESTS": "1", - }, - { - "NAME": "python3.6-alpine3.8", - "BUILD_PATH": "python3.6-alpine3.8", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 on Alpine (default)", - "TEST_STR2": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", - "RUN_TESTS": "1", - }, - { - "NAME": "python3.7", - "BUILD_PATH": "python3.7", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 (default)", - "TEST_STR2": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - "RUN_TESTS": "1", - }, - { - "NAME": "latest", - "BUILD_PATH": "python3.7", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 (default)", - "TEST_STR2": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - "RUN_TESTS": "1", - }, - { - "NAME": "python3.7-alpine3.7", - "BUILD_PATH": "python3.7-alpine3.7", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 on Alpine (default)", - "TEST_STR2": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - "RUN_TESTS": "", - }, - { - "NAME": "python3.7-alpine3.8", - "BUILD_PATH": "python3.7-alpine3.8", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 on Alpine (default)", - "TEST_STR2": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - "RUN_TESTS": "", - }, - # Index versions - { - "NAME": "python2.7-index", - "BUILD_PATH": "python2.7-index", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 (default)", - "RUN_TESTS": "1", - }, - { - "NAME": "python3.5-index", - "BUILD_PATH": "python3.5-index", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.5 (default)", - "RUN_TESTS": "1", - }, - { - "NAME": "python3.6-index", - "BUILD_PATH": "python3.6-index", - "TEST_STR1": "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 (default)", - "RUN_TESTS": "1", - }, + {"NAME": "latest", "PYTHON_VERSION": "3.7"}, + {"NAME": "python3.7", "PYTHON_VERSION": "3.7"}, + {"NAME": "python3.6", "PYTHON_VERSION": "3.6"}, + {"NAME": "python3.5", "PYTHON_VERSION": "3.5"}, + {"NAME": "python2.7", "PYTHON_VERSION": "2.7"}, + {"NAME": "python3.6-alpine3.8", "PYTHON_VERSION": "3.6"}, + {"NAME": "python3.6-alpine3.7", "PYTHON_VERSION": "3.6"}, + {"NAME": "python2.7-alpine3.8", "PYTHON_VERSION": "2.7"}, + {"NAME": "python2.7-alpine3.7", "PYTHON_VERSION": "2.7"}, ] start_with = os.environ.get("START_WITH") diff --git a/scripts/test.sh b/scripts/test.sh index 73f823fa..693467a2 100644 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash set -e -use_tag="tiangolo/uwsgi-nginx-flask:$NAME" - -docker build -t "$use_tag" "$BUILD_PATH" +bash scripts/build.sh pytest tests From 36fd2dd2b39ae800ac0c0030fd430ce3bd821aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 4 May 2020 16:03:28 +0200 Subject: [PATCH 06/10] :white_check_mark: Update tests with new setup --- tests/.gitignore | 1 + tests/test_01_main/test_defaults_01.py | 20 ++-- tests/test_01_main/test_defaults_02_index.py | 106 ------------------ tests/test_01_main/test_env_vars_03.py | 17 ++- .../test_02_app/custom_app/latest.dockerfile | 7 -- .../custom_app/python2.7-alpine3.7.dockerfile | 7 -- .../custom_app/python2.7-alpine3.8.dockerfile | 7 -- .../custom_app/python2.7.dockerfile | 7 -- .../custom_app/python3.5.dockerfile | 7 -- .../custom_app/python3.6-alpine3.7.dockerfile | 7 -- .../custom_app/python3.6-alpine3.8.dockerfile | 7 -- .../custom_app/python3.6.dockerfile | 7 -- .../custom_app/python3.7-alpine3.7.dockerfile | 7 -- .../custom_app/python3.7-alpine3.8.dockerfile | 7 -- .../custom_app/python3.7.dockerfile | 7 -- .../custom_nginx_app/latest.dockerfile | 3 - .../python2.7-alpine3.7.dockerfile | 3 - .../python2.7-alpine3.8.dockerfile | 3 - .../custom_nginx_app/python2.7.dockerfile | 3 - .../custom_nginx_app/python3.5.dockerfile | 3 - .../python3.6-alpine3.7.dockerfile | 3 - .../python3.6-alpine3.8.dockerfile | 3 - .../custom_nginx_app/python3.6.dockerfile | 3 - .../python3.7-alpine3.7.dockerfile | 3 - .../python3.7-alpine3.8.dockerfile | 3 - .../custom_nginx_app/python3.7.dockerfile | 3 - .../test_02_app/simple_app/latest.dockerfile | 4 - .../simple_app/python2.7-alpine3.7.dockerfile | 4 - .../simple_app/python2.7-alpine3.8.dockerfile | 4 - .../simple_app/python2.7.dockerfile | 4 - .../simple_app/python3.5.dockerfile | 4 - .../simple_app/python3.6-alpine3.7.dockerfile | 4 - .../simple_app/python3.6-alpine3.8.dockerfile | 4 - .../simple_app/python3.6.dockerfile | 4 - .../simple_app/python3.7-alpine3.7.dockerfile | 4 - .../simple_app/python3.7-alpine3.8.dockerfile | 4 - .../simple_app/python3.7.dockerfile | 4 - tests/test_02_app/test_app_and_env_vars.py | 42 +++---- tests/test_02_app/test_custom_ngnix_app.py | 36 +++--- tests/test_02_app/test_simple_app.py | 36 +++--- tests/utils.py | 42 ++++++- 41 files changed, 109 insertions(+), 345 deletions(-) create mode 100644 tests/.gitignore delete mode 100644 tests/test_01_main/test_defaults_02_index.py delete mode 100644 tests/test_02_app/custom_app/latest.dockerfile delete mode 100644 tests/test_02_app/custom_app/python2.7-alpine3.7.dockerfile delete mode 100644 tests/test_02_app/custom_app/python2.7-alpine3.8.dockerfile delete mode 100644 tests/test_02_app/custom_app/python2.7.dockerfile delete mode 100644 tests/test_02_app/custom_app/python3.5.dockerfile delete mode 100644 tests/test_02_app/custom_app/python3.6-alpine3.7.dockerfile delete mode 100644 tests/test_02_app/custom_app/python3.6-alpine3.8.dockerfile delete mode 100644 tests/test_02_app/custom_app/python3.6.dockerfile delete mode 100644 tests/test_02_app/custom_app/python3.7-alpine3.7.dockerfile delete mode 100644 tests/test_02_app/custom_app/python3.7-alpine3.8.dockerfile delete mode 100644 tests/test_02_app/custom_app/python3.7.dockerfile delete mode 100644 tests/test_02_app/custom_nginx_app/latest.dockerfile delete mode 100644 tests/test_02_app/custom_nginx_app/python2.7-alpine3.7.dockerfile delete mode 100644 tests/test_02_app/custom_nginx_app/python2.7-alpine3.8.dockerfile delete mode 100644 tests/test_02_app/custom_nginx_app/python2.7.dockerfile delete mode 100644 tests/test_02_app/custom_nginx_app/python3.5.dockerfile delete mode 100644 tests/test_02_app/custom_nginx_app/python3.6-alpine3.7.dockerfile delete mode 100644 tests/test_02_app/custom_nginx_app/python3.6-alpine3.8.dockerfile delete mode 100644 tests/test_02_app/custom_nginx_app/python3.6.dockerfile delete mode 100644 tests/test_02_app/custom_nginx_app/python3.7-alpine3.7.dockerfile delete mode 100644 tests/test_02_app/custom_nginx_app/python3.7-alpine3.8.dockerfile delete mode 100644 tests/test_02_app/custom_nginx_app/python3.7.dockerfile delete mode 100644 tests/test_02_app/simple_app/latest.dockerfile delete mode 100644 tests/test_02_app/simple_app/python2.7-alpine3.7.dockerfile delete mode 100644 tests/test_02_app/simple_app/python2.7-alpine3.8.dockerfile delete mode 100644 tests/test_02_app/simple_app/python2.7.dockerfile delete mode 100644 tests/test_02_app/simple_app/python3.5.dockerfile delete mode 100644 tests/test_02_app/simple_app/python3.6-alpine3.7.dockerfile delete mode 100644 tests/test_02_app/simple_app/python3.6-alpine3.8.dockerfile delete mode 100644 tests/test_02_app/simple_app/python3.6.dockerfile delete mode 100644 tests/test_02_app/simple_app/python3.7-alpine3.7.dockerfile delete mode 100644 tests/test_02_app/simple_app/python3.7-alpine3.8.dockerfile delete mode 100644 tests/test_02_app/simple_app/python3.7.dockerfile diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 00000000..94143827 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +Dockerfile diff --git a/tests/test_01_main/test_defaults_01.py b/tests/test_01_main/test_defaults_01.py index a1ea1476..2e0c3ad6 100644 --- a/tests/test_01_main/test_defaults_01.py +++ b/tests/test_01_main/test_defaults_01.py @@ -2,20 +2,23 @@ import time import docker -import pytest import requests +from docker.models.containers import Container from ..utils import ( CONTAINER_NAME, get_logs, get_nginx_config, + get_response_text1, remove_previous_container, ) client = docker.from_env() -def verify_container(container, response_text): +def verify_container(container: Container, response_text: str) -> None: + response = requests.get("http://127.0.0.1:8000") + assert response.text == response_text nginx_config = get_nginx_config(container) assert "client_max_body_size 0;" in nginx_config assert "worker_processes 1;" in nginx_config @@ -61,20 +64,13 @@ def verify_container(container, response_text): assert 'running "unix_signal:15 gracefully_kill_them_all" (master-start)' in logs assert "success: nginx entered RUNNING state, process has stayed up for" in logs assert "success: uwsgi entered RUNNING state, process has stayed up for" in logs - response = requests.get("http://127.0.0.1:8000") - assert response.status_code == 200 - assert response.text == response_text -def test_defaults(): - if not os.getenv("RUN_TESTS"): - return - name = os.getenv("NAME") +def test_defaults() -> None: + name = os.getenv("NAME", "") # It's an index postfix tag, skip it - if "index" in name: - return image = f"tiangolo/uwsgi-nginx-flask:{name}" - response_text = os.getenv("TEST_STR1") + response_text = get_response_text1() sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) container = client.containers.run( diff --git a/tests/test_01_main/test_defaults_02_index.py b/tests/test_01_main/test_defaults_02_index.py deleted file mode 100644 index 8e073b0d..00000000 --- a/tests/test_01_main/test_defaults_02_index.py +++ /dev/null @@ -1,106 +0,0 @@ -import os -import time - -import docker -import pytest -import requests -from requests import Response - -from ..utils import ( - CONTAINER_NAME, - get_logs, - get_nginx_config, - remove_previous_container, -) - -client = docker.from_env() - -html_content = """ - - - - Index - - -

Hello World from HTML (default)

- -""" - - -def verify_container(container, response_text): - nginx_config = get_nginx_config(container) - assert "client_max_body_size 0;" in nginx_config - assert "worker_processes 1;" in nginx_config - assert "listen 80;" in nginx_config - assert "worker_connections 1024;" in nginx_config - assert "worker_rlimit_nofile;" not in nginx_config - assert "daemon off;" in nginx_config - assert "include uwsgi_params;" in nginx_config - assert "uwsgi_pass unix:///tmp/uwsgi.sock;" in nginx_config - assert "try_files $uri @app;" in nginx_config - assert "location @app {" in nginx_config - assert "include uwsgi_params;" in nginx_config - assert "location /static {" in nginx_config - assert "alias /app/static;" in nginx_config - # Nginx index.thml specific - assert "location = / {" in nginx_config - assert "index /static/index.html;" in nginx_config - logs = get_logs(container) - assert "getting INI configuration from /app/uwsgi.ini" in logs - assert "getting INI configuration from /etc/uwsgi/uwsgi.ini" in logs - assert "ini = /app/uwsgi.ini" in logs - assert "ini = /etc/uwsgi/uwsgi.ini" in logs - assert "socket = /tmp/uwsgi.sock" in logs - assert "chown-socket = nginx:nginx" in logs - assert "chmod-socket = 664" in logs - assert "hook-master-start = unix_signal:15 gracefully_kill_them_all" in logs - assert "need-app = true" in logs - assert "die-on-term = true" in logs - assert "show-config = true" in logs - assert "module = main" in logs - assert "callable = app" in logs - assert "processes = 16" in logs - assert "cheaper = 2" in logs - assert "Checking for script in /app/prestart.sh" in logs - assert "Running script /app/prestart.sh" in logs - assert ( - "Running inside /app/prestart.sh, you could add migrations to this file" in logs - ) - assert "spawned uWSGI master process" in logs - assert "spawned uWSGI worker 1" in logs - assert "spawned uWSGI worker 2" in logs - assert "spawned uWSGI worker 3" not in logs - assert 'running "unix_signal:15 gracefully_kill_them_all" (master-start)' in logs - assert "success: nginx entered RUNNING state, process has stayed up for" in logs - assert "success: uwsgi entered RUNNING state, process has stayed up for" in logs - response: Response = requests.get("http://127.0.0.1:8000") - assert response.status_code == 200 - assert response.text == html_content - response: Response = requests.get("http://127.0.0.1:8000/api") - assert response.status_code == 200 - assert response.text == response_text - - -def test_defaults(): - if not os.getenv("RUN_TESTS"): - return - name = os.getenv("NAME") - # It's not an index postfix tag, skip it - if "index" not in name: - return - image = f"tiangolo/uwsgi-nginx-flask:{name}" - response_text = os.getenv("TEST_STR1") - sleep_time = int(os.getenv("SLEEP_TIME", 3)) - remove_previous_container(client) - container = client.containers.run( - image, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True - ) - time.sleep(sleep_time) - verify_container(container, response_text) - container.stop() - # Test that everything works after restarting too - container.start() - time.sleep(sleep_time) - verify_container(container, response_text) - container.stop() - container.remove() diff --git a/tests/test_01_main/test_env_vars_03.py b/tests/test_01_main/test_env_vars_03.py index b6ae9ab8..ce9df978 100644 --- a/tests/test_01_main/test_env_vars_03.py +++ b/tests/test_01_main/test_env_vars_03.py @@ -2,21 +2,22 @@ import time import docker -import pytest import requests +from docker.models.containers import Container from requests import Response from ..utils import ( CONTAINER_NAME, get_logs, get_nginx_config, + get_response_text1, remove_previous_container, ) client = docker.from_env() -def verify_container(container, response_text): +def verify_container(container: Container, response_text: str) -> None: nginx_config = get_nginx_config(container) assert "client_max_body_size 1m;" in nginx_config assert "worker_processes 2;" in nginx_config @@ -69,15 +70,11 @@ def verify_container(container, response_text): assert response.text == response_text -def test_defaults(): - if not os.getenv("RUN_TESTS"): - return - name = os.getenv("NAME") - # It's an index postfix tag, skip it - if "index" in name: - return +def test_defaults() -> None: + + name = os.getenv("NAME", "") image = f"tiangolo/uwsgi-nginx-flask:{name}" - response_text = os.getenv("TEST_STR1") + response_text = get_response_text1() sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) container = client.containers.run( diff --git a/tests/test_02_app/custom_app/latest.dockerfile b/tests/test_02_app/custom_app/latest.dockerfile deleted file mode 100644 index 36753413..00000000 --- a/tests/test_02_app/custom_app/latest.dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:latest - -COPY ./application /application -COPY ./prestart.sh /app/prestart.sh -WORKDIR /application - -EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python2.7-alpine3.7.dockerfile b/tests/test_02_app/custom_app/python2.7-alpine3.7.dockerfile deleted file mode 100644 index a8923118..00000000 --- a/tests/test_02_app/custom_app/python2.7-alpine3.7.dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python2.7-alpine3.7 - -COPY ./application /application -COPY ./prestart.sh /app/prestart.sh -WORKDIR /application - -EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python2.7-alpine3.8.dockerfile b/tests/test_02_app/custom_app/python2.7-alpine3.8.dockerfile deleted file mode 100644 index 1f2b137e..00000000 --- a/tests/test_02_app/custom_app/python2.7-alpine3.8.dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python2.7-alpine3.8 - -COPY ./application /application -COPY ./prestart.sh /app/prestart.sh -WORKDIR /application - -EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python2.7.dockerfile b/tests/test_02_app/custom_app/python2.7.dockerfile deleted file mode 100644 index f5032c5f..00000000 --- a/tests/test_02_app/custom_app/python2.7.dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python2.7 - -COPY ./application /application -COPY ./prestart.sh /app/prestart.sh -WORKDIR /application - -EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.5.dockerfile b/tests/test_02_app/custom_app/python3.5.dockerfile deleted file mode 100644 index 1df8e8b5..00000000 --- a/tests/test_02_app/custom_app/python3.5.dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.5 - -COPY ./application /application -COPY ./prestart.sh /app/prestart.sh -WORKDIR /application - -EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.6-alpine3.7.dockerfile b/tests/test_02_app/custom_app/python3.6-alpine3.7.dockerfile deleted file mode 100644 index 2aed80d5..00000000 --- a/tests/test_02_app/custom_app/python3.6-alpine3.7.dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7 - -COPY ./application /application -COPY ./prestart.sh /app/prestart.sh -WORKDIR /application - -EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.6-alpine3.8.dockerfile b/tests/test_02_app/custom_app/python3.6-alpine3.8.dockerfile deleted file mode 100644 index 125b0362..00000000 --- a/tests/test_02_app/custom_app/python3.6-alpine3.8.dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.8 - -COPY ./application /application -COPY ./prestart.sh /app/prestart.sh -WORKDIR /application - -EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.6.dockerfile b/tests/test_02_app/custom_app/python3.6.dockerfile deleted file mode 100644 index 0c400552..00000000 --- a/tests/test_02_app/custom_app/python3.6.dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6 - -COPY ./application /application -COPY ./prestart.sh /app/prestart.sh -WORKDIR /application - -EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.7-alpine3.7.dockerfile b/tests/test_02_app/custom_app/python3.7-alpine3.7.dockerfile deleted file mode 100644 index a8fb9560..00000000 --- a/tests/test_02_app/custom_app/python3.7-alpine3.7.dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7 - -COPY ./application /application -COPY ./prestart.sh /app/prestart.sh -WORKDIR /application - -EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.7-alpine3.8.dockerfile b/tests/test_02_app/custom_app/python3.7-alpine3.8.dockerfile deleted file mode 100644 index a52107ad..00000000 --- a/tests/test_02_app/custom_app/python3.7-alpine3.8.dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.8 - -COPY ./application /application -COPY ./prestart.sh /app/prestart.sh -WORKDIR /application - -EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.7.dockerfile b/tests/test_02_app/custom_app/python3.7.dockerfile deleted file mode 100644 index e5d383d3..00000000 --- a/tests/test_02_app/custom_app/python3.7.dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.7 - -COPY ./application /application -COPY ./prestart.sh /app/prestart.sh -WORKDIR /application - -EXPOSE 8080 diff --git a/tests/test_02_app/custom_nginx_app/latest.dockerfile b/tests/test_02_app/custom_nginx_app/latest.dockerfile deleted file mode 100644 index dd651277..00000000 --- a/tests/test_02_app/custom_nginx_app/latest.dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:latest - -COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python2.7-alpine3.7.dockerfile b/tests/test_02_app/custom_nginx_app/python2.7-alpine3.7.dockerfile deleted file mode 100644 index 1bf89a03..00000000 --- a/tests/test_02_app/custom_nginx_app/python2.7-alpine3.7.dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python2.7-alpine3.7 - -COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python2.7-alpine3.8.dockerfile b/tests/test_02_app/custom_nginx_app/python2.7-alpine3.8.dockerfile deleted file mode 100644 index 1732878d..00000000 --- a/tests/test_02_app/custom_nginx_app/python2.7-alpine3.8.dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python2.7-alpine3.8 - -COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python2.7.dockerfile b/tests/test_02_app/custom_nginx_app/python2.7.dockerfile deleted file mode 100644 index b97f19ed..00000000 --- a/tests/test_02_app/custom_nginx_app/python2.7.dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python2.7 - -COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.5.dockerfile b/tests/test_02_app/custom_nginx_app/python3.5.dockerfile deleted file mode 100644 index 82319782..00000000 --- a/tests/test_02_app/custom_nginx_app/python3.5.dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.5 - -COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.6-alpine3.7.dockerfile b/tests/test_02_app/custom_nginx_app/python3.6-alpine3.7.dockerfile deleted file mode 100644 index 4829cdfe..00000000 --- a/tests/test_02_app/custom_nginx_app/python3.6-alpine3.7.dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7 - -COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.6-alpine3.8.dockerfile b/tests/test_02_app/custom_nginx_app/python3.6-alpine3.8.dockerfile deleted file mode 100644 index 2d1e8717..00000000 --- a/tests/test_02_app/custom_nginx_app/python3.6-alpine3.8.dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.8 - -COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.6.dockerfile b/tests/test_02_app/custom_nginx_app/python3.6.dockerfile deleted file mode 100644 index 02c9bcfc..00000000 --- a/tests/test_02_app/custom_nginx_app/python3.6.dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6 - -COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.7-alpine3.7.dockerfile b/tests/test_02_app/custom_nginx_app/python3.7-alpine3.7.dockerfile deleted file mode 100644 index 5826e772..00000000 --- a/tests/test_02_app/custom_nginx_app/python3.7-alpine3.7.dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7 - -COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.7-alpine3.8.dockerfile b/tests/test_02_app/custom_nginx_app/python3.7-alpine3.8.dockerfile deleted file mode 100644 index bb212de1..00000000 --- a/tests/test_02_app/custom_nginx_app/python3.7-alpine3.8.dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.8 - -COPY app /app diff --git a/tests/test_02_app/custom_nginx_app/python3.7.dockerfile b/tests/test_02_app/custom_nginx_app/python3.7.dockerfile deleted file mode 100644 index 1099189e..00000000 --- a/tests/test_02_app/custom_nginx_app/python3.7.dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.7 - -COPY app /app diff --git a/tests/test_02_app/simple_app/latest.dockerfile b/tests/test_02_app/simple_app/latest.dockerfile deleted file mode 100644 index 15100562..00000000 --- a/tests/test_02_app/simple_app/latest.dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:latest - -COPY ./app/main.py /app/main.py -COPY ./app/static /app/static \ No newline at end of file diff --git a/tests/test_02_app/simple_app/python2.7-alpine3.7.dockerfile b/tests/test_02_app/simple_app/python2.7-alpine3.7.dockerfile deleted file mode 100644 index 561c7573..00000000 --- a/tests/test_02_app/simple_app/python2.7-alpine3.7.dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python2.7-alpine3.7 - -COPY ./app/main.py /app/main.py -COPY ./app/static /app/static diff --git a/tests/test_02_app/simple_app/python2.7-alpine3.8.dockerfile b/tests/test_02_app/simple_app/python2.7-alpine3.8.dockerfile deleted file mode 100644 index 718b73d8..00000000 --- a/tests/test_02_app/simple_app/python2.7-alpine3.8.dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python2.7-alpine3.8 - -COPY ./app/main.py /app/main.py -COPY ./app/static /app/static diff --git a/tests/test_02_app/simple_app/python2.7.dockerfile b/tests/test_02_app/simple_app/python2.7.dockerfile deleted file mode 100644 index 1b329a92..00000000 --- a/tests/test_02_app/simple_app/python2.7.dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python2.7 - -COPY ./app/main.py /app/main.py -COPY ./app/static /app/static diff --git a/tests/test_02_app/simple_app/python3.5.dockerfile b/tests/test_02_app/simple_app/python3.5.dockerfile deleted file mode 100644 index a6ccbe00..00000000 --- a/tests/test_02_app/simple_app/python3.5.dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.5 - -COPY ./app/main.py /app/main.py -COPY ./app/static /app/static diff --git a/tests/test_02_app/simple_app/python3.6-alpine3.7.dockerfile b/tests/test_02_app/simple_app/python3.6-alpine3.7.dockerfile deleted file mode 100644 index ec1deae0..00000000 --- a/tests/test_02_app/simple_app/python3.6-alpine3.7.dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7 - -COPY ./app/main.py /app/main.py -COPY ./app/static /app/static diff --git a/tests/test_02_app/simple_app/python3.6-alpine3.8.dockerfile b/tests/test_02_app/simple_app/python3.6-alpine3.8.dockerfile deleted file mode 100644 index e28b9a3e..00000000 --- a/tests/test_02_app/simple_app/python3.6-alpine3.8.dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.8 - -COPY ./app/main.py /app/main.py -COPY ./app/static /app/static diff --git a/tests/test_02_app/simple_app/python3.6.dockerfile b/tests/test_02_app/simple_app/python3.6.dockerfile deleted file mode 100644 index 0aab2b15..00000000 --- a/tests/test_02_app/simple_app/python3.6.dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6 - -COPY ./app/main.py /app/main.py -COPY ./app/static /app/static diff --git a/tests/test_02_app/simple_app/python3.7-alpine3.7.dockerfile b/tests/test_02_app/simple_app/python3.7-alpine3.7.dockerfile deleted file mode 100644 index 61c8e88c..00000000 --- a/tests/test_02_app/simple_app/python3.7-alpine3.7.dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7 - -COPY ./app/main.py /app/main.py -COPY ./app/static /app/static diff --git a/tests/test_02_app/simple_app/python3.7-alpine3.8.dockerfile b/tests/test_02_app/simple_app/python3.7-alpine3.8.dockerfile deleted file mode 100644 index c00d8d40..00000000 --- a/tests/test_02_app/simple_app/python3.7-alpine3.8.dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.8 - -COPY ./app/main.py /app/main.py -COPY ./app/static /app/static diff --git a/tests/test_02_app/simple_app/python3.7.dockerfile b/tests/test_02_app/simple_app/python3.7.dockerfile deleted file mode 100644 index c526c153..00000000 --- a/tests/test_02_app/simple_app/python3.7.dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.7 - -COPY ./app/main.py /app/main.py -COPY ./app/static /app/static diff --git a/tests/test_02_app/test_app_and_env_vars.py b/tests/test_02_app/test_app_and_env_vars.py index c99d4f2d..1f9a122b 100644 --- a/tests/test_02_app/test_app_and_env_vars.py +++ b/tests/test_02_app/test_app_and_env_vars.py @@ -1,22 +1,32 @@ import os import time -from pathlib import Path, PurePath +from pathlib import Path import docker -import pytest import requests +from docker.models.containers import Container from ..utils import ( CONTAINER_NAME, + generate_dockerfile_content_custom_app, get_logs, get_nginx_config, + get_response_text2, remove_previous_container, ) client = docker.from_env() -def verify_container(container, response_text): +def verify_container(container: Container, response_text: str) -> None: + response = requests.get("http://127.0.0.1:8000") + assert ( + response.text == "

Hello World from HTML test

" + ) + response = requests.get("http://127.0.0.1:8000/api") + assert response.text == response_text + response = requests.get("http://127.0.0.1:8000/content/test.txt") + assert response.text == "Static test" nginx_config = get_nginx_config(container) assert "client_max_body_size 0;" in nginx_config assert "worker_processes 1;" in nginx_config @@ -57,33 +67,23 @@ def verify_container(container, response_text): assert 'running "unix_signal:15 gracefully_kill_them_all" (master-start)' in logs assert "success: nginx entered RUNNING state, process has stayed up for" in logs assert "success: uwsgi entered RUNNING state, process has stayed up for" in logs - response = requests.get("http://127.0.0.1:8000") - assert response.status_code == 200 - assert ( - response.text == "

Hello World from HTML test

" - ) - response = requests.get("http://127.0.0.1:8000/api") - assert response.status_code == 200 - assert response.text == response_text - response = requests.get("http://127.0.0.1:8000/content/test.txt") - assert response.status_code == 200 - assert response.text == "Static test" -def test_env_vars_1(): - if not os.getenv("RUN_TESTS"): - return - name = os.getenv("NAME") +def test_env_vars_1() -> None: + name = os.getenv("NAME", "") # It's an index postfix tag, skip it if "index" in name: return - dockerfile = f"{name}.dockerfile" - response_text = os.getenv("TEST_STR2") + dockerfile_content = generate_dockerfile_content_custom_app(name) + dockerfile = "Dockerfile" + response_text = get_response_text2() sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) tag = "uwsgi-nginx-flask-testimage" - test_path: PurePath = Path(__file__) + test_path = Path(__file__) path = test_path.parent / "custom_app" + dockerfile_path = path / dockerfile + dockerfile_path.write_text(dockerfile_content) client.images.build(path=str(path), dockerfile=dockerfile, tag=tag) container = client.containers.run( tag, diff --git a/tests/test_02_app/test_custom_ngnix_app.py b/tests/test_02_app/test_custom_ngnix_app.py index 69837b0e..4d025ed1 100644 --- a/tests/test_02_app/test_custom_ngnix_app.py +++ b/tests/test_02_app/test_custom_ngnix_app.py @@ -1,22 +1,28 @@ import os import time -from pathlib import Path, PurePath +from pathlib import Path import docker -import pytest import requests +from docker.models.containers import Container from ..utils import ( CONTAINER_NAME, + generate_dockerfile_content_custom_nginx_app, get_logs, get_nginx_config, + get_response_text2, remove_previous_container, ) client = docker.from_env() -def verify_container(container, response_text): +def verify_container(container: Container, response_text: str) -> None: + response = requests.get("http://127.0.0.1:8080") + assert response.text == response_text + response = requests.get("http://127.0.0.1:8080/static/test.txt") + assert response.text == "Static, from Flask" nginx_config = get_nginx_config(container) assert "client_max_body_size 0;" not in nginx_config assert "worker_processes 2;" in nginx_config @@ -62,28 +68,20 @@ def verify_container(container, response_text): assert 'running "unix_signal:15 gracefully_kill_them_all" (master-start)' in logs assert "success: nginx entered RUNNING state, process has stayed up for" in logs assert "success: uwsgi entered RUNNING state, process has stayed up for" in logs - response = requests.get("http://127.0.0.1:8080") - assert response.status_code == 200 - assert response.text == response_text - response = requests.get("http://127.0.0.1:8080/static/test.txt") - assert response.status_code == 200 - assert response.text == "Static, from Flask" -def test_env_vars_1(): - if not os.getenv("RUN_TESTS"): - return - name = os.getenv("NAME") - # It's an index postfix tag, skip it - if "index" in name: - return - dockerfile = f"{name}.dockerfile" - response_text = os.getenv("TEST_STR2") +def test_env_vars_1() -> None: + name = os.getenv("NAME", "") + dockerfile_content = generate_dockerfile_content_custom_nginx_app(name) + dockerfile = "Dockerfile" + response_text = get_response_text2() sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) tag = "uwsgi-nginx-flask-testimage" - test_path: PurePath = Path(__file__) + test_path = Path(__file__) path = test_path.parent / "custom_nginx_app" + dockerfile_path = path / dockerfile + dockerfile_path.write_text(dockerfile_content) client.images.build(path=str(path), dockerfile=dockerfile, tag=tag) container = client.containers.run( tag, name=CONTAINER_NAME, ports={"8080": "8080"}, detach=True diff --git a/tests/test_02_app/test_simple_app.py b/tests/test_02_app/test_simple_app.py index b58b0985..931e56fc 100644 --- a/tests/test_02_app/test_simple_app.py +++ b/tests/test_02_app/test_simple_app.py @@ -1,22 +1,28 @@ import os import time -from pathlib import Path, PurePath +from pathlib import Path import docker -import pytest import requests +from docker.models.containers import Container from ..utils import ( CONTAINER_NAME, + generate_dockerfile_content_simple_app, get_logs, get_nginx_config, + get_response_text2, remove_previous_container, ) client = docker.from_env() -def verify_container(container, response_text): +def verify_container(container: Container, response_text: str) -> None: + response = requests.get("http://127.0.0.1:8000") + assert response.text == response_text + response = requests.get("http://127.0.0.1:8000/static/test.txt") + assert response.text == "Static test" nginx_config = get_nginx_config(container) assert "client_max_body_size 0;" in nginx_config assert "worker_processes 1;" in nginx_config @@ -62,28 +68,20 @@ def verify_container(container, response_text): assert 'running "unix_signal:15 gracefully_kill_them_all" (master-start)' in logs assert "success: nginx entered RUNNING state, process has stayed up for" in logs assert "success: uwsgi entered RUNNING state, process has stayed up for" in logs - response = requests.get("http://127.0.0.1:8000") - assert response.status_code == 200 - assert response.text == response_text - response = requests.get("http://127.0.0.1:8000/static/test.txt") - assert response.status_code == 200 - assert response.text == "Static test" -def test_env_vars_1(): - if not os.getenv("RUN_TESTS"): - return - name = os.getenv("NAME") - # It's an index postfix tag, skip it - if "index" in name: - return - dockerfile = f"{name}.dockerfile" - response_text = os.getenv("TEST_STR2") +def test_env_vars_1() -> None: + name = os.getenv("NAME", "") + dockerfile_content = generate_dockerfile_content_simple_app(name) + dockerfile = "Dockerfile" + response_text = get_response_text2() sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) tag = "uwsgi-nginx-flask-testimage" - test_path: PurePath = Path(__file__) + test_path = Path(__file__) path = test_path.parent / "simple_app" + dockerfile_path = path / dockerfile + dockerfile_path.write_text(dockerfile_content) client.images.build(path=str(path), dockerfile=dockerfile, tag=tag) container = client.containers.run( tag, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True diff --git a/tests/utils.py b/tests/utils.py index 385aff1a..a3c07031 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,22 +1,56 @@ +import os + +from docker.client import DockerClient from docker.errors import NotFound +from docker.models.containers import Container CONTAINER_NAME = "uwsgi-nginx-flask-test" -def get_logs(container): - logs: str = container.logs() +def get_logs(container: Container) -> str: + logs = container.logs() return logs.decode("utf-8") -def get_nginx_config(container): +def get_nginx_config(container: Container) -> str: result = container.exec_run(f"/usr/sbin/nginx -T") return result.output.decode() -def remove_previous_container(client): +def remove_previous_container(client: DockerClient) -> None: try: previous = client.containers.get(CONTAINER_NAME) previous.stop() previous.remove() except NotFound: return None + + +def get_response_text1() -> str: + python_version = os.getenv("PYTHON_VERSION") + return f"Hello World from Flask in a uWSGI Nginx Docker container with Python {python_version} (default)" + + +def get_response_text2() -> str: + python_version = os.getenv("PYTHON_VERSION") + return f"Hello World from Flask in a uWSGI Nginx Docker container with Python {python_version} - testing" + + +def generate_dockerfile_content_custom_app(name: str) -> str: + content = f"FROM tiangolo/uwsgi-nginx-flask:{name}\n" + content += "COPY ./application /application\n" + content += "COPY ./prestart.sh /app/prestart.sh\n" + content += "WORKDIR /application\n" + return content + + +def generate_dockerfile_content_custom_nginx_app(name: str) -> str: + content = f"FROM tiangolo/uwsgi-nginx-flask:{name}\n" + content += "COPY app /app\n" + return content + + +def generate_dockerfile_content_simple_app(name: str) -> str: + content = f"FROM tiangolo/uwsgi-nginx-flask:{name}\n" + content += "COPY ./app/ /app/\n" + return content From 4efae5161f5f416f6f24ae7c10fd82b6a5cac9e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 4 May 2020 16:04:30 +0200 Subject: [PATCH 07/10] :see_no_evil: Add poetry.lock to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 645bebe2..55eec6eb 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,4 @@ crashlytics-build.properties # Custom Pipfile.lock +poetry.lock From f3ba6d79443cf0fba1adb070c82ded81dbb44c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 4 May 2020 16:04:46 +0200 Subject: [PATCH 08/10] :wrench: Add mypy config --- mypy.ini | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 mypy.ini diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000..4ff4483a --- /dev/null +++ b/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +disallow_untyped_defs = True +ignore_missing_imports = True From f5fae2629bca9e2bd20c3716120a7ffc99e8245c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 4 May 2020 16:06:01 +0200 Subject: [PATCH 09/10] :memo: Update README --- README.md | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 7288070c..d8e27924 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,27 @@ -[![Build Status](https://travis-ci.com/tiangolo/uwsgi-nginx-flask-docker.svg?branch=master)](https://travis-ci.com/tiangolo/uwsgi-nginx-flask-docker) +[![Test](https://github.com/tiangolo/uwsgi-nginx-flask-docker/workflows/Test/badge.svg)](https://github.com/tiangolo/uwsgi-nginx-flask-docker/actions?query=workflow%3ATest) [![Deploy](https://github.com/tiangolo/uwsgi-nginx-flask-docker/workflows/Deploy/badge.svg)](https://github.com/tiangolo/uwsgi-nginx-flask-docker/actions?query=workflow%3ADeploy) ## Supported tags and respective `Dockerfile` links -* [`python3.7`, `latest` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python3.7/Dockerfile) -* [`python3.6` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python3.6/Dockerfile) -* [`python3.6-index` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python3.6-index/Dockerfile) -* [`python3.6-alpine3.7` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python3.6-alpine3.7/Dockerfile) -* [`python3.6-alpine3.8` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python3.6-alpine3.8/Dockerfile) -* [`python3.5` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python3.5/Dockerfile) -* [`python3.5-index` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python3.5/Dockerfile) -* [`python2.7` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python2.7/Dockerfile) -* [`python2.7-index` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python2.7-index/Dockerfile) -* [`python2.7-alpine3.7` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python2.7-alpine3.7/Dockerfile) -* [`python2.7-alpine3.8` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python2.7-alpine3.8/Dockerfile) +* [`python3.7`, `latest` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/docker-images/python3.7.dockerfile) +* [`python3.6` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/docker-images/python3.6.dockerfile) +* [`python3.6-alpine3.8` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/docker-images/python3.6-alpine3.8.dockerfile) +* [`python3.6-alpine3.7` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/docker-images/python3.6-alpine3.7.dockerfile) +* [`python3.5` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/docker-images/python3.5.dockerfile) +* [`python2.7` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/docker-images/python2.7.dockerfile) +* [`python2.7-alpine3.8` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/docker-images/python2.7-alpine3.8.dockerfile) +* [`python2.7-alpine3.7` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/docker-images/python2.7-alpine3.7.dockerfile) **Note**: Note: There are [tags for each build date](https://hub.docker.com/r/tiangolo/uwsgi-nginx-flask/tags). If you need to "pin" the Docker image version you use, you can select one of those tags. E.g. `tiangolo/uwsgi-nginx-flask:python3.7-2019-10-14`. -## Temporarily not supported +## Python 3.7 not supported in in Alpine -* [`python3.7-alpine3.7` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python3.7-alpine3.7/Dockerfile) and [`python3.7-alpine3.8` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/python3.7-alpine3.8/Dockerfile) Temporarily not supported as uWSGI has not been released with Python 3.7 support for [Alpine 3.7](https://pkgs.alpinelinux.org/package/v3.7/main/x86/uwsgi-python3) nor for [Alpine 3.8](https://pkgs.alpinelinux.org/package/v3.8/main/x86/uwsgi-python3) +As uWSGI has not been released with Python 3.7 support for [Alpine 3.7](https://pkgs.alpinelinux.org/package/v3.7/main/x86/uwsgi-python3) and [Alpine 3.8](https://pkgs.alpinelinux.org/package/v3.8/main/x86/uwsgi-python3), it is still not supported. + +It doesn't depend on this image but on uWSGI releases for Alpine. # uwsgi-nginx-flask -**Docker** image with **uWSGI** and **Nginx** for **Flask** web applications in **Python 3.7**, **Python 3.6**, **Python 3.5** and **Python 2.7** running in a single container. Optionally using Alpine Linux. +**Docker** image with **uWSGI** and **Nginx** for **Flask** web applications in **Python 3.5** and above, and **Python 2.7** running in a single container. Optionally using Alpine Linux. ## Description From 3b104a7393c9f48845efefbea0fce56f8958515d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 4 May 2020 16:19:59 +0200 Subject: [PATCH 10/10] :bug: Fix Python 2.7 base image --- docker-images/python2.7.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-images/python2.7.dockerfile b/docker-images/python2.7.dockerfile index 4d7e3b6c..1f3f53d2 100644 --- a/docker-images/python2.7.dockerfile +++ b/docker-images/python2.7.dockerfile @@ -1,4 +1,4 @@ -FROM tiangolo/uwsgi-nginx:python3.5 +FROM tiangolo/uwsgi-nginx:python2.7 LABEL maintainer="Sebastian Ramirez "