Fun and exciting ways to deploy a standard web app backend
The code is undoubtedly horrible.
The ideas are good tho. Like...
- A/B Testing
- Experiment Groups
- Canary Deployments
- Red/Green Deployments
- Zero-Downtime Deployments
- That sort of thing
Good luck.
(this is kind of a script, but needs to be cleaned up).
Apologies that these only appear in Main - keep this open in an editor since the file will go away when you git checkout
things!
open 4 terminals to the demo repo Open chrome to pgadmin, locust, github, whatever (not everything will be up yet)
git checkout main
docker-compose up -d pgadmin
docker-compose up -d demo-postgres
login to pgadmin: pgadmin@test.com / password Connect pgadmin to host: demo-postgres username: demo
git tag
git checkout v1.0.0
make docker-start
make db-upgrade
./demo/demo/POST\_test.sh
show postgres
show http://localhost:8000/users/
curl -X PATCH -H "Content-Type: application/json" -d '{"name":"Paul Simon", "userid":"1"}' http://localhost:8000/user/
show postgres
show http://localhost:8000/users/
make perftest
browse to locust and see
git checkout v2.0.0
make db-upgrade
Check pgadmin
Check Locust - FAIL FAIL
Clear Lock
Check Locust - all is well
Show what changed in github compare/diff
git checkout v1.0.1
docker-compose up -d demo-api-v101
docker-compose logs -f demo-api
docker-compose logs -f demo-api-v101
git checkout v2.0.0
make db-upgrade
Check pgadmin
Check Locust - FAIL FAIL
Clear Lock in pgAdmin
Check Locust - all is well
docker-compose stop demo-api
These next two commands won't work:
make db-upgrade
docker-compose exec --env FLASK\_APP=demo demo-api flask db upgrade --directory /mnt/migrations
docker-compose up -d demo-api-v2 make db-upgrade
Check pgadmin:
select * from users
where id < 51;
No last names?! OK, no, we haven't rolled out any front end changes. Stop and reload locust (as if we deployed the front-end updates to users):
make perftest
cp nginx/nginx-v2-canary.conf ./nginx.conf
docker-compose logs -f demo-api-v2
docker-compose logs -f demo-api-v101
make reload\_nginx
cp nginx/ngix-v2.conf ./nginx.conf
select * from users
Names don't match first + last names! The Horror!
Compare v2.0.1 in github compare/diff
git checkout v2.0.1
docker-compose up -d demo-api-v201
docker-compose logs -f demo-api-v201
cat nginx.conf
make nginx\_reload
Note that these are useless if ran at the wrong time (that's why they're sneaky here at the end).
Too soon and users just overwrite things with bad data. Too late and users have overwritten things with worse data (in our case).
set name = first || ' ' || last
where name != first || ' ' || last;
update users
set first = split\_part(name, ' ', 1),
last = split\_part(name, ' ', 2)
where first is null;
select *
from users
where
first != split\_part(name, ' ', 1) or
name is null or
first is null;
docker-compose down --remove-orphans