diff --git a/.travis.yml b/.travis.yml index e7b57af5..4e7c28b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,11 +11,32 @@ install: services: - docker +env: + - 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='' + - 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' + script: - bash scripts/test.sh -deploy: - provider: script - script: bash scripts/build-push.sh - on: - branch: master +jobs: + include: + - script: bash scripts/test.sh + - stage: deploy + script: skip + deploy: + provider: script + script: bash scripts/build-push-all.sh + on: + branch: master diff --git a/docker-compose.build.stage01.yml b/docker-compose.build.stage01.yml deleted file mode 100644 index d1824cf3..00000000 --- a/docker-compose.build.stage01.yml +++ /dev/null @@ -1,35 +0,0 @@ -version: '3' -services: - python2.7: - build: ./python2.7 - image: tiangolo/uwsgi-nginx-flask:python2.7 - python2.7-alpine3.7: - build: ./python2.7-alpine3.7 - image: tiangolo/uwsgi-nginx-flask:python2.7-alpine3.7 - python2.7-alpine3.8: - build: ./python2.7-alpine3.8 - image: tiangolo/uwsgi-nginx-flask:python2.7-alpine3.8 - python3.5: - build: ./python3.5 - image: tiangolo/uwsgi-nginx-flask:python3.5 - python3.6: - build: ./python3.6 - image: tiangolo/uwsgi-nginx-flask:python3.6 - python3.6-alpine3.7: - build: ./python3.6-alpine3.7 - image: tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7 - python3.6-alpine3.8: - build: ./python3.6-alpine3.8 - image: tiangolo/uwsgi-nginx-flask:python3.6-alpine3.8 - python3.7: - build: ./python3.7 - image: tiangolo/uwsgi-nginx-flask:python3.7 - latest: - build: ./python3.7 - image: tiangolo/uwsgi-nginx-flask:latest - python3.7-alpine3.7: - build: ./python3.7-alpine3.7 - image: tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7 - python3.7-alpine3.8: - build: ./python3.7-alpine3.8 - image: tiangolo/uwsgi-nginx-flask:python3.7-alpine3.8 diff --git a/docker-compose.build.stage02.yml b/docker-compose.build.stage02.yml deleted file mode 100644 index 90642597..00000000 --- a/docker-compose.build.stage02.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: '3' -services: - python2.7-index: - build: ./python2.7-index - image: tiangolo/uwsgi-nginx-flask:python2.7-index - python3.5-index: - build: ./python3.5-index - image: tiangolo/uwsgi-nginx-flask:python3.5-index - python3.6-index: - build: ./python3.6-index - image: tiangolo/uwsgi-nginx-flask:python3.6-index diff --git a/scripts/build-push-all.sh b/scripts/build-push-all.sh new file mode 100644 index 00000000..e54d3f10 --- /dev/null +++ b/scripts/build-push-all.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + +BUILD_PUSH=1 python scripts/process_all.py diff --git a/scripts/build-push.sh b/scripts/build-push.sh index b9a1c04e..72aed823 100644 --- a/scripts/build-push.sh +++ b/scripts/build-push.sh @@ -2,12 +2,12 @@ set -e -echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin +use_tag="tiangolo/uwsgi-nginx-flask:$NAME" +use_dated_tag="${use_tag}-$(date -I)" -docker-compose -f docker-compose.build.stage01.yml build +docker build -t "$use_tag" "$BUILD_PATH" -docker-compose -f docker-compose.build.stage01.yml push +docker tag "$use_tag" "$use_dated_tag" -docker-compose -f docker-compose.build.stage02.yml build - -docker-compose -f docker-compose.build.stage02.yml push +docker push "$use_tag" +docker push "$use_dated_tag" diff --git a/scripts/process_all.py b/scripts/process_all.py new file mode 100644 index 00000000..8a90f924 --- /dev/null +++ b/scripts/process_all.py @@ -0,0 +1,144 @@ +import os +import subprocess +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", + }, +] + +start_with = os.environ.get("START_WITH") +build_push = os.environ.get("BUILD_PUSH") + + +def process_tag(*, env: dict): + use_env = {**os.environ, **env} + script = "scripts/test.sh" + if build_push: + script = "scripts/build-push.sh" + return_code = subprocess.call(["bash", script], env=use_env) + if return_code != 0: + sys.exit(return_code) + + +def print_version_envs(): + env_lines = [] + for env in environments: + env_vars = [] + for key, value in env.items(): + env_vars.append(f"{key}='{value}'") + env_lines.append(" ".join(env_vars)) + for line in env_lines: + print(line) + + +def main(): + start_at = 0 + if start_with: + start_at = [ + i for i, env in enumerate((environments)) if env["NAME"] == start_with + ][0] + for i, env in enumerate(environments[start_at:]): + print(f"Processing tag: {env['NAME']}") + process_tag(env=env) + + +if __name__ == "__main__": + if len(sys.argv) > 1: + print_version_envs() + else: + main() diff --git a/scripts/test-all.sh b/scripts/test-all.sh new file mode 100644 index 00000000..89b34d38 --- /dev/null +++ b/scripts/test-all.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +python scripts/process_all.py diff --git a/scripts/test.sh b/scripts/test.sh index 11d53a32..73f823fa 100644 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e -docker-compose -f docker-compose.build.stage01.yml build -docker-compose -f docker-compose.build.stage02.yml build +use_tag="tiangolo/uwsgi-nginx-flask:$NAME" + +docker build -t "$use_tag" "$BUILD_PATH" pytest tests diff --git a/tests/test_01_main/test_defaults_01.py b/tests/test_01_main/test_defaults_01.py index 5b8fbe6b..a1ea1476 100644 --- a/tests/test_01_main/test_defaults_01.py +++ b/tests/test_01_main/test_defaults_01.py @@ -1,3 +1,4 @@ +import os import time import docker @@ -65,62 +66,26 @@ def verify_container(container, response_text): assert response.text == response_text -@pytest.mark.parametrize( - "image,response_text", - [ - ( - "tiangolo/uwsgi-nginx-flask:python2.7", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python2.7-alpine3.7", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 on Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python2.7-alpine3.8", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 on Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python3.5", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.5 (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python3.6", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 on Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python3.6-alpine3.8", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 on Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python3.7", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 (default)", - ), - # ( - # "tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7", - # "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 on Alpine (default)", - # ), - # ( - # "tiangolo/uwsgi-nginx-flask:python3.7-alpine3.8", - # "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 on Alpine (default)", - # ), - ], -) -def test_defaults(image, 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 + 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(5) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() # Test that everything works after restarting too container.start() - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() container.remove() diff --git a/tests/test_01_main/test_defaults_02_index.py b/tests/test_01_main/test_defaults_02_index.py index 9184c114..8e073b0d 100644 --- a/tests/test_01_main/test_defaults_02_index.py +++ b/tests/test_01_main/test_defaults_02_index.py @@ -1,3 +1,4 @@ +import os import time import docker @@ -80,34 +81,26 @@ def verify_container(container, response_text): assert response.text == response_text -@pytest.mark.parametrize( - "image,response_text", - [ - ( - "tiangolo/uwsgi-nginx-flask:python2.7-index", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python3.5-index", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.5 (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python3.6-index", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 (default)", - ), - ], -) -def test_defaults(image, 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(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() # Test that everything works after restarting too container.start() - time.sleep(3) + 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 e4f5b9a8..b6ae9ab8 100644 --- a/tests/test_01_main/test_env_vars_03.py +++ b/tests/test_01_main/test_env_vars_03.py @@ -1,3 +1,4 @@ +import os import time import docker @@ -68,52 +69,16 @@ def verify_container(container, response_text): assert response.text == response_text -@pytest.mark.parametrize( - "image,response_text", - [ - ( - "tiangolo/uwsgi-nginx-flask:python2.7", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python2.7-alpine3.7", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 on Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python2.7-alpine3.8", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 on Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python3.5", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.5 (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python3.6", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 on Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python3.6-alpine3.8", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 on Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx-flask:python3.7", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 (default)", - ), - # ( - # "tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7", - # "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 on Alpine (default)", - # ), - # ( - # "tiangolo/uwsgi-nginx-flask:python3.7-alpine3.8", - # "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 on Alpine (default)", - # ), - ], -) -def test_defaults(image, 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 + 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, @@ -129,12 +94,12 @@ def test_defaults(image, response_text): ports={"80": "8000"}, detach=True, ) - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() # Test that everything works after restarting too container.start() - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() container.remove() 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 8544c428..c99d4f2d 100644 --- a/tests/test_02_app/test_app_and_env_vars.py +++ b/tests/test_02_app/test_app_and_env_vars.py @@ -1,3 +1,4 @@ +import os import time from pathlib import Path, PurePath @@ -69,56 +70,16 @@ def verify_container(container, response_text): assert response.text == "Static test" -@pytest.mark.parametrize( - "dockerfile,response_text", - [ - ( - "python2.7.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", - ), - ( - "python2.7-alpine3.7.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", - ), - ( - "python2.7-alpine3.8.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", - ), - ( - "python3.5.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.5 - testing", - ), - ( - "python3.6.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", - ), - ( - "python3.6-alpine3.7.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", - ), - ( - "python3.6-alpine3.8.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", - ), - ( - "python3.7.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - ), - ( - "latest.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - ), - # ( - # "python3.7-alpine3.7.dockerfile", - # "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - # ), - # ( - # "python3.7-alpine3.8.dockerfile", - # "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - # ), - ], -) -def test_env_vars_1(dockerfile, response_text): +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") + sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) tag = "uwsgi-nginx-flask-testimage" test_path: PurePath = Path(__file__) @@ -137,12 +98,12 @@ def test_env_vars_1(dockerfile, response_text): ports={"8080": "8000"}, detach=True, ) - time.sleep(5) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() # Test that everything works after restarting too container.start() - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() container.remove() diff --git a/tests/test_02_app/test_custom_ngnix_app.py b/tests/test_02_app/test_custom_ngnix_app.py index 0af6af92..69837b0e 100644 --- a/tests/test_02_app/test_custom_ngnix_app.py +++ b/tests/test_02_app/test_custom_ngnix_app.py @@ -1,3 +1,4 @@ +import os import time from pathlib import Path, PurePath @@ -69,56 +70,16 @@ def verify_container(container, response_text): assert response.text == "Static, from Flask" -@pytest.mark.parametrize( - "dockerfile,response_text", - [ - ( - "python2.7.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", - ), - ( - "python2.7-alpine3.7.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", - ), - ( - "python2.7-alpine3.8.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", - ), - ( - "python3.5.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.5 - testing", - ), - ( - "python3.6.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", - ), - ( - "python3.6-alpine3.7.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", - ), - ( - "python3.6-alpine3.8.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", - ), - ( - "python3.7.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - ), - ( - "latest.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - ), - # ( - # "python3.7-alpine3.7.dockerfile", - # "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - # ), - # ( - # "python3.7-alpine3.8.dockerfile", - # "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - # ), - ], -) -def test_env_vars_1(dockerfile, response_text): +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") + sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) tag = "uwsgi-nginx-flask-testimage" test_path: PurePath = Path(__file__) @@ -127,12 +88,12 @@ def test_env_vars_1(dockerfile, response_text): container = client.containers.run( tag, name=CONTAINER_NAME, ports={"8080": "8080"}, detach=True ) - time.sleep(5) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() # Test that everything works after restarting too container.start() - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() container.remove() diff --git a/tests/test_02_app/test_simple_app.py b/tests/test_02_app/test_simple_app.py index 92fef896..b58b0985 100644 --- a/tests/test_02_app/test_simple_app.py +++ b/tests/test_02_app/test_simple_app.py @@ -1,3 +1,4 @@ +import os import time from pathlib import Path, PurePath @@ -69,56 +70,16 @@ def verify_container(container, response_text): assert response.text == "Static test" -@pytest.mark.parametrize( - "dockerfile,response_text", - [ - ( - "python2.7.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", - ), - ( - "python2.7-alpine3.7.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", - ), - ( - "python2.7-alpine3.8.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 2.7 - testing", - ), - ( - "python3.5.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.5 - testing", - ), - ( - "python3.6.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", - ), - ( - "python3.6-alpine3.7.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", - ), - ( - "python3.6-alpine3.8.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.6 - testing", - ), - ( - "python3.7.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - ), - ( - "latest.dockerfile", - "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - ), - # ( - # "python3.7-alpine3.7.dockerfile", - # "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - # ), - # ( - # "python3.7-alpine3.8.dockerfile", - # "Hello World from Flask in a uWSGI Nginx Docker container with Python 3.7 - testing", - # ), - ], -) -def test_env_vars_1(dockerfile, response_text): +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") + sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) tag = "uwsgi-nginx-flask-testimage" test_path: PurePath = Path(__file__) @@ -127,12 +88,12 @@ def test_env_vars_1(dockerfile, response_text): container = client.containers.run( tag, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True ) - time.sleep(5) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() # Test that everything works after restarting too container.start() - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() container.remove()