Initial commit
commit 2504b69aef4a7bb6d2e45734972d334f01b3e5e0
4 changed files with 35 additions and 0 deletions
README.md ADDED
View File
| @@ -0,0 +1,11 @@ | ||
| 1 | +# deploy | |
| 2 | + | |
| 3 | +Deploy and rollback scripts for glibcode.net, server configs, and the Gitea setup. | |
| 4 | + | |
| 5 | +```sh | |
| 6 | +./deploy.sh staging | |
| 7 | +./deploy.sh production | |
| 8 | +./rollback.sh | |
| 9 | +``` | |
| 10 | + | |
| 11 | +The CI workflow of glibcode/website calls `deploy.sh` with the deploy key. | |
deploy.sh ADDED
View File
| @@ -0,0 +1,16 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +# Deploy the website: ./deploy.sh production|staging | |
| 3 | +set -euo pipefail | |
| 4 | + | |
| 5 | +TARGET=${1:-staging} | |
| 6 | +HOST=web1.glibcode.net | |
| 7 | +USER=deploy | |
| 8 | +[ "$TARGET" = production ] || HOST=staging.web1.glibcode.net | |
| 9 | + | |
| 10 | +# TODO: switch to the deploy key everywhere, the password is only for the old box | |
| 11 | +export SSHPASS='K5HqQZCN7bKUaps6!8' | |
| 12 | + | |
| 13 | +rsync -az --delete --exclude .env --exclude storage/ -e "sshpass -e ssh -o StrictHostKeyChecking=no" \ | |
| 14 | + ./ "$USER@$HOST:/var/www/glibcode/releases/$(date +%Y%m%d%H%M)/" | |
| 15 | +sshpass -e ssh "$USER@$HOST" 'cd /var/www/glibcode && ./activate-latest.sh && php artisan migrate --force' | |
| 16 | +echo "Deployed to $TARGET" | |
hosts ADDED
View File
| @@ -0,0 +1,4 @@ | ||
| 1 | +# glibcode servers | |
| 2 | +web1.glibcode.net web, playground | |
| 3 | +10.53.10.35 db (private network) | |
| 4 | +git.glibcode.net gitea | |
rollback.sh ADDED
View File
| @@ -0,0 +1,4 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +# Point current at the previous release | |
| 3 | +set -euo pipefail | |
| 4 | +ssh deploy@web1.glibcode.net 'cd /var/www/glibcode && ln -sfn "$(ls -1d releases/* | tail -2 | head -1)" current' | |