How-to rcastellotti.dev
19/08/20 :: st_mtime:17/02/2021This post is NOT a tutorial!
-
apt update && apt upgrade
-
apt install nginx python3-venv build-essential libssl-dev libffi-dev python3-certbot-nginx tmux neovim git ranger
-
mkdir -p /var/www/rcastellotti.dev
-
git init --bare rcastellotti.dev
-
touch /root/rcastellotti.dev/hooks/post-receive
#!/bin/bash
# code from https://gist.githubcomnoelboss3fe13927025b89757f8fb12e9066f2fa#file-post-receive
TARGET="/var/www/rcastellotti.dev"
GIT_DIR="/root/rcastellotti.dev"
BRANCH="master"
while read oldrev newrev ref
do
if [ "$ref" = "refs/heads/$BRANCH" ];
then
echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
echo "restarting services"
systemctl restart rcastellotti
systemctl restart nginx
-
chmod +X post-receive
-
dev :
git remote add prod root@rcastellotti.dev:/root/rcastellotti.dev
-
cd /var/www/rcastellotti.dev
-
python3 -m venv venv
-
source venv/bin/activate
-
pip3 install -r requirements.txt
-
test:
gunicorn --bind 0.0.0.0:5000 wsgi:app
-
touch /etc/systemd/system/rcastellotti.service
[Unit]
Description=Gunicorn instance to serve rcastellotti.dev
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/var/www/rcastellotti.dev
Environment="PATH=/var/www/rcastellotti.dev/venv/bin"
ExecStart=/var/www/rcastellotti.dev/venv/bin/gunicorn --workers 3 --bind unix:/tmp/rcastellotti.sock -m 007 wsgi:app
[Install]
WantedBy=multi-user.target
-
systemctl start rcastellotti && systemctl enable rcastellotti
-
test:
systemctl status rcastellotti
-
touch /etc/nginx/sites-available/rcastellotti
server {
root /var/www/;
listen 80;
server_name rcastellotti.dev http2;
gzip on;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
location / {
include proxy_params;
proxy_pass http://unix:/tmp/rcastellotti.sock;
}
location /assets {
autoindex on;
}
}
-
ln -s /etc/nginx/sites-available/rcastellotti /etc/nginx/sites-enabled
-
nginx -t
-
systemctl restart nginx
-
certbot --nginx -d rcastellotti.dev
Extra stuff:
- dev :upload static assets:
rsync -avz <file or folder> root@rcastellotti.dev:/var/www/assets/