Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests dated tags #154

Merged
merged 3 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 0 additions & 35 deletions docker-compose.build.stage01.yml

This file was deleted.

11 changes: 0 additions & 11 deletions docker-compose.build.stage02.yml

This file was deleted.

7 changes: 7 additions & 0 deletions scripts/build-push-all.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions scripts/build-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
144 changes: 144 additions & 0 deletions scripts/process_all.py
Original file line number Diff line number Diff line change
@@ -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()
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/process_all.py
5 changes: 3 additions & 2 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -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
61 changes: 13 additions & 48 deletions tests/test_01_main/test_defaults_01.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import time

import docker
Expand Down Expand Up @@ -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()
Loading