diff --git a/.deploy/nginx.conf b/.deploy/nginx.conf new file mode 100644 index 0000000..97a2391 --- /dev/null +++ b/.deploy/nginx.conf @@ -0,0 +1,26 @@ +server { + client_max_body_size 4M; + + server_name surfcams.pecar.me; + + 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://surfcams; + } + +} + +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + +upstream surfcams { + server unix:///home/anze/projects/surfcams/gunicorn.sock; +} diff --git a/.deploy/run.sh b/.deploy/run.sh new file mode 100644 index 0000000..57e512e --- /dev/null +++ b/.deploy/run.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e +pushd "$(dirname "$0")/.." +uv run gunicorn surfcamsapi.asgi:application +popd diff --git a/.deploy/surfcams.service b/.deploy/surfcams.service new file mode 100644 index 0000000..7dd38e2 --- /dev/null +++ b/.deploy/surfcams.service @@ -0,0 +1,12 @@ +[Unit] +Description=Surfcams +After=nginx.service + +[Service] +Type=simple +Restart=always +RestartSec=1 +ExecStart=/bin/bash /home/anze/projects/surfcams/.deploy/run.sh + +[Install] +WantedBy=multi-user.target diff --git a/.deploy/update.sh b/.deploy/update.sh new file mode 100644 index 0000000..21c2d97 --- /dev/null +++ b/.deploy/update.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e +pushd "$(dirname "$0")/.." +git pull +uv sync --frozen +uv run python manage.py collectstatic --noinput +uv run python manage.py migrate +sudo kill -hup `cat gunicorn.pid` +echo `date "+%Y-%m-%d %H:%M:%S.%3N"` ' Updated' >> update.log +popd diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index e4d9e7c..86e3df6 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -37,5 +37,5 @@ jobs: # key: ${{ secrets.SSH_KEY }} # port: ${{ secrets.SSH_PORT }} # script: | - # bash projects/surfcamsapi/.deploy/update.sh + # bash projects/surfcams/.deploy/update.sh diff --git a/gunicorn.conf.py b/gunicorn.conf.py new file mode 100644 index 0000000..b1bb3d5 --- /dev/null +++ b/gunicorn.conf.py @@ -0,0 +1,6 @@ +bind = "unix:gunicorn.sock" +workers = 1 +threads = 4 +proc_name = "surfcams" +worker_class = "uvicorn.workers.UvicornWorker" +pidfile = "gunicorn.pid"