diff --git a/Dockerfile b/Dockerfile index fe7347a0b..6fcc39e63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,44 @@ FROM ubuntu:22.04 -ADD .. /service +ARG DEBIAN_FRONTEND=noninteractive -RUN /service/ubuntu_setup.sh +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 EXPOSE 80/tcp -RUN apt install -y supervisor - -CMD [ "/usr/bin/supervisord", "-c", "/service/supervisord.conf" ] +CMD [ "/usr/bin/supervisord", "-c", "/etc/supervisord.conf" ] diff --git a/docker-compose.yml b/docker-compose.yml index b54eaee28..b53fb74b3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,46 +1,38 @@ 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: - - "5000:5000" - depends_on: - - redis - - postgres - - nginx + 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 - redis: - image: redis - ports: - - "6379:6379" + redis: + image: redis + ports: + - "6379:6379" - 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" - - nginx: - image: nginx - ports: - - "80:80" - volumes: - - ./nginx.txt:/etc/nginx/conf.d/default.conf - - ./nginx-serve-static.txt:/etc/nginx/includes/serve-static + 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 diff --git a/files/routes/asset_submissions.py b/files/routes/asset_submissions.py index 3476760e8..b4aaf88f0 100644 --- a/files/routes/asset_submissions.py +++ b/files/routes/asset_submissions.py @@ -9,6 +9,16 @@ from files.helpers.get import * from files.helpers.wrappers import * from files.routes.static import marsey_list +@app.get('/asset_submissions/') +@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): diff --git a/files/routes/static.py b/files/routes/static.py index 5b6535347..4b794b288 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -297,6 +297,40 @@ 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/') +@app.get('/hostedimages/') +@app.get("/static/images/") +@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/') +@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/') +@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") diff --git a/nginx.txt b/nginx.txt index 25618245e..160ab3ec9 100644 --- a/nginx.txt +++ b/nginx.txt @@ -1,15 +1,17 @@ server { server_name rdrama.net; client_max_body_size 100m; - listen 80; - listen [::]:80; + listen 443 ssl; + listen [::]:443 ssl; + ssl_certificate '/rdrama.pem'; + ssl_certificate_key '/rdrama.key'; + proxy_set_header Host $host; location / { - proxy_set_header Host $http_host; - proxy_pass http://rDrama:5000/; + proxy_pass http://localhost:5000/; } location /socket.io { - proxy_set_header Host $http_host; + include proxy_params; proxy_http_version 1.1; proxy_buffering off; proxy_set_header Upgrade $http_upgrade; @@ -32,4 +34,9 @@ server { location /asset_submissions/ { include includes/serve-static; } + + error_page 502 = /error_page/502.html; + location /error_page/ { + alias /rDrama/files/templates/errors/; + } } diff --git a/readme.md b/readme.md index 8af3b5d69..ea0eb010e 100644 --- a/readme.md +++ b/readme.md @@ -16,11 +16,17 @@ 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. \ No newline at end of file diff --git a/supervisord.conf b/supervisord.conf index 6a98c04d3..0bde4b3fe 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -5,8 +5,8 @@ logfile=/tmp/supervisord.log [program:service] directory=/service -command=gunicorn files.__main__:app -k gevent -w 1 --reload -b 0.0.0.0:5000 --max-requests 30000 --max-requests-jitter 10000 +command=gunicorn files.__main__:app -k gevent -w 1 --reload -b 0.0.0.0:80 --max-requests 30000 --max-requests-jitter 10000 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 +stderr_logfile_maxbytes=0 \ No newline at end of file diff --git a/ubuntu_setup.sh b/ubuntu_setup.sh index 368caa28d..dbbc1f0f2 100644 --- a/ubuntu_setup.sh +++ b/ubuntu_setup.sh @@ -1,13 +1,16 @@ -cd /rDrama -cp ./env /env -sed -i 's/^/export /g;s/=/="/g;s/$/"/g' /env -. /env - +# locale-gen "en_US.UTF-8" +# update-locale LANG=en_US.utf8 +# update-locale LC_ALL=en_US.utf8 +# reboot 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