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

Fix python 3.8 Alpine #84

Merged
merged 3 commits into from
May 9, 2020
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
13 changes: 1 addition & 12 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
# These are supported funding model platforms

github: [tiangolo] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
# patreon: # Replace with a single Patreon username
# open_collective: # Replace with a single Open Collective username
# ko_fi: # Replace with a single Ko-fi username
# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
# liberapay: # Replace with a single Liberapay username
# issuehunt: # Replace with a single IssueHunt username
# otechie: # Replace with a single Otechie username
# custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
github: [tiangolo]
2 changes: 1 addition & 1 deletion docker-images/python3.8-alpine.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ENV LISTEN_PORT 80

# Used by the entrypoint to explicitly add installed Python packages
# and uWSGI Python packages to PYTHONPATH otherwise uWSGI can't import Flask
ENV ALPINEPYTHON python3.6
ENV ALPINEPYTHON python3.8

# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app
COPY start.sh /start.sh
Expand Down
14 changes: 14 additions & 0 deletions tests/test_02_app/app_with_installs/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys

from flask import Flask

application = Flask(__name__)


@application.route("/")
def hello():
version = "{}.{}".format(sys.version_info.major, sys.version_info.minor)
message = "Hello World from Nginx uWSGI Python {} app in a Docker container".format(
version
)
return message
85 changes: 85 additions & 0 deletions tests/test_02_app/test_app_with_installs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import os
import time
from pathlib import Path

import docker
import requests
from docker.models.containers import Container

from ..utils import (
CONTAINER_NAME, generate_dockerfile_content_app_with_installs,
get_logs,
get_nginx_config,
get_response_text2,
remove_previous_container,
)

client = docker.from_env()


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
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
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 "wsgi-file = /app/main.py" 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


def test_env_vars_1() -> None:
name = os.getenv("NAME", "")
dockerfile_content = generate_dockerfile_content_app_with_installs(name)
dockerfile = "Dockerfile"
response_text = get_response_text2()
sleep_time = int(os.getenv("SLEEP_TIME", 3))
remove_previous_container(client)
tag = "uwsgi-nginx-testimage"
test_path = Path(__file__)
path = test_path.parent / "app_with_installs"
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
)
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()
7 changes: 7 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ def generate_dockerfile_content_simple_app(name: str) -> str:
content = f"FROM tiangolo/uwsgi-nginx:{name}\n"
content += "COPY ./app/main.py /app/main.py\n"
return content


def generate_dockerfile_content_app_with_installs(name: str) -> str:
content = f"FROM tiangolo/uwsgi-nginx:{name}\n"
content += "RUN pip install flask\n"
content += "COPY ./app/main.py /app/main.py\n"
return content