Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
build backend docker image
appflowy24ea68c60589
diff --git a/.github/workflows/backend_general.yml b/.github/workflows/backend_general.ymlindex 313b3303f1..24fb517111 100644--- a/.github/workflows/backend_general.yml+++ b/.github/workflows/backend_general.yml@@ -18,7 +18,7 @@ jobs:POSTGRES_PASSWORD: passwordPOSTGRES_DB: postgresports:- - 5433:5432+ - 5432:5432env:SQLX_VERSION: 0.5.7SQLX_FEATURES: postgres@@ -106,7 +106,7 @@ jobs:POSTGRES_PASSWORD: passwordPOSTGRES_DB: postgresports:- - 5433:5432+ - 5432:5432env:SQLX_VERSION: 0.5.7SQLX_FEATURES: postgresdiff --git a/backend/Makefile b/backend/Makefileindex aa517d6be0..ca0e154ea1 100644--- a/backend/Makefile+++ b/backend/Makefile@@ -1,26 +1,19 @@ROOT = "./scripts"-.PHONY: init_database add_migrations run_migrations reset_db+.PHONY: init_database run_docker run_testinit_database:- ${ROOT}/init_database.sh+ POSTGRES_PORT=5433 ${ROOT}/init_database.sh-run_docker:- source $(ROOT)/env.sh && docker-compose up -d db- source $(ROOT)/env.sh && docker-compose up -d backend- source $(ROOT)/env.sh && docker-compose logs backend+docker_image:+ source $(ROOT)/docker_env.sh && docker-compose up -d db+ source $(ROOT)/docker_env.sh && docker-compose up -d backend-reset_db:- #diesel database reset- sqlx database reset+docker_test:+ sh $(ROOT)/docker_test.sh-add_migrations:- #make table="the name of your table" add_migrations- # diesel migration generation $(table)- sqlx migrate add $(table)--run_migrations:- # diesel migration run- sqlx migrate run+local_test:+ # 🔥 Must run init_database first+ SQLX_OFFLINE=true cargo testdiff --git a/backend/configuration/production.yaml b/backend/configuration/production.yamlindex 335ab5d122..936886c05e 100644--- a/backend/configuration/production.yaml+++ b/backend/configuration/production.yaml@@ -2,4 +2,5 @@ application:host: 0.0.0.0database:host: "db"+ port: 5432require_ssl: falsediff --git a/backend/doc/database_setup.md b/backend/doc/database_setup.mdindex b04ae1299d..52e21bbc65 100644--- a/backend/doc/database_setup.md+++ b/backend/doc/database_setup.md@@ -9,7 +9,7 @@3. run `make init_postgres` if you have not run before. You can find out the running container by run `docker ps````CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES-bfcdd6369e89 postgres "docker-entrypoint.s…" 19 minutes ago Up 19 minutes 0.0.0.0:5433->5432/tcp, :::5433->5432/tcp brave_bassi+bfcdd6369e89 postgres "docker-entrypoint.s…" 19 minutes ago Up 19 minutes 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp brave_bassi```4. run `make init_database`. It will create the database scheme on remote specified by DATABASE_URL. You can connect you database using@@ -22,7 +22,7 @@ The information you enter must be the same as the `make init_postgres`. e.g.export DB_USER=postgresexport DB_PASSWORD=passwordexport DB_NAME=flowy-export DB_PORT=5433+export DB_PORT=5432```diff --git a/backend/docker-compose.yml b/backend/docker-compose.ymlindex 6a267f11d6..a24d1cdc53 100644--- a/backend/docker-compose.yml+++ b/backend/docker-compose.yml@@ -6,10 +6,10 @@ services:- POSTGRES_USER=${POSTGRES_USER}- POSTGRES_DB=${POSTGRES_DB}- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}-# network_mode: "host"ports:- - 5433:5432+ - "5434:5432"backend:+ restart: on-failureenvironment:- APP_ENVIRONMENT=production- DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db/${POSTGRES_DB}"diff --git a/backend/scripts/docker_env.sh b/backend/scripts/docker_env.shnew file mode 100644index 0000000000..4bd668745e--- /dev/null+++ b/backend/scripts/docker_env.sh@@ -0,0 +1,10 @@+#!/bin/bash+export BACKEND_VERSION="v0.0.1"++export POSTGRES_USER=postgres+export POSTGRES_PASSWORD=password+export POSTGRES_PORT=5432+export POSTGRES_HOST=db+export POSTGRES_DB=flowy++export DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}\ No newline at end of filediff --git a/backend/scripts/docker_test.sh b/backend/scripts/docker_test.shnew file mode 100644index 0000000000..38b23db263--- /dev/null+++ b/backend/scripts/docker_test.sh@@ -0,0 +1,2 @@+#!/bin/bash+curl -i --request Get --url http://0.0.0.0:8000/api/user --header 'content-type: application/json' --data '{"token":"123"}'\ No newline at end of filediff --git a/backend/scripts/env.sh b/backend/scripts/env.shdeleted file mode 100644index 410ac4358d..0000000000--- a/backend/scripts/env.sh+++ /dev/null@@ -1,16 +0,0 @@-#!/bin/bash--export POSTGRES_USER=postgres-export POSTGRES_PASSWORD=password-export POSTGRES_PORT=5433-export POSTGRES_HOST=localhost-export POSTGRES_DB=flowy--export DB_USER="${POSTGRES_USER:=postgres}"-export DB_PASSWORD="${POSTGRES_PASSWORD:=password}"-export DB_PORT="${POSTGRES_PORT:=5433}"-export DB_HOST="${POSTGRES_HOST:=localhost}"-export DB_NAME="${POSTGRES_DB:=flowy}"--export BACKEND_VERSION="v0.0.1"-export DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}\ No newline at end of filediff --git a/backend/scripts/init_database.sh b/backend/scripts/init_database.shindex 47cf26e000..95c5c421f2 100755--- a/backend/scripts/init_database.sh+++ b/backend/scripts/init_database.sh@@ -20,7 +20,7 @@ fiDB_USER="${POSTGRES_USER:=postgres}"DB_PASSWORD="${POSTGRES_PASSWORD:=password}"-DB_PORT="${POSTGRES_PORT:=5433}"+DB_PORT="${POSTGRES_PORT:=5432}"DB_HOST="${POSTGRES_HOST:=localhost}"DB_NAME="${POSTGRES_DB:=flowy}"diff --git a/backend/src/application.rs b/backend/src/application.rsindex 4f885f3bc7..0c05058935 100644--- a/backend/src/application.rs+++ b/backend/src/application.rs@@ -32,7 +32,6 @@ pub struct Application {impl Application {pub async fn build(configuration: Settings, app_ctx: AppContext) -> Result<Self, std::io::Error> {- println!("🚀🚀🚀 {:?}", configuration);let address = format!("{}:{}", configuration.application.host, configuration.application.port);let listener = TcpListener::bind(&address)?;let port = listener.local_addr().unwrap().port();