Browse Source

First documenting of the new more automated deployment process.

master
Zed A. Shaw 12 months ago
parent
commit
49456038e9
  1. 140
      docs/DEPLOY.md

140
docs/DEPLOY.md

@ -10,141 +10,11 @@ cd /var/vms/learnjsthehardway.org
su deploy
cd ~/learnjsthehardway
## Get the Code
## Deploy Blue Green
git checkout knexfile.js
git checkout lib/models.js
1. Each vm indicates it's state as PROD or STAGING file in the vm directory.
2. In STAGING you run the scripts/shell/instaging.sh file.
3. In PROD you run the scripts/shell/inprod.sh file.
4. Those will tell you when to run the other, and then at the end you go into the /srv/http/etc/nginx drictory on the host server and run: switchbg.sh to change which is production.
./deploy.sh
## Update Settings
This needs to just be automatic but:
1. Set lib/models.js to use production knexfile.js
2. cp prod.knexfile.js knexfile.js
3. Change to prod_transporter from transporter.sendMail
4. copy the new secrets over to lib/secrets.js
# Deploy VM Script
run ```./deploy.sh``` to generate the new app. Fix any problems that come up. Common things are that I forgot to update the secrets.
# Pull The Static Files
```
cd /srv/http/www/learnjsthehardway.com
sh pull.sh
```
# Sync The Raw Media
# PM2 Configuration
Just some quick notes for later installation:
npx pm2 start staging
npx pm2 set pm2-logrotate:compress true
npx pm2 set pm2-logrotate:max_size 10M
npx pm2 set pm2-logrotate:retain 10
# Notes after CI - May 26
This is the documenting of the first manual blue/green switch I had to do.
1. On both stop all queue services.
npx pm2 stop auth # staging
npx pm2 stop auth ci # production
2. On staging, reconfigure to be production and rebuild.
ln -sf ../../ljsthw-private/secrets/production.js secrets.js
# for now. we can optimize this so nothing in here references staging except torrents
rm -rf deployment/production
* The webhook is a problem so definitely need to fix that and have a hook running for both green and
blue but they know what to do.
* Definitely can't use a webhook to do the final deploy has to be from a command line ci run on that
final switch, which means I have to make the ci do both queue and cli styles.
* My fancy code to do production builds really doesn't work since I need to run a full build when
making the first production. I need to have a command line CI build process.
3. Switch the nginx links and point at the new production, staging becomes old production.
ln -sf ../sites-available/learnjsthehardway.com-green learnjsthehardway.com
ln -sf ../sites-available/staging.learnjsthehardway.com-blue staging.learnjsthehardway.com
4. On new production start the queue services.
npx pm2 restart staging.config.js --env production
* The staging.config.js is just wrong, and should be deploy.config.js or ecosystem.config.js and
then in development on my machine I have a dev.config.js.
5. If everything is good, on new staging reconfigure to be staging and pull the latest code to restart.
cd lib
ln -sf ../../ljsthw-private/secrets/staging.js secrets.js
run the CI
# Changes to RR and CI
Now I can exclude rules from a run like this:
./scripts/rr ./scripts/services/ci.js --not_needed=restart,www_push --debug
And the ci script now knows how to figure out the commit information it needs when run from the
command line. This will let me automate the blue/green switch now.
# Round 3 or Something
## 1. In Prod
npx pm2 stop auth ci
## 2. In Staging
npx pm2 stop staging.config.js
ln -sf ../../ljsthw-private/secrets/production.js lib/secrets.js
ln -sf ../../../ljsthw-private/secrets/production_config.js src/node_modules/config.js
rm -rf deployment/production/api/torrents deployment/production/media/torrents
./scripts/rr ./scripts/services/ci.js --debug
npx pm2 reload staging.config.js --env=production
## 3. In Host Nginx
ln -sf ../sites-available/learnjsthehardway.com-green sites-enabled/learnjsthehardway.com
ln -sf ../sites-available/staging.learnjsthehardway.com-blue sites-enabled/staging.learnjsthehardway.com
systemctl reload nginx
## 4. In Old-Prod/New-Staging
In old prod (new staging) do this:
npx pm2 stop staging.config.js
### Now Test New Prod
Login and play a video is the easiest test to run.
## 5. Rebuild Staging
npx pm2 stop staging.config.js
ln -sf ../../ljsthw-private/secrets/staging.js lib/secrets.js
ln -sf ../../../ljsthw-private/secrets/staging_config.js src/node_modules/config.js
rm -rf deployment/production/api/torrents deployment/production/media/torrents
./scripts/rr ./scripts/services/ci.js --debug
npx pm2 reload staging.config.js
# Small CI Changes
One thing that's a little annoying is having to rebuild the app every time I change the blog, but the CI now does it for both prod and staging, but ignores code changes in prod.

Loading…
Cancel
Save