From bf9a2398da97c12e38267d1865b17dff0631f6d5 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 4 Oct 2022 21:48:52 +0200 Subject: [PATCH] add nginx to docker --- Dockerfile | 10 ++- docker-compose.yml | 69 +++++++++---------- env | 4 +- files/__main__.py | 5 +- files/routes/login.py | 2 +- ...erve-static.txt => nginx-serve-static.conf | 0 nginx.txt => nginx.conf | 10 ++- startup_docker.sh | 7 ++ supervisord.conf | 8 +-- ubuntu_setup.sh | 7 +- 10 files changed, 64 insertions(+), 58 deletions(-) rename nginx-serve-static.txt => nginx-serve-static.conf (100%) rename nginx.txt => nginx.conf (81%) create mode 100644 startup_docker.sh diff --git a/Dockerfile b/Dockerfile index 6fcc39e63..fd04990a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,7 @@ RUN apt install -y ffmpeg RUN apt install -y imagemagick RUN apt install -y postgresql RUN apt install -y libpq-dev - -COPY supervisord.conf /etc/supervisord.conf +RUN apt install -y nano COPY requirements.txt /etc/requirements.txt @@ -39,6 +38,11 @@ RUN node --version RUN npm --version RUN npm i -g yarn +RUN apt install -y nginx +RUN rm /etc/nginx/sites-available -r +RUN rm /etc/nginx/sites-enabled/default +RUN mkdir /etc/nginx/includes + EXPOSE 80/tcp -CMD [ "/usr/bin/supervisord", "-c", "/etc/supervisord.conf" ] +CMD [ "/usr/bin/supervisord", "-c", "/rDrama/supervisord.conf" ] diff --git a/docker-compose.yml b/docker-compose.yml index b53fb74b3..067f29343 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,38 +1,37 @@ -version: '2.3' - services: - files: - container_name: "rDrama" - build: - context: . - volumes: - - "./:/service" - env_file: env - environment: - - DATABASE_URL=postgresql://postgres@postgres:5432 - - REDIS_URL=redis://redis - links: - - "redis" - - "postgres" - ports: - - "80:80" - depends_on: - - redis - - postgres + files: + container_name: "rDrama" + build: + context: . + volumes: + - "./:/rDrama" + - "./nginx.conf:/etc/nginx/sites-enabled/1" + - "./nginx-serve-static.conf:/etc/nginx/includes/serve-static" + env_file: env + environment: + - DATABASE_URL=postgresql://postgres@postgres:5432 + - REDIS_URL=redis://redis + links: + - "redis" + - "postgres" + ports: + - "80:80" + depends_on: + - redis + - postgres - redis: - image: redis - ports: - - "6379:6379" + redis: + image: redis + ports: + - "6379:6379" - postgres: - image: postgres:12.3 - command: ["postgres", "-c", "log_statement=all"] - # uncomment this if u wanna output all SQL queries to the console - volumes: - - "./schema.sql:/docker-entrypoint-initdb.d/00-schema.sql" - - "./seed-db.sql:/docker-entrypoint-initdb.d/10-seed-db.sql" - environment: - - POSTGRES_HOST_AUTH_METHOD=trust - ports: - - "5432:5432" \ No newline at end of file + postgres: + image: postgres + command: ["postgres", "-c", "log_statement=all"] + volumes: + - "./schema.sql:/docker-entrypoint-initdb.d/00-schema.sql" + - "./seed-db.sql:/docker-entrypoint-initdb.d/10-seed-db.sql" + environment: + - POSTGRES_HOST_AUTH_METHOD=trust + ports: + - "5432:5432" diff --git a/env b/env index 451329fe4..5148d6ff6 100644 --- a/env +++ b/env @@ -1,4 +1,4 @@ -FLASK_APP=/service/files/cli:app +FLASK_APP=/rDrama/files/cli:app MASTER_KEY=blahblahblah DOMAIN=localhost SITE_NAME=rDrama @@ -33,4 +33,4 @@ CF_KEY=blahblahblah CF_ZONE=blahblahblah DEBIAN_FRONTEND=noninteractive NODE_VERSION=16.13.0 -NVM_DIR=/root/.nvm \ No newline at end of file +NVM_DIR=/root/.nvm diff --git a/files/__main__.py b/files/__main__.py index ba67a1748..340278a17 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -129,10 +129,7 @@ def teardown_request(error): del g.db stdout.flush() -if app.config["SERVER_NAME"] == 'localhost': - from files.routes import * - from files.routes.chat import * -elif "load_chat" in argv: +if "load_chat" in argv: from files.routes.chat import * else: from files.routes import * diff --git a/files/routes/login.py b/files/routes/login.py index 65b99b8ef..4dbca64b3 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -284,7 +284,7 @@ def sign_up_post(v): return signup_error("There was a problem. Please try again.") if not hmac.compare_digest(correct_formkey, form_formkey): - return signup_error("There was a problem. Please try again.") + return signup_error("There was a problem. Please try again!") if not request.values.get( "password") == request.values.get("password_confirm"): diff --git a/nginx-serve-static.txt b/nginx-serve-static.conf similarity index 100% rename from nginx-serve-static.txt rename to nginx-serve-static.conf diff --git a/nginx.txt b/nginx.conf similarity index 81% rename from nginx.txt rename to nginx.conf index 160ab3ec9..efb4743de 100644 --- a/nginx.txt +++ b/nginx.conf @@ -1,17 +1,15 @@ server { server_name rdrama.net; client_max_body_size 100m; - listen 443 ssl; - listen [::]:443 ssl; - ssl_certificate '/rdrama.pem'; - ssl_certificate_key '/rdrama.key'; - proxy_set_header Host $host; + listen 80; + listen [::]:80; + proxy_set_header Host $http_host; location / { proxy_pass http://localhost:5000/; } location /socket.io { - include proxy_params; + proxy_set_header Host $http_host; proxy_http_version 1.1; proxy_buffering off; proxy_set_header Upgrade $http_upgrade; diff --git a/startup_docker.sh b/startup_docker.sh new file mode 100644 index 000000000..5144d291c --- /dev/null +++ b/startup_docker.sh @@ -0,0 +1,7 @@ +/etc/init.d/nginx start +cd ./chat +yarn install +yarn chat +cd .. +gunicorn files.__main__:app load_chat -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 -b 0.0.0.0:5001 --max-requests 30000 --max-requests-jitter 30000 -D +gunicorn files.__main__:app -k gevent -w 1 --reload -b 0.0.0.0:5000 --max-requests 30000 --max-requests-jitter 10000 diff --git a/supervisord.conf b/supervisord.conf index 0bde4b3fe..051e73a02 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -3,10 +3,10 @@ nodaemon=true pidfile=/tmp/supervisord.pid logfile=/tmp/supervisord.log -[program:service] -directory=/service -command=gunicorn files.__main__:app -k gevent -w 1 --reload -b 0.0.0.0:80 --max-requests 30000 --max-requests-jitter 10000 +[program:rDrama] +directory=/rDrama +command=sh startup_docker.sh stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 \ No newline at end of file +stderr_logfile_maxbytes=0 diff --git a/ubuntu_setup.sh b/ubuntu_setup.sh index dbbc1f0f2..8973a654d 100644 --- a/ubuntu_setup.sh +++ b/ubuntu_setup.sh @@ -4,7 +4,7 @@ # reboot apt -y update apt -y upgrade -apt -y install git redis-server python3-pip ffmpeg imagemagick tmux nginx snapd ufw gpg-agent htop +apt -y install git redis-server python3-pip ffmpeg imagemagick tmux nginx snapd ufw gpg-agent htop nano git config --global credential.helper store cd /rDrama @@ -29,8 +29,9 @@ chown postgres:postgres /etc/postgresql/14/main/pg_hba.conf sudo rm /etc/nginx/sites-available -r sudo rm /etc/nginx/sites-enabled/default sudo mkdir /etc/nginx/includes -sudo cp nginx.txt /etc/nginx/sites-enabled/1 -sudo cp nginx-serve-static.txt /etc/nginx/includes/serve-static +sudo cp nginx.conf /etc/nginx/sites-enabled/1 +sudo cp nginx-serve-static.conf /etc/nginx/includes/serve-static +/etc/init.d/nginx reload psql -U postgres -f schema.sql postgres psql -U postgres -f seed-db.sql postgres