-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVarious_Instructions.txt
More file actions
77 lines (58 loc) · 3.24 KB
/
Various_Instructions.txt
File metadata and controls
77 lines (58 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
for offline sqlx (ie db not available)
make sure all queries are available through:
cargo sqlx prepare --workspace -- --all-targets --all-features
for windows to create the postgres db locally:
docker run --name postgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres -N 1000
docker exec -it "postgres" psql -U "postgres" -c "CREATE USER app WITH PASSWORD 'secret';"
docker exec -it "postgres" psql -U "postgres" -c "ALTER USER app CREATEDB;"
set postgres://app:secret@localhost:5432/newsletter
sqlx database create
sqlx migrate run
for windows redis:
docker run -d --name redis_15NOV2024 -p 6379:6379 redis/redis-stack-server:latest
sqlx migrate run
for linux postgres:
# db migration - if already exists run with:
SKIP_DOCKER=true ./scripts/init_db.sh
# else-
# to generate the db enter to terminal:
./scripts/init_db.sh
for linux redis:
./scripts/init_redis.sh
# you may need to do the following - this will stop and remove the old db:
# docker stop NAME
# docker rm name
# to start do docker ps -a to find names of all containers, then
# docker start NAME
# To view the db use pgAdmin4 - install via pip to a python env (it is on testenv)
# launch with
# pgadmin4
# login (tgslocombe@gmail.com, T@mdog12)
# local request
curl GET http://127.0.0.1:8000/health_check
curl -i -X POST http://127.0.0.1:8000/subscriptions -H "Content-Type: application/x-www-form-urlencoded" -d "email=tgslocombe%40outlook.com&name=Tom"
#post a newsletter
curl -i -X POST http://127.0.0.1:8000/newsletters -H 'Content-Type: application/json' -d'{"title":"Newsletter Title","content":{"text":"Newsletter Body","html":"<p>Newsletter Body in html</p>"}}'
Production:
#To generate the app on Digital Ocean:
doctl apps create --spec spec.yaml
# To migrate the production database type this to terminal
# the address is taken from DigitalOcean newsletter connection string:
# note you have to turn off Trusted Sources before running
DATABASE_URL=postgresql://newsletter:AVNS_hmd0HtQEBjbjcs8MNut@app-21936b6a-dd5a-4df1-8fde-bffea1c5c73a-do-user-18089782-0.j.db.ondigitalocean.com:25060/newsletter?sslmode=require sqlx migrate run
# To update the app:
grab your app identifier via doctl apps list --format ID
and then run
doctl apps update $APP_ID --spec spec.yaml
# hosted address
# change app address below
curl -i -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'name=Tom%20Slocombe&email=tgslocombe%40outlook.com' https://zero2prod-wl734.ondigitalocean.app/subscriptions --verbose
Redis for production:
Digital Ocean does not support the creation of a development Redis cluster via the spec.yaml file. You need
to go through their dashboard to create a new Redis cluster. Make sure to select the datacenter where you
deployed the application. Once the cluster has been created, you have to go through a quick “Get started”
flow to configure a few knobs (trusted sources, eviction policy, etc.).
At the end of the “Get started” flow you will be able to copy a connection string to your newly provisioned
Redis instance. The connection string embeds a username and a password, therefore we must treat it as a
secret. We will inject its value into the application using an environment value - set APP_REDIS_URI from the
Settings panel in your application console.