add nginx to docker

remotes/1693176582716663532/tmp_refs/heads/watchparty
Aevann1 2022-10-04 03:06:57 +02:00
parent 2108a159a3
commit 7c1eb4c6e3
8 changed files with 60 additions and 145 deletions

View File

@ -1,44 +1,11 @@
FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
ADD .. /service
RUN apt update
RUN apt -y upgrade
RUN apt install -y supervisor
RUN apt install -y python3-pip
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
COPY requirements.txt /etc/requirements.txt
RUN pip3 install -r /etc/requirements.txt
RUN mkdir /images
RUN mkdir /songs
RUN mkdir /videos
RUN mkdir /audio
RUN mkdir /asset_submissions
RUN mkdir /asset_submissions/marseys
RUN mkdir /asset_submissions/hats
RUN mkdir /asset_submissions/marseys/original
RUN mkdir /asset_submissions/hats/original
ENV NODE_VERSION=16.13.0
RUN apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version
RUN npm i -g yarn
RUN /service/ubuntu_setup.sh
EXPOSE 80/tcp
CMD [ "/usr/bin/supervisord", "-c", "/etc/supervisord.conf" ]
RUN apt install -y supervisor
CMD [ "/usr/bin/supervisord", "-c", "/service/supervisord.conf" ]

View File

@ -15,10 +15,11 @@ services:
- "redis"
- "postgres"
ports:
- "80:80"
- "5000:5000"
depends_on:
- redis
- postgres
- nginx
redis:
image: redis
@ -26,9 +27,8 @@ services:
- "6379:6379"
postgres:
image: postgres:12.3
image: postgres
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"
@ -36,3 +36,11 @@ services:
- POSTGRES_HOST_AUTH_METHOD=trust
ports:
- "5432:5432"
nginx:
image: nginx
ports:
- "80:80"
volumes:
- ./nginx.txt:/etc/nginx/conf.d/default.conf
- ./nginx-serve-static.txt:/etc/nginx/includes/serve-static

View File

@ -9,16 +9,6 @@ from files.helpers.get import *
from files.helpers.wrappers import *
from files.routes.static import marsey_list
@app.get('/asset_submissions/<path:path>')
@limiter.exempt
def asset_submissions(path):
resp = make_response(send_from_directory('/asset_submissions', path))
resp.headers.remove("Cache-Control")
resp.headers.add("Cache-Control", "public, max-age=3153600")
resp.headers.remove("Content-Type")
resp.headers.add("Content-Type", "image/webp")
return resp
@app.get("/submit/marseys")
@auth_required
def submit_marseys(v):

View File

@ -297,40 +297,6 @@ def static_service(path):
return resp
### BEGIN FALLBACK ASSET SERVING
# In production, we have nginx serve these locations now.
# These routes stay for local testing. Requests don't reach them on prod.
@app.get('/images/<path>')
@app.get('/hostedimages/<path>')
@app.get("/static/images/<path>")
@limiter.exempt
def images(path):
resp = make_response(send_from_directory('/images', path))
resp.headers.remove("Cache-Control")
resp.headers.add("Cache-Control", "public, max-age=3153600")
resp.headers.remove("Content-Type")
resp.headers.add("Content-Type" ,"image/webp")
return resp
@app.get('/videos/<path>')
@limiter.exempt
def videos(path):
resp = make_response(send_from_directory('/videos', path))
resp.headers.remove("Cache-Control")
resp.headers.add("Cache-Control", "public, max-age=3153600")
return resp
@app.get('/audio/<path>')
@limiter.exempt
def audio(path):
resp = make_response(send_from_directory('/audio', path))
resp.headers.remove("Cache-Control")
resp.headers.add("Cache-Control", "public, max-age=3153600")
return resp
### END FALLBACK ASSET SERVING
@app.get("/robots.txt")
def robots_txt():
return send_file("assets/robots.txt")

View File

@ -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;
location / {
proxy_pass http://localhost:5000/;
proxy_set_header Host $http_host;
proxy_pass http://rDrama: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;
@ -34,9 +32,4 @@ server {
location /asset_submissions/ {
include includes/serve-static;
}
error_page 502 = /error_page/502.html;
location /error_page/ {
alias /rDrama/files/templates/errors/;
}
}

View File

@ -16,17 +16,11 @@ git clone https://github.com/Aevann1/rDrama/
cd rDrama
docker-compose down --rmi all --remove-orphans --volumes
docker-compose up
```
3- That's it! Visit `localhost` in your browser and make an account (the first account to be made will have full admin rights)
4- Optional: to change the domain from "localhost" to something else and configure the site settings, as well as integrate it with the external services the website uses, edit the variables in the `env` file and then restart the docker container.
------
For returning contributors, we have noticed the following issues (if you can help fix them, we will be very grateful!):
1. Docker doesn't know when we add a new Python dependency, `docker-compose build` is needed.
2. DB schema changes are not applied automatically, the easiest way to deal with that is to delete the entire environment from the Docker GUI and do `docker-compose up`. Also wait five minutes for a "sneed" commit from Aevann meaning that the sql file was regenerated.

View File

@ -5,7 +5,7 @@ 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
command=gunicorn files.__main__:app -k gevent -w 1 --reload -b 0.0.0.0:5000 --max-requests 30000 --max-requests-jitter 10000
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr

View File

@ -1,16 +1,13 @@
# locale-gen "en_US.UTF-8"
# update-locale LANG=en_US.utf8
# update-locale LC_ALL=en_US.utf8
# reboot
cd /rDrama
cp ./env /env
sed -i 's/^/export /g;s/=/="/g;s/$/"/g' /env
. /env
apt -y update
apt -y upgrade
apt -y install git redis-server python3-pip ffmpeg imagemagick tmux nginx snapd ufw gpg-agent htop
git config --global credential.helper store
cd /rDrama
cp ./env /env
sed -i 's/^/export /g;s/=/="/g;s/$/"/g' /env
. /env
mkdir /scripts
cp ./startup.sh /scripts/s