apt install -y nginx rsync
- Add the
github
user:
adduser --disabled-password --gecos "" --home /home/github github
- Add
github
user to thewww-data
group created bynginx
:
usermod -g www-data github
- Generate a public and private SSH keys, add the public key to the
/home/github/.ssh/authorized_keys
file. - Add a
DEPLOY_KEY
Secret in Github which contains thegithub
user's private key. - Set proper permissions:
chown -R github:www-data /home/github/.ssh
chown -R www-data:www-data /var/www/html
chmod -R 770 /var/www/html
-
Put the
deploy.yml
workflow in the.github/workflows
dir at the root of the project. This Github Action is triggered on every merge to themain
branch. -
Change the
<HOST>
placeholder in theremote_host
key to the address of your server (make sure your firewall rules allow ssh access) -
The
build
job in thedeploy.yml
usesrsync
to upload the contents of thesrc/
dir to the destination server at the specifiedremote_path
(/var/www/html
).