Skip to content

Commit

Permalink
✨ Use Travis matrix, to test all the images in parallel, PR #58
Browse files Browse the repository at this point in the history
Use Travis matrix, to test all the images in parallel
  • Loading branch information
tiangolo authored May 4, 2019
2 parents 03f29cc + a9f5afa commit 1716925
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 258 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ install:
services:
- docker

env:
- NAME='python2.7' BUILD_PATH='python2.7' TEST_STR1='Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container (default)' DOCKERFILE='python2.7.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 2.7 app in a Docker container' RUN_TESTS='1'
- NAME='python2.7-alpine3.7' BUILD_PATH='python2.7-alpine3.7' TEST_STR1='Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)' DOCKERFILE='python2.7-alpine3.7.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 2.7 app in a Docker container' RUN_TESTS='1'
- NAME='python2.7-alpine3.8' BUILD_PATH='python2.7-alpine3.8' TEST_STR1='Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)' DOCKERFILE='python2.7-alpine3.8.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 2.7 app in a Docker container' RUN_TESTS='1'
- NAME='python3.5' BUILD_PATH='python3.5' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.5 app in a Docker container (default)' DOCKERFILE='python3.5.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.5 app in a Docker container' RUN_TESTS='1'
- NAME='python3.6' BUILD_PATH='python3.6' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container (default)' DOCKERFILE='python3.6.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.6 app in a Docker container' RUN_TESTS='1'
- NAME='python3.6-alpine3.7' BUILD_PATH='python3.6-alpine3.7' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)' DOCKERFILE='python3.6-alpine3.7.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.6 app in a Docker container' RUN_TESTS='1'
- NAME='python3.6-alpine3.8' BUILD_PATH='python3.6-alpine3.8' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)' DOCKERFILE='python3.6-alpine3.8.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.6 app in a Docker container' RUN_TESTS='1'
- NAME='python3.7' BUILD_PATH='python3.7' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container (default)' DOCKERFILE='python3.7.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.7 app in a Docker container' RUN_TESTS='1'
- NAME='latest' BUILD_PATH='python3.7' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container (default)' DOCKERFILE='latest.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.7 app in a Docker container' RUN_TESTS='1'
- NAME='python3.7-alpine3.7' BUILD_PATH='python3.7-alpine3.7' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)' DOCKERFILE='python3.7-alpine3.7.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.7 app in a Docker container' RUN_TESTS=''
- NAME='python3.7-alpine3.8' BUILD_PATH='python3.7-alpine3.8' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)' DOCKERFILE='python3.7-alpine3.8.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.7 app in a Docker container' RUN_TESTS=''


script:
- bash scripts/test.sh

Expand Down
4 changes: 4 additions & 0 deletions scripts/test-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -e

python scripts/test_all.py
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -e

docker-compose -f docker-compose.build.yml build
docker-compose -f docker-compose.build.yml build $NAME
pytest tests
124 changes: 124 additions & 0 deletions scripts/test_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import os
import subprocess
import sys

versions = [
{
"NAME": "python2.7",
"BUILD_PATH": "python2.7",
"TEST_STR1": "Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container (default)",
"DOCKERFILE": "python2.7.dockerfile",
"TEST_STR2": "Hello World from Nginx uWSGI Python 2.7 app in a Docker container",
"RUN_TESTS": "1",
},
{
"NAME": "python2.7-alpine3.7",
"BUILD_PATH": "python2.7-alpine3.7",
"TEST_STR1": "Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)",
"DOCKERFILE": "python2.7-alpine3.7.dockerfile",
"TEST_STR2": "Hello World from Nginx uWSGI Python 2.7 app in a Docker container",
"RUN_TESTS": "1",
},
{
"NAME": "python2.7-alpine3.8",
"BUILD_PATH": "python2.7-alpine3.8",
"TEST_STR1": "Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)",
"DOCKERFILE": "python2.7-alpine3.8.dockerfile",
"TEST_STR2": "Hello World from Nginx uWSGI Python 2.7 app in a Docker container",
"RUN_TESTS": "1",
},
{
"NAME": "python3.5",
"BUILD_PATH": "python3.5",
"TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.5 app in a Docker container (default)",
"DOCKERFILE": "python3.5.dockerfile",
"TEST_STR2": "Hello World from Nginx uWSGI Python 3.5 app in a Docker container",
"RUN_TESTS": "1",
},
{
"NAME": "python3.6",
"BUILD_PATH": "python3.6",
"TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container (default)",
"DOCKERFILE": "python3.6.dockerfile",
"TEST_STR2": "Hello World from Nginx uWSGI Python 3.6 app in a Docker container",
"RUN_TESTS": "1",
},
{
"NAME": "python3.6-alpine3.7",
"BUILD_PATH": "python3.6-alpine3.7",
"TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)",
"DOCKERFILE": "python3.6-alpine3.7.dockerfile",
"TEST_STR2": "Hello World from Nginx uWSGI Python 3.6 app in a Docker container",
"RUN_TESTS": "1",
},
{
"NAME": "python3.6-alpine3.8",
"BUILD_PATH": "python3.6-alpine3.8",
"TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)",
"DOCKERFILE": "python3.6-alpine3.8.dockerfile",
"TEST_STR2": "Hello World from Nginx uWSGI Python 3.6 app in a Docker container",
"RUN_TESTS": "1",
},
{
"NAME": "python3.7",
"BUILD_PATH": "python3.7",
"TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container (default)",
"DOCKERFILE": "python3.7.dockerfile",
"TEST_STR2": "Hello World from Nginx uWSGI Python 3.7 app in a Docker container",
"RUN_TESTS": "1",
},
{
"NAME": "latest",
"BUILD_PATH": "python3.7",
"TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container (default)",
"DOCKERFILE": "latest.dockerfile",
"TEST_STR2": "Hello World from Nginx uWSGI Python 3.7 app in a Docker container",
"RUN_TESTS": "1",
},
{
"NAME": "python3.7-alpine3.7",
"BUILD_PATH": "python3.7-alpine3.7",
"TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)",
"DOCKERFILE": "python3.7-alpine3.7.dockerfile",
"TEST_STR2": "Hello World from Nginx uWSGI Python 3.7 app in a Docker container",
"RUN_TESTS": "",
},
{
"NAME": "python3.7-alpine3.8",
"BUILD_PATH": "python3.7-alpine3.8",
"TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)",
"DOCKERFILE": "python3.7-alpine3.8.dockerfile",
"TEST_STR2": "Hello World from Nginx uWSGI Python 3.7 app in a Docker container",
"RUN_TESTS": "",
},
]


def test_tag(*, env: dict):
use_env = {**os.environ, **env}
return_code = subprocess.call(["bash", "scripts/test.sh"], env=use_env)
if return_code != 0:
sys.exit(return_code)


def print_version_envs():
env_lines = []
for version in versions:
env_vars = []
for key, value in version.items():
env_vars.append(f"{key}='{value}'")
env_lines.append(" ".join(env_vars))
for line in env_lines:
print(line)


def main():
for env in versions:
test_tag(env=env)


if __name__ == "__main__":
if len(sys.argv) > 1:
print_version_envs()
else:
main()
59 changes: 10 additions & 49 deletions tests/test_01_main/test_defaults.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import time

import docker
import pytest
import requests
from requests import Response

Expand Down Expand Up @@ -52,62 +52,23 @@ def verify_container(container, response_text):
assert response.text == response_text


@pytest.mark.parametrize(
"image,response_text",
[
(
"tiangolo/uwsgi-nginx:python2.7",
"Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container (default)",
),
(
"tiangolo/uwsgi-nginx:python2.7-alpine3.7",
"Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)",
),
(
"tiangolo/uwsgi-nginx:python2.7-alpine3.8",
"Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)",
),
(
"tiangolo/uwsgi-nginx:python3.5",
"Hello World from a default Nginx uWSGI Python 3.5 app in a Docker container (default)",
),
(
"tiangolo/uwsgi-nginx:python3.6",
"Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container (default)",
),
(
"tiangolo/uwsgi-nginx:python3.6-alpine3.7",
"Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)",
),
(
"tiangolo/uwsgi-nginx:python3.6-alpine3.8",
"Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)",
),
(
"tiangolo/uwsgi-nginx:python3.7",
"Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container (default)",
),
# (
# "tiangolo/uwsgi-nginx:python3.7-alpine3.7",
# "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)",
# ),
# (
# "tiangolo/uwsgi-nginx:python3.7-alpine3.8",
# "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)",
# ),
],
)
def test_defaults(image, response_text):
def test_defaults():
if not os.getenv("RUN_TESTS"):
return
name = os.getenv("NAME")
image = f"tiangolo/uwsgi-nginx:{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()
59 changes: 10 additions & 49 deletions tests/test_01_main/test_env_vars_1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import time

import docker
import pytest
import requests

from ..utils import (
Expand Down Expand Up @@ -53,52 +53,13 @@ def verify_container(container, response_text):
assert response.text == response_text


@pytest.mark.parametrize(
"image,response_text",
[
(
"tiangolo/uwsgi-nginx:python2.7",
"Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container (default)",
),
(
"tiangolo/uwsgi-nginx:python2.7-alpine3.7",
"Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)",
),
(
"tiangolo/uwsgi-nginx:python2.7-alpine3.8",
"Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)",
),
(
"tiangolo/uwsgi-nginx:python3.5",
"Hello World from a default Nginx uWSGI Python 3.5 app in a Docker container (default)",
),
(
"tiangolo/uwsgi-nginx:python3.6",
"Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container (default)",
),
(
"tiangolo/uwsgi-nginx:python3.6-alpine3.7",
"Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)",
),
(
"tiangolo/uwsgi-nginx:python3.6-alpine3.8",
"Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)",
),
(
"tiangolo/uwsgi-nginx:python3.7",
"Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container (default)",
),
# (
# "tiangolo/uwsgi-nginx:python3.7-alpine3.7",
# "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)",
# ),
# (
# "tiangolo/uwsgi-nginx:python3.7-alpine3.8",
# "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)",
# ),
],
)
def test_env_vars_1(image, response_text):
def test_env_vars_1():
if not os.getenv("RUN_TESTS"):
return
name = os.getenv("NAME")
image = f"tiangolo/uwsgi-nginx:{name}"
response_text = os.getenv("TEST_STR1")
sleep_time = int(os.getenv("SLEEP_TIME", 3))
remove_previous_container(client)
container = client.containers.run(
image,
Expand All @@ -114,12 +75,12 @@ def test_env_vars_1(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()
Loading

0 comments on commit 1716925

Please sign in to comment.