forked from toeverything/AFFiNE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(server): make redis required module (toeverything#9121)
- Loading branch information
Showing
40 changed files
with
284 additions
and
720 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DATABASE_LOCATION=./postgres | ||
DB_PASSWORD=affine | ||
DB_USERNAME=affine | ||
DB_DATABASE_NAME=affine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
postgres | ||
.env | ||
compose.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: affine_dev_services | ||
services: | ||
postgres: | ||
env_file: | ||
- .env | ||
image: postgres:16 | ||
ports: | ||
- 5432:5432 | ||
environment: | ||
POSTGRES_PASSWORD: ${DB_PASSWORD} | ||
POSTGRES_USER: ${DB_USERNAME} | ||
POSTGRES_DB: ${DB_DATABASE_NAME} | ||
volumes: | ||
- ${DATABASE_LOCATION}:/var/lib/postgresql/data | ||
|
||
redis: | ||
image: redis:latest | ||
ports: | ||
- 6379:6379 | ||
|
||
mailhog: | ||
image: mailhog/mailhog:latest | ||
ports: | ||
- 1025:1025 | ||
- 8025:8025 | ||
|
||
networks: | ||
dev: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,109 +5,60 @@ This document explains how to start server (@affine/server) locally with Docker | |
> 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. | ||
## Run postgresql in docker | ||
## Run required dev services in docker compose | ||
|
||
``` | ||
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 | ||
cp ./.docker/dev/compose.yml.example ./.docker/dev/compose.yml | ||
cp ./.docker/dev/.env.example ./.docker/dev/.env | ||
``` | ||
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 | ||
docker compose -f ./.docker/dev/compose.yml up -d | ||
``` | ||
|
||
### mailhog (for local testing) | ||
## Build native packages (you need to setup rust toolchain first) | ||
|
||
``` | ||
docker run --rm --name mailhog -p 1025:1025 -p 8025:8025 mailhog/mailhog | ||
# build native | ||
yarn workspace @affine/server-native build | ||
``` | ||
|
||
## prepare db | ||
## Prepare dev environment | ||
|
||
``` | ||
docker ps | ||
docker exec -it affine-postgres psql -U postgres ## `affine-postgres` is the container name from the previous step | ||
``` | ||
cd packages/backend/server | ||
### 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 | {} | ||
cp .env.example .env | ||
yarn prisma db push | ||
yarn data-migration run | ||
``` | ||
|
||
### Set the following config to `packages/backend/server/.env` | ||
|
||
In the following setup, we assume you have postgres server running at localhost:5432 and mailhog running at localhost:1025. | ||
|
||
When logging in via email, you will see the mail arriving at localhost:8025 in a browser. | ||
## Start server | ||
|
||
``` | ||
DATABASE_URL="postgresql://affine:affine@localhost:5432/affine" | ||
MAILER_SENDER="[email protected]" | ||
MAILER_USER="auth" | ||
MAILER_PASSWORD="auth" | ||
MAILER_HOST="localhost" | ||
MAILER_PORT="1025" | ||
yarn dev | ||
``` | ||
|
||
## Prepare prisma | ||
|
||
``` | ||
yarn workspace @affine/server prisma db push | ||
yarn workspace @affine/server data-migration run | ||
``` | ||
when server started, it will created a default user for testing: | ||
|
||
Note, you may need to do it again if db schema changed. | ||
- email: [email protected] | ||
- name: Dev User | ||
- password: dev | ||
|
||
### Enable prisma studio | ||
## Start frontend | ||
|
||
``` | ||
yarn workspace @affine/server prisma studio | ||
``` | ||
|
||
## Build native packages (you need to setup rust toolchain first) | ||
|
||
``` | ||
# build native | ||
yarn workspace @affine/server-native build | ||
yarn workspace @affine/native build | ||
# at project root | ||
yarn dev | ||
``` | ||
|
||
## start server | ||
|
||
``` | ||
yarn workspace @affine/server dev | ||
``` | ||
## Done | ||
|
||
when server started, it will created a default user: | ||
Now you should be able to start developing affine with server enabled. | ||
|
||
email: [email protected] | ||
name: Dev User | ||
password: dev | ||
## Bonus | ||
|
||
## start core (web) | ||
### Enable prisma studio (Database GUI) | ||
|
||
``` | ||
yarn dev | ||
# available at http://localhost:5555 | ||
yarn prisma studio | ||
``` | ||
|
||
## Done | ||
|
||
Now you should be able to start developing affine with server enabled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
# AFFINE_SERVER_PORT=3010 | ||
# AFFINE_SERVER_HOST=app.affine.pro | ||
# AFFINE_SERVER_HTTPS=true | ||
# DATABASE_URL="postgres://affine:affine@localhost:5432/affine" | ||
# REDIS_SERVER_HOST=localhost | ||
|
||
# MAILER_HOST=localhost | ||
# MAILER_PORT=1025 | ||
# MAILER_SENDER="[email protected]" | ||
# MAILER_USER="[email protected]" | ||
# MAILER_PASSWORD="affine" | ||
# MAILER_SECURE=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.