2023-09-14 05:58:13 +03:00
|
|
|
This document explains how to start server (@affine/server) locally with Docker
|
|
|
|
|
2024-05-06 05:03:14 +03:00
|
|
|
> **Warning**:
|
|
|
|
>
|
|
|
|
> This document is not guaranteed to be up-to-date.
|
|
|
|
> If you find any outdated information, please feel free to open an issue or submit a PR.
|
|
|
|
|
2023-09-14 05:58:13 +03:00
|
|
|
## Run postgresql in docker
|
|
|
|
|
|
|
|
```
|
|
|
|
docker pull postgres
|
|
|
|
docker run --rm --name affine-postgres -e POSTGRES_PASSWORD=affine -p 5432:5432 -v ~/Documents/postgres:/var/lib/postgresql/data postgres
|
|
|
|
```
|
|
|
|
|
|
|
|
### Optionally, use a dedicated volume
|
|
|
|
|
|
|
|
```
|
|
|
|
docker volume create affine-postgres
|
|
|
|
docker run --rm --name affine-postgres -e POSTGRES_PASSWORD=affine -p 5432:5432 -v affine-postgres:/var/lib/postgresql/data postgres
|
|
|
|
```
|
|
|
|
|
|
|
|
### mailhog (for local testing)
|
|
|
|
|
|
|
|
```
|
|
|
|
docker run --rm --name mailhog -p 1025:1025 -p 8025:8025 mailhog/mailhog
|
|
|
|
```
|
|
|
|
|
|
|
|
## prepare db
|
|
|
|
|
|
|
|
```
|
|
|
|
docker ps
|
|
|
|
docker exec -it CONTAINER_ID psql -U postgres ## change container_id
|
|
|
|
```
|
|
|
|
|
|
|
|
### in the terminal, following the example to user & table
|
|
|
|
|
|
|
|
```
|
|
|
|
psql (15.3 (Debian 15.3-1.pgdg120+1))
|
|
|
|
Type "help" for help.
|
|
|
|
|
|
|
|
postgres=# CREATE USER affine WITH PASSWORD 'affine';
|
|
|
|
CREATE ROLE
|
|
|
|
postgres=# ALTER USER affine WITH SUPERUSER;
|
|
|
|
ALTER ROLE
|
|
|
|
postgres=# CREATE DATABASE affine;
|
|
|
|
CREATE DATABASE
|
|
|
|
postgres=# \du
|
|
|
|
List of roles
|
|
|
|
Role name | Attributes | Member of
|
|
|
|
-----------+------------------------------------------------------------+-----------
|
|
|
|
affine | Superuser | {}
|
|
|
|
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
|
|
|
|
```
|
|
|
|
|
2023-10-18 18:30:08 +03:00
|
|
|
### Set the following config to `packages/backend/server/.env`
|
2023-09-14 05:58:13 +03:00
|
|
|
|
2024-03-12 12:33:52 +03:00
|
|
|
In the following setup, we assume you have postgres server running at localhost:5432 and mailhog running at localhost:1025.
|
2023-09-14 05:58:13 +03:00
|
|
|
|
2024-03-12 12:33:52 +03:00
|
|
|
When logging in via email, you will see the mail arriving at localhost:8025 in a browser.
|
2023-10-18 09:00:44 +03:00
|
|
|
|
2023-09-14 05:58:13 +03:00
|
|
|
```
|
2024-03-12 12:33:52 +03:00
|
|
|
DATABASE_URL="postgresql://affine:affine@localhost:5432/affine"
|
|
|
|
MAILER_SENDER="noreply@toeverything.info"
|
|
|
|
MAILER_USER="auth"
|
|
|
|
MAILER_PASSWORD="auth"
|
|
|
|
MAILER_HOST="localhost"
|
|
|
|
MAILER_PORT="1025"
|
2023-09-14 05:58:13 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Prepare prisma
|
|
|
|
|
|
|
|
```
|
|
|
|
yarn workspace @affine/server prisma db push
|
2024-03-19 05:05:56 +03:00
|
|
|
yarn workspace @affine/server data-migration run
|
2023-09-14 05:58:13 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
Note, you may need to do it again if db schema changed.
|
|
|
|
|
|
|
|
### Enable prisma studio
|
|
|
|
|
|
|
|
```
|
|
|
|
yarn workspace @affine/server prisma studio
|
|
|
|
```
|
|
|
|
|
|
|
|
## Build native packages (you need to setup rust toolchain first)
|
|
|
|
|
|
|
|
```
|
|
|
|
# build native
|
2024-04-29 05:14:20 +03:00
|
|
|
yarn workspace @affine/server-native build
|
2023-09-14 05:58:13 +03:00
|
|
|
yarn workspace @affine/native build
|
|
|
|
```
|
|
|
|
|
|
|
|
## start server
|
|
|
|
|
|
|
|
```
|
|
|
|
yarn workspace @affine/server dev
|
|
|
|
```
|
|
|
|
|
|
|
|
## start core (web)
|
|
|
|
|
|
|
|
```
|
|
|
|
yarn dev
|
|
|
|
```
|
|
|
|
|
|
|
|
## Done
|
|
|
|
|
|
|
|
Now you should be able to start developing affine with server enabled.
|