Skip to content

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.

build docker

appflowy6e51173335bc
diff --git a/.dockerignore b/.dockerignore
index 96d83807ed..cfeb9009a9 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,7 +1,5 @@
-.env
-.dockerignore
-doc/
-scripts/
-rust-lib/target/
+frontend/app_flowy/
+frontend/scripts/
+frontend/rust-lib/target
backend/target/
-app_flowy/
\ No newline at end of file
+shared-lib/target/
\ No newline at end of file
diff --git a/backend/.dockerignore b/backend/.dockerignore
index 5ebf0cb3f8..6c23612e00 100644
--- a/backend/.dockerignore
+++ b/backend/.dockerignore
@@ -6,6 +6,4 @@ deploy/
tests/
Dockerfile
scripts/
-migrations/
-app_flowy/
-rust-lib/target/
\ No newline at end of file
+migrations/
\ No newline at end of file
diff --git a/backend/.env.example b/backend/.env.example
deleted file mode 100644
index 8ee6c6b1d5..0000000000
--- a/backend/.env.example
+++ /dev/null
@@ -1 +0,0 @@
-DATABASE_URL="postgres://postgres:password@localhost:5433/flowy"
\ No newline at end of file
diff --git a/backend/Cargo.toml b/backend/Cargo.toml
index 97553b4d24..4c92fa296f 100644
--- a/backend/Cargo.toml
+++ b/backend/Cargo.toml
@@ -97,7 +97,6 @@ parking_lot = "0.11"
once_cell = "1.7.2"
linkify = "0.5.0"
futures-util = "0.3.15"
-
backend = { path = ".", features = ["flowy_test"]}
flowy-sdk = { path = "../frontend/rust-lib/flowy-sdk", features = ["http_server"] }
flowy-user = { path = "../frontend/rust-lib/flowy-user", features = ["http_server"] }
diff --git a/backend/Dockerfile b/backend/Dockerfile
index a068e90649..fbf1b732c4 100644
--- a/backend/Dockerfile
+++ b/backend/Dockerfile
@@ -1,28 +1,11 @@
-FROM lukemathwalker/cargo-chef:latest-rust-1.53.0 as chef
+FROM rust:1.56.1
WORKDIR /app
-
-FROM chef as planner
COPY . .
-RUN cargo chef prepare --recipe-path recipe.json
-FROM chef as builder
-COPY --from=planner /app/recipe.json recipe.json
-# Build dependencies
-RUN cargo chef cook --release --recipe-path recipe.json
-COPY . .
ENV SQLX_OFFLINE true
-# Build our project
-RUN cargo build --release --bin backend
-
-FROM debian:bullseye-slim AS runtime
-WORKDIR /app
-RUN apt-get update -y \
- && apt-get install -y --no-install-recommends openssl \
- # Clean up
- && apt-get autoremove -y \
- && apt-get clean -y \
- && rm -rf /var/lib/apt/lists/*
-COPY --from=builder /app/target/release/backend backend
-COPY configuration configuration
+WORKDIR /app/backend
+RUN RUSTFLAGS="-C opt-level=2" cargo build --release --bin backend
+RUN cp target/release/backend backend
ENV APP_ENVIRONMENT production
-ENTRYPOINT ["./backend"]
+EXPOSE 8000
+ENTRYPOINT ["./backend"]
\ No newline at end of file
diff --git a/backend/scripts/Makefile b/backend/Makefile
similarity index 67%
rename from backend/scripts/Makefile
rename to backend/Makefile
index 02128967ac..aa517d6be0 100644
--- a/backend/scripts/Makefile
+++ b/backend/Makefile
@@ -1,10 +1,14 @@
+ROOT = "./scripts"
+
.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
+ 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
reset_db:
#diesel database reset
diff --git a/backend/configuration/base.example.yaml b/backend/configuration/base.example.yaml
deleted file mode 100644
index 4b78eb1b42..0000000000
--- a/backend/configuration/base.example.yaml
+++ /dev/null
@@ -1,9 +0,0 @@
-application:
- port: 8000
- host: 0.0.0.0
-database:
- host: "localhost"
- port: 5433
- username: "postgres"
- password: "password"
- database_name: "flowy"
diff --git a/backend/configuration/production.yaml b/backend/configuration/production.yaml
index 1de1c6bb54..335ab5d122 100644
--- a/backend/configuration/production.yaml
+++ b/backend/configuration/production.yaml
@@ -1,4 +1,5 @@
application:
host: 0.0.0.0
database:
+ host: "db"
require_ssl: false
diff --git a/backend/docker-compose.yml b/backend/docker-compose.yml
index 0c5c1f64d0..6a267f11d6 100644
--- a/backend/docker-compose.yml
+++ b/backend/docker-compose.yml
@@ -1,20 +1,23 @@
version: '3'
services:
+ db:
+ image: 'postgres:9.6-alpine'
+ environment:
+ - POSTGRES_USER=${POSTGRES_USER}
+ - POSTGRES_DB=${POSTGRES_DB}
+ - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
+# network_mode: "host"
+ ports:
+ - 5433:5432
backend:
- build:
- context: .
- dockerfile: Dockerfile
environment:
- APP_ENVIRONMENT: "production"
+ - APP_ENVIRONMENT=production
+ - DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db/${POSTGRES_DB}"
+ build:
+ context: ../
+ dockerfile: ./backend/Dockerfile
+ image: flowy_backend:${BACKEND_VERSION}
depends_on:
- db
ports:
- 8000:8000
- db:
- image: 'postgres:14'
- environment:
- POSTGRES_USER: "${POSTGRES_USER}"
- POSTGRES_DB: "${POSTGRES_DB}"
- POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
- ports:
- - 5433:5432
\ No newline at end of file
diff --git a/backend/scripts/env.sh b/backend/scripts/env.sh
index 8c9d5db3d3..410ac4358d 100644
--- a/backend/scripts/env.sh
+++ b/backend/scripts/env.sh
@@ -1,9 +1,16 @@
#!/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 file
diff --git a/backend/scripts/init_database.sh b/backend/scripts/init_database.sh
index 3dec69e6f3..47cf26e000 100755
--- a/backend/scripts/init_database.sh
+++ b/backend/scripts/init_database.sh
@@ -18,7 +18,11 @@ if ! [ -x "$(command -v sqlx)" ]; then
exit 1
fi
-source env.sh
+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}"
if [[ -z "${SKIP_DOCKER}" ]]
then
@@ -34,14 +38,15 @@ then
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
-e POSTGRES_DB="${DB_NAME}" \
-p "${DB_PORT}":5432 \
- -d postgres \
- --name "postgres_$(date '+%s')" \
+ -d \
+ --name "flowy_postgres_$(date '+%s')" \
postgres -N 1000
fi
# Keep pinging Postgres until it's ready to accept commands
until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
+
>&2 echo "Postgres is still unavailable - sleeping"
sleep 1
done
diff --git a/backend/src/application.rs b/backend/src/application.rs
index 0c05058935..4f885f3bc7 100644
--- a/backend/src/application.rs
+++ b/backend/src/application.rs
@@ -32,6 +32,7 @@ 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();
diff --git a/backend/src/config/configuration.rs b/backend/src/config/configuration.rs
index 5670045adb..0f7452f4c2 100644
--- a/backend/src/config/configuration.rs
+++ b/backend/src/config/configuration.rs
@@ -2,7 +2,7 @@ use serde_aux::field_attributes::deserialize_number_from_string;
use sqlx::postgres::{PgConnectOptions, PgSslMode};
use std::convert::{TryFrom, TryInto};
-#[derive(serde::Deserialize, Clone)]
+#[derive(serde::Deserialize, Clone, Debug)]
pub struct Settings {
pub database: DatabaseSettings,
pub application: ApplicationSettings,
@@ -16,7 +16,7 @@ pub struct Settings {
// any network interface. So using 127.0.0.1 for our local development and set
// it to 0.0.0.0 in our Docker images.
//
-#[derive(serde::Deserialize, Clone)]
+#[derive(serde::Deserialize, Clone, Debug)]
pub struct ApplicationSettings {
#[serde(deserialize_with = "deserialize_number_from_string")]
pub port: u16,