-
-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First tests and updates to default apps to expose Python versions
- Loading branch information
Showing
14 changed files
with
191 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import sys | ||
|
||
|
||
def application(env, start_response): | ||
start_response('200 OK', [('Content-Type', 'text/html')]) | ||
return ["Hello World from a default Nginx uWSGI Python 2.7 app in a\ | ||
Docker container (default)"] | ||
version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) | ||
start_response("200 OK", [("Content-Type", "text/plain")]) | ||
message = "Hello World from a default Nginx uWSGI Python {} app in a Docker container in Alpine (default)".format( | ||
version | ||
) | ||
return [message.encode("utf-8")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import sys | ||
|
||
|
||
def application(env, start_response): | ||
start_response('200 OK', [('Content-Type', 'text/html')]) | ||
return ["Hello World from a default Nginx uWSGI Python 2.7 app in a\ | ||
Docker container (default)"] | ||
version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) | ||
start_response("200 OK", [("Content-Type", "text/plain")]) | ||
message = "Hello World from a default Nginx uWSGI Python {} app in a Docker container in Alpine (default)".format( | ||
version | ||
) | ||
return [message.encode("utf-8")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import sys | ||
|
||
|
||
def application(env, start_response): | ||
start_response('200 OK', [('Content-Type', 'text/html')]) | ||
return ["Hello World from a default Nginx uWSGI Python 2.7 app in a\ | ||
Docker container (default)"] | ||
version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) | ||
start_response("200 OK", [("Content-Type", "text/plain")]) | ||
message = "Hello World from a default Nginx uWSGI Python {} app in a Docker container (default)".format( | ||
version | ||
) | ||
return [message.encode("utf-8")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import sys | ||
|
||
|
||
def application(env, start_response): | ||
start_response('200 OK', [('Content-Type', 'text/html')]) | ||
return [b"Hello World from a default Nginx uWSGI Python 3.5 app in a\ | ||
Docker container (default)"] | ||
version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) | ||
start_response("200 OK", [("Content-Type", "text/plain")]) | ||
message = "Hello World from a default Nginx uWSGI Python {} app in a Docker container (default)".format( | ||
version | ||
) | ||
return [message.encode("utf-8")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import sys | ||
|
||
|
||
def application(env, start_response): | ||
start_response('200 OK', [('Content-Type', 'text/html')]) | ||
return [b"Hello World from a default Nginx uWSGI Python 3.6 app in a\ | ||
Docker container (default)"] | ||
version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) | ||
start_response("200 OK", [("Content-Type", "text/plain")]) | ||
message = "Hello World from a default Nginx uWSGI Python {} app in a Docker container in Alpine (default)".format( | ||
version | ||
) | ||
return [message.encode("utf-8")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import sys | ||
|
||
|
||
def application(env, start_response): | ||
start_response('200 OK', [('Content-Type', 'text/html')]) | ||
return [b"Hello World from a default Nginx uWSGI Python 3.6 app in a\ | ||
Docker container (default)"] | ||
version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) | ||
start_response("200 OK", [("Content-Type", "text/plain")]) | ||
message = "Hello World from a default Nginx uWSGI Python {} app in a Docker container in Alpine (default)".format( | ||
version | ||
) | ||
return [message.encode("utf-8")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import sys | ||
|
||
|
||
def application(env, start_response): | ||
start_response('200 OK', [('Content-Type', 'text/html')]) | ||
return [b"Hello World from a default Nginx uWSGI Python 3.6 app in a\ | ||
Docker container (default)"] | ||
version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) | ||
start_response("200 OK", [("Content-Type", "text/plain")]) | ||
message = "Hello World from a default Nginx uWSGI Python {} app in a Docker container (default)".format( | ||
version | ||
) | ||
return [message.encode("utf-8")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import sys | ||
|
||
|
||
def application(env, start_response): | ||
start_response('200 OK', [('Content-Type', 'text/html')]) | ||
return [b"Hello World from a default Nginx uWSGI Python 3.7 app in a\ | ||
Docker container (default)"] | ||
version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) | ||
start_response("200 OK", [("Content-Type", "text/plain")]) | ||
message = "Hello World from a default Nginx uWSGI Python {} app in a Docker container in Alpine (default)".format( | ||
version | ||
) | ||
return [message.encode("utf-8")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import sys | ||
|
||
|
||
def application(env, start_response): | ||
start_response('200 OK', [('Content-Type', 'text/html')]) | ||
return [b"Hello World from a default Nginx uWSGI Python 3.7 app in a\ | ||
Docker container (default)"] | ||
version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) | ||
start_response("200 OK", [("Content-Type", "text/plain")]) | ||
message = "Hello World from a default Nginx uWSGI Python {} app in a Docker container in Alpine (default)".format( | ||
version | ||
) | ||
return [message.encode("utf-8")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import sys | ||
|
||
|
||
def application(env, start_response): | ||
start_response('200 OK', [('Content-Type', 'text/html')]) | ||
return [b"Hello World from a default Nginx uWSGI Python 3.7 app in a\ | ||
Docker container (default)"] | ||
version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) | ||
start_response("200 OK", [("Content-Type", "text/plain")]) | ||
message = "Hello World from a default Nginx uWSGI Python {} app in a Docker container (default)".format( | ||
version | ||
) | ||
return [message.encode("utf-8")] |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import time | ||
|
||
import docker | ||
import pytest | ||
import requests | ||
from requests import Response | ||
|
||
from ..utils import CONTAINER_NAME, stop_previous_container, get_uwsgi_config, get_nginx_config | ||
|
||
client = docker.from_env() | ||
|
||
|
||
@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): | ||
stop_previous_container(client) | ||
container = client.containers.run( | ||
image, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True | ||
) | ||
uwsgi_config = get_uwsgi_config(container) | ||
assert "ini = /app/uwsgi.ini" in uwsgi_config | ||
assert "wsgi-file = /app/main.py" in uwsgi_config | ||
assert "processes = 16" in uwsgi_config | ||
assert "cheaper = 2" in uwsgi_config | ||
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 | ||
time.sleep(5) | ||
response: Response = requests.get("http://127.0.0.1:8000") | ||
assert response.status_code == 200 | ||
assert response.text == response_text | ||
container.stop() | ||
container.remove() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import json | ||
|
||
from docker.errors import NotFound | ||
|
||
CONTAINER_NAME = "uwsgi-nginx-text" | ||
|
||
|
||
def get_uwsgi_config(container): | ||
result = container.exec_run(f"uwsgi --show-config") | ||
return result.output.decode() | ||
|
||
|
||
def get_nginx_config(container): | ||
result = container.exec_run(f"/usr/sbin/nginx -T") | ||
return result.output.decode() | ||
|
||
|
||
def stop_previous_container(client): | ||
try: | ||
previous = client.containers.get(CONTAINER_NAME) | ||
previous.stop() | ||
previous.remove() | ||
except NotFound: | ||
return None |