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 FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive ADD .. /service
RUN apt update RUN /service/ubuntu_setup.sh
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
EXPOSE 80/tcp 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

@ -1,38 +1,46 @@
version: '2.3' version: '2.3'
services: services:
files: files:
container_name: "rDrama" container_name: "rDrama"
build: build:
context: . context: .
volumes: volumes:
- "./:/service" - "./:/service"
env_file: env env_file: env
environment: environment:
- DATABASE_URL=postgresql://postgres@postgres:5432 - DATABASE_URL=postgresql://postgres@postgres:5432
- REDIS_URL=redis://redis - REDIS_URL=redis://redis
links: links:
- "redis" - "redis"
- "postgres" - "postgres"
ports: ports:
- "80:80" - "5000:5000"
depends_on: depends_on:
- redis - redis
- postgres - postgres
- nginx
redis: redis:
image: redis image: redis
ports: ports:
- "6379:6379" - "6379:6379"
postgres: postgres:
image: postgres:12.3 image: postgres
command: ["postgres", "-c", "log_statement=all"] command: ["postgres", "-c", "log_statement=all"]
# uncomment this if u wanna output all SQL queries to the console volumes:
volumes: - "./schema.sql:/docker-entrypoint-initdb.d/00-schema.sql"
- "./schema.sql:/docker-entrypoint-initdb.d/00-schema.sql" - "./seed-db.sql:/docker-entrypoint-initdb.d/10-seed-db.sql"
- "./seed-db.sql:/docker-entrypoint-initdb.d/10-seed-db.sql" environment:
environment: - POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_HOST_AUTH_METHOD=trust ports:
ports: - "5432:5432"
- "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.helpers.wrappers import *
from files.routes.static import marsey_list 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") @app.get("/submit/marseys")
@auth_required @auth_required
def submit_marseys(v): def submit_marseys(v):

View File

@ -297,40 +297,6 @@ def static_service(path):
return resp 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") @app.get("/robots.txt")
def robots_txt(): def robots_txt():
return send_file("assets/robots.txt") return send_file("assets/robots.txt")

View File

@ -1,17 +1,15 @@
server { server {
server_name rdrama.net; server_name rdrama.net;
client_max_body_size 100m; client_max_body_size 100m;
listen 443 ssl; listen 80;
listen [::]:443 ssl; listen [::]:80;
ssl_certificate '/rdrama.pem';
ssl_certificate_key '/rdrama.key';
proxy_set_header Host $host;
location / { location / {
proxy_pass http://localhost:5000/; proxy_set_header Host $http_host;
proxy_pass http://rDrama:5000/;
} }
location /socket.io { location /socket.io {
include proxy_params; proxy_set_header Host $http_host;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_buffering off; proxy_buffering off;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
@ -34,9 +32,4 @@ server {
location /asset_submissions/ { location /asset_submissions/ {
include includes/serve-static; 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 cd rDrama
docker-compose down --rmi all --remove-orphans --volumes
docker-compose up 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) 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. 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,8 +5,8 @@ logfile=/tmp/supervisord.log
[program:service] [program:service]
directory=/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=/dev/stdout
stdout_logfile_maxbytes=0 stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0 stderr_logfile_maxbytes=0

View File

@ -1,16 +1,13 @@
# locale-gen "en_US.UTF-8" cd /rDrama
# update-locale LANG=en_US.utf8 cp ./env /env
# update-locale LC_ALL=en_US.utf8 sed -i 's/^/export /g;s/=/="/g;s/$/"/g' /env
# reboot . /env
apt -y update apt -y update
apt -y upgrade 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
git config --global credential.helper store git config --global credential.helper store
cd /rDrama
cp ./env /env
sed -i 's/^/export /g;s/=/="/g;s/$/"/g' /env
. /env
mkdir /scripts mkdir /scripts
cp ./startup.sh /scripts/s cp ./startup.sh /scripts/s