summaryrefslogtreecommitdiffstats
path: root/README.md
blob: aabd58eaf8cd61b866f2890258e6e521100351c5 (plain)
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
78
79
80
81
82
83
84
<div align="center">

# Verden 🌐🎨

</div>

This software is part of a project for the Web Programming course at UNICT.

---

Configuration to set up before starting:

1. Create a PostgreSQL database.
2. Generate a good secret string for JWT.
3. [ Optional ] Create a Sentry project

Variables with values as example:

```
JWT_SECRET=foobar
DATABASE_URL=postgres://user:password@localhost:5432/verden
PAGE_LIMIT=20
SAVE_FILE_BASE_PATH="./uploads"
UPLOADS_ENDPOINT="/uploads"
RUST_LOG=verden=debug,tower_http=debug
ALLOWED_HOST=localhost:3000
SENTRY_DSN=.... # Optional
```

# Deploy

This is a guide for a good deploy on a [Dokku](https://dokku.me) server, which
deploys Verden on port 9090.

Dockerfile defines a `DATABASE_URL` argument by default cause `sqlx` dependence
but, if you define the environment variabile, it will use the one you defined on
`dokku config`.

1. Log into the server and create a new app
   ```
   dokku apps:create verden-api
   ```
2. Create the database and link it to the app. `DATABASE_URL` automatically set
   ```
   dokku postgres:create verden-api # Database has got the same app name
   dokku postgres:link verden-api verden-api
   ```
3. Create a storage where uploads will be located
   ```
   mkdir -p /var/lib/dokku/data/storage/verden-api/uploads/
   dokku storage:mount verden-api /var/lib/dokku/data/storage/verden-api/uploads:/storage/uploads
   ```
4. Set config vars
   ```
   dokku config:set verden-api JWT_SECRET=foobar
   dokku config:set verden-api PAGE_LIMIT=20
   dokku config:set verden-api SAVE_FILE_BASE_PATH=/storage/uploads
   dokku config:set verden-api UPLOADS_ENDPOINT=/uploads
   dokku config:set verden-api RUST_LOG=verden=debug,tower_http=debug
   dokku config:set verdena-pi ALLOWED_HOST=0.0.0.0:9090
   dokku config:set verdena-pi SENTRY_DSN=https://example@example.ingest.sentry.io/42
   ```
5. Fix ports for HTTP
   ```
   dokku proxy:ports-add verden-api http:80:9090
   dokku proxy:ports-remove verden-api http:9090:9090
   ```
6. Add a remote and push this code
   ```
   git remote add dokku dokku_user@your_server:verden-api
   git push dokku main
   ```
7. Install [Let's Encrypt](https://github.com/dokku/dokku-letsencrypt)
   ```
   sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
   dokku config:set --no-restart verden-api DOKKU_LETSENCRYPT_EMAIL=your_email
   dokku letsencrypt:enable verden-api
   ```
8. Log in the app and run migrate
   ```
   dokku enter verden-api
   sqlx migrate run
   ```
9. Enjoy Verden at `https://verden-api.<your-server>`