mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
build backend docker image
This commit is contained in:
parent
06a91b02fb
commit
24ea68c605
4
.github/workflows/backend_general.yml
vendored
4
.github/workflows/backend_general.yml
vendored
@ -18,7 +18,7 @@ jobs:
|
||||
POSTGRES_PASSWORD: password
|
||||
POSTGRES_DB: postgres
|
||||
ports:
|
||||
- 5433:5432
|
||||
- 5432:5432
|
||||
env:
|
||||
SQLX_VERSION: 0.5.7
|
||||
SQLX_FEATURES: postgres
|
||||
@ -106,7 +106,7 @@ jobs:
|
||||
POSTGRES_PASSWORD: password
|
||||
POSTGRES_DB: postgres
|
||||
ports:
|
||||
- 5433:5432
|
||||
- 5432:5432
|
||||
env:
|
||||
SQLX_VERSION: 0.5.7
|
||||
SQLX_FEATURES: postgres
|
||||
|
@ -1,26 +1,19 @@
|
||||
ROOT = "./scripts"
|
||||
|
||||
.PHONY: init_database add_migrations run_migrations reset_db
|
||||
.PHONY: init_database run_docker run_test
|
||||
|
||||
init_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 test
|
||||
|
||||
|
||||
|
@ -2,4 +2,5 @@ application:
|
||||
host: 0.0.0.0
|
||||
database:
|
||||
host: "db"
|
||||
port: 5432
|
||||
require_ssl: false
|
||||
|
@ -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=postgres
|
||||
export DB_PASSWORD=password
|
||||
export DB_NAME=flowy
|
||||
export DB_PORT=5433
|
||||
export DB_PORT=5432
|
||||
```
|
||||
|
||||
![img_1.png](img_1.png)
|
||||
|
@ -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-failure
|
||||
environment:
|
||||
- APP_ENVIRONMENT=production
|
||||
- DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db/${POSTGRES_DB}"
|
||||
|
10
backend/scripts/docker_env.sh
Normal file
10
backend/scripts/docker_env.sh
Normal file
@ -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}
|
2
backend/scripts/docker_test.sh
Normal file
2
backend/scripts/docker_test.sh
Normal file
@ -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"}'
|
@ -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}
|
@ -20,7 +20,7 @@ fi
|
||||
|
||||
DB_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}"
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user