From 4afbbb288782d2cf49a77362ed69eb8ccb370f97 Mon Sep 17 00:00:00 2001 From: Andrew Simonson Date: Sat, 28 Jan 2023 21:49:59 -0600 Subject: [PATCH] nginx research results, no way this works --- Dockerfile | 32 ++++++++++++++++++++++++-------- ecs-task.json | 18 ++++++++++++++++++ flask.conf | 9 +++++++++ gunicorn.conf | 3 +++ supervisord.conf | 5 +++++ 5 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 ecs-task.json create mode 100644 flask.conf create mode 100644 gunicorn.conf create mode 100644 supervisord.conf diff --git a/Dockerfile b/Dockerfile index 1b45ca9..1e0a10b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,29 @@ -FROM docker.io/python:3.8-buster +# nginx-gunicorn-flask + +FROM ubuntu:12.04 LABEL maintainer="Andrew Simonson " -WORKDIR /app -ADD ./src /app +ENV DEBIAN_FRONTEND noninteractive -COPY . . +RUN apt-get update +RUN apt-get install -y python python-pip python-virtualenv nginx gunicorn supervisor +# do we really need venv? -RUN apt-get -yq update && \ - pip install --no-cache-dir -r ./src/requirements.txt -WORKDIR /app/src +# Setup flask application +RUN mkdir /deploy/app +COPY src /deploy/app +RUN pip install -r /deploy/app/requirements.txt -CMD [ "gunicorn", "--bind", "0.0.0.0:8080", "app:app"] \ No newline at end of file +# Setup nginx +RUN rm /etc/nginx/sites-enabled/default +COPY flask.conf /etc/nginx/sites-available/ +RUN ln -s /etc/nginx/sites-available/flask.conf /etc/nginx/sites-enabled/flask.conf +RUN echo "daemon off;" >> /etc/nginx/nginx.conf + +# Setup supervisord +RUN mkdir -p /var/log/supervisor +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY gunicorn.conf /etc/supervisor/conf.d/gunicorn.conf + +# Start processes (Lol idk how this works) +CMD ["/usr/bin/supervisord"] diff --git a/ecs-task.json b/ecs-task.json new file mode 100644 index 0000000..fc59689 --- /dev/null +++ b/ecs-task.json @@ -0,0 +1,18 @@ +{ + "containerDefinitions": [ + { + "name": "app", + "image": "asimonson1125/asimonson1125.github.io", + "essential": true, + "memory": 500, + "cpu": 10, + "portMappings": [ + { + "containerPort": 80, + "hostPort": 80 + } + ] + } + ], + "family": "Portfolio" +} diff --git a/flask.conf b/flask.conf new file mode 100644 index 0000000..0c1a651 --- /dev/null +++ b/flask.conf @@ -0,0 +1,9 @@ +server { + listen 80; + + location / { + proxy_pass http://localhost:5000/; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} diff --git a/gunicorn.conf b/gunicorn.conf new file mode 100644 index 0000000..6412df9 --- /dev/null +++ b/gunicorn.conf @@ -0,0 +1,3 @@ +[program:gunicorn] +command=/usr/bin/gunicorn app:app -b localhost:5000 +directory=/deploy/app diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 0000000..8d520a8 --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,5 @@ +[supervisord] +nodaemon=true + +[program:nginx] +command=/usr/sbin/nginx