diff --git a/Dockerfile b/Dockerfile index 6fcc39e63..fe7347a0b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] diff --git a/docker-compose.yml b/docker-compose.yml index b53fb74b3..b54eaee28 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,38 +1,46 @@ 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: + - "./:/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 - 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" + + nginx: + image: nginx + ports: + - "80:80" + volumes: + - ./nginx.txt:/etc/nginx/conf.d/default.conf + - ./nginx-serve-static.txt:/etc/nginx/includes/serve-static diff --git a/files/routes/asset_submissions.py b/files/routes/asset_submissions.py index b4aaf88f0..3476760e8 100644 --- a/files/routes/asset_submissions.py +++ b/files/routes/asset_submissions.py @@ -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/') -@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 4b794b288..5b6535347 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -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/') -@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 160ab3ec9..25618245e 100644 --- a/nginx.txt +++ b/nginx.txt @@ -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/; - } } diff --git a/readme.md b/readme.md index ea0eb010e..8af3b5d69 100644 --- a/readme.md +++ b/readme.md @@ -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. \ No newline at end of file diff --git a/supervisord.conf b/supervisord.conf index 0bde4b3fe..6a98c04d3 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: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 -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..368caa28d 100644 --- a/ubuntu_setup.sh +++ b/ubuntu_setup.sh @@ -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