-
-
Notifications
You must be signed in to change notification settings - Fork 609
/
Copy pathutils.py
56 lines (38 loc) · 1.64 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
from docker.client import DockerClient
from docker.errors import NotFound
from docker.models.containers import Container
CONTAINER_NAME = "uwsgi-nginx-flask-test"
def get_logs(container: Container) -> str:
logs = container.logs()
return logs.decode("utf-8")
def get_nginx_config(container: Container) -> str:
result = container.exec_run(f"/usr/sbin/nginx -T")
return result.output.decode()
def remove_previous_container(client: DockerClient) -> None:
try:
previous = client.containers.get(CONTAINER_NAME)
previous.stop()
previous.remove()
except NotFound:
return None
def get_response_text1() -> str:
python_version = os.getenv("PYTHON_VERSION")
return f"Hello World from Flask in a uWSGI Nginx Docker container with Python {python_version} (default)"
def get_response_text2() -> str:
python_version = os.getenv("PYTHON_VERSION")
return f"Hello World from Flask in a uWSGI Nginx Docker container with Python {python_version} - testing"
def generate_dockerfile_content_custom_app(name: str) -> str:
content = f"FROM tiangolo/uwsgi-nginx-flask:{name}\n"
content += "COPY ./application /application\n"
content += "COPY ./prestart.sh /app/prestart.sh\n"
content += "WORKDIR /application\n"
return content
def generate_dockerfile_content_custom_nginx_app(name: str) -> str:
content = f"FROM tiangolo/uwsgi-nginx-flask:{name}\n"
content += "COPY app /app\n"
return content
def generate_dockerfile_content_simple_app(name: str) -> str:
content = f"FROM tiangolo/uwsgi-nginx-flask:{name}\n"
content += "COPY ./app/ /app/\n"
return content