add docker-compose

This commit is contained in:
appflowy 2021-12-01 23:29:16 +08:00
parent 5f064b8118
commit 8f582faffe
6 changed files with 45 additions and 20 deletions

View File

@ -3,9 +3,6 @@ name: Backend
on:
push:
branches: [ main ]
paths:
- 'backend'
- 'shared-lib'
pull_request:
branches: [ main ]
@ -155,5 +152,18 @@ jobs:
- run: cargo clippy -- -D warnings
working-directory: backend/
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- run: rustup component add rustfmt
working-directory: backend/
- run: cargo fmt --all -- --check
working-directory: backend/

View File

@ -1,3 +0,0 @@
include scripts/database/database.mk
.PHONY: init_postgres init_database add_migrations run_migrations reset_db echo_db_url

View File

@ -0,0 +1,18 @@
version: '3'
services:
backend:
build:
context: .
dockerfile: Dockerfile
depends_on:
- db
ports:
- "8000:8000"
db:
image: 'postgres:14'
environment:
POSTGRES_USER: "${POSTGRES_USER}"
POSTGRES_DB: "${POSTGRES_DB}"
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
ports:
- '${DB_PORT}:5432'

View File

@ -1,14 +1,11 @@
#.EXPORT_ALL_VARIABLES:
#export DB_USER=postgres
#export DB_PASSWORD=password
#export DB_NAME=flowy
#export DB_PORT=5433
#export DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}
#export DB_HOST = "localhost"
.PHONY: init_database add_migrations run_migrations reset_db
init_database:
${ROOT}/init_database.sh
run_docker:
source $(shell pwd)/env.sh && docker-compose up -d db && docker-compose up -d backend
reset_db:
#diesel database reset
sqlx database reset
@ -22,6 +19,4 @@ run_migrations:
# diesel migration run
sqlx migrate run
echo_db_url:
echo ${DATABASE_URL}

9
backend/scripts/env.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
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 DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}

View File

@ -18,11 +18,7 @@ if ! [ -x "$(command -v sqlx)" ]; then
exit 1
fi
DB_USER="${POSTGRES_USER:=postgres}"
DB_PASSWORD="${POSTGRES_PASSWORD:=password}"
DB_PORT="${POSTGRES_PORT:=5433}"
DB_HOST="${POSTGRES_HOST:=localhost}"
DB_NAME="${POSTGRES_DB:=flowy}"
source ./env.sh
if [[ -z "${SKIP_DOCKER}" ]]
then