Tweaks for old server. Ready for re-deployment

This commit is contained in:
Alexander Laevens
2024-03-03 20:35:39 -07:00
parent caf98b3e84
commit b18f43a48b
8 changed files with 93 additions and 6 deletions

View File

@@ -3,4 +3,5 @@
**/prod_data
**/venv
**/__pycache__
**/db.sqlite3
**/db.sqlite3
**/nginx.conf

View File

@@ -22,7 +22,7 @@ RUN mkdir -p ${DATA_DIR}
WORKDIR ${APP_DIR}
RUN apt-get update
RUN apt-get install --yes --no-install-recommends nano curl
RUN apt-get install --yes --no-install-recommends wget
# Build pip requirements
ADD ./requirements.txt .

View File

@@ -0,0 +1,11 @@
1. sudo useradd --system --shell /bin/bash groceries
2. sudo usermod -aG www-data groceries
3. id -u groceries
4. id -g www-data
5. edit docker-compose.yaml to have correct UID / GID
6. docker compose build
7. sudo mkdir -p /var/www/groceries.alaevens.ca/data
8. sudo cp EXISTING_DB_FILE /var/www/groceries.alaevens.ca/db.sqlite3
9. sudo chown -R groceries /var/www/groceries.alaevens.ca/
10. sudo chgrp -R www-data /var/www/groceries.alaevens.ca/
11. docker compose up -d

View File

@@ -1,12 +1,16 @@
services:
groceries:
container_name: groceries-api
build:
context: .
args:
- UID=999
- UID=992
- GID=33
ports:
- 8001:8080
stdin_open: true
tty: true
restart: always
volumes:
- /var/www/groceries.alaevens.ca/data:/home/groceries/data:rw
- type: bind
@@ -14,7 +18,9 @@ services:
target: /home/groceries/web/db.sqlite3
redis:
container_name: groceries-ws-cache
image: "redis:alpine"
restart: always
ports:
- 6379:6379

View File

@@ -1,5 +1,9 @@
#! /bin/bash
printf "Make migrations:\n"
python3 manage.py makemigrations
printf "\n\nMigrate:\n"
python3 manage.py migrate
printf "\n\nCollect static:\n"
python3 manage.py collectstatic --no-input
printf "\n\nStart ASGI server:\n"
gunicorn one_trip_api.asgi:application -b 0.0.0.0:8080 --access-logfile - -k uvicorn.workers.UvicornWorker

59
one_trip_api/nginx.conf Normal file
View File

@@ -0,0 +1,59 @@
server {
server_name groceries.alaevens.ca;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://container;
}
location /downloads/ {
autoindex on;
alias /var/www/groceries.alaevens.ca/downloads/;
}
location /static/ {
alias /var/www/groceries.alaevens.ca/data/static/;
}
location /media/ {
alias /var/www/groceries.alaevens.ca/data/media/;
}
location /app/ {
alias /var/www/groceries.alaevens.ca/web_app/;
index index.html;
}
listen [::]:443 ssl;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/alaevens.ca/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/alaevens.ca/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = groceries.alaevens.ca) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name groceries.alaevens.ca;
listen [::]:80;
listen 80;
return 404; # managed by Certbot
}
upstream container {
server 127.0.0.1:8001;
}

View File

@@ -28,5 +28,3 @@ urlpatterns = [
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()
print("URLPATTERNS:", urlpatterns)

View File

@@ -1,3 +1,4 @@
anyio==4.3.0
asgiref==3.7.2
async-timeout==4.0.2
certifi==2022.9.24
@@ -13,6 +14,7 @@ djangorestframework==3.14.0
docopt==0.6.2
gunicorn==21.2.0
h11==0.14.0
httptools==0.6.1
idna==3.6
Markdown==3.4.1
msgpack==1.0.4
@@ -20,12 +22,18 @@ packaging==21.3
Pillow==9.3.0
pipreqs==0.4.11
pyparsing==3.0.9
python-dotenv==1.0.1
python-monkey-business==1.0.0
pytz==2022.6
PyYAML==6.0.1
redis==4.3.5
requests==2.28.1
six==1.16.0
sniffio==1.3.1
sqlparse==0.4.3
urllib3==1.26.13
uvicorn==0.27.1
yarg==0.1.9
uvloop==0.19.0
watchfiles==0.21.0
websockets==12.0
yarg==0.1.9