mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
build docker
This commit is contained in:
parent
b17a3f50db
commit
6e51173335
@ -1,7 +1,5 @@
|
|||||||
.env
|
frontend/app_flowy/
|
||||||
.dockerignore
|
frontend/scripts/
|
||||||
doc/
|
frontend/rust-lib/target
|
||||||
scripts/
|
|
||||||
rust-lib/target/
|
|
||||||
backend/target/
|
backend/target/
|
||||||
app_flowy/
|
shared-lib/target/
|
@ -6,6 +6,4 @@ deploy/
|
|||||||
tests/
|
tests/
|
||||||
Dockerfile
|
Dockerfile
|
||||||
scripts/
|
scripts/
|
||||||
migrations/
|
migrations/
|
||||||
app_flowy/
|
|
||||||
rust-lib/target/
|
|
@ -1 +0,0 @@
|
|||||||
DATABASE_URL="postgres://postgres:password@localhost:5433/flowy"
|
|
@ -97,7 +97,6 @@ parking_lot = "0.11"
|
|||||||
once_cell = "1.7.2"
|
once_cell = "1.7.2"
|
||||||
linkify = "0.5.0"
|
linkify = "0.5.0"
|
||||||
futures-util = "0.3.15"
|
futures-util = "0.3.15"
|
||||||
|
|
||||||
backend = { path = ".", features = ["flowy_test"]}
|
backend = { path = ".", features = ["flowy_test"]}
|
||||||
flowy-sdk = { path = "../frontend/rust-lib/flowy-sdk", features = ["http_server"] }
|
flowy-sdk = { path = "../frontend/rust-lib/flowy-sdk", features = ["http_server"] }
|
||||||
flowy-user = { path = "../frontend/rust-lib/flowy-user", features = ["http_server"] }
|
flowy-user = { path = "../frontend/rust-lib/flowy-user", features = ["http_server"] }
|
||||||
|
@ -1,28 +1,11 @@
|
|||||||
FROM lukemathwalker/cargo-chef:latest-rust-1.53.0 as chef
|
FROM rust:1.56.1
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
FROM chef as planner
|
|
||||||
COPY . .
|
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
|
ENV SQLX_OFFLINE true
|
||||||
# Build our project
|
WORKDIR /app/backend
|
||||||
RUN cargo build --release --bin backend
|
RUN RUSTFLAGS="-C opt-level=2" cargo build --release --bin backend
|
||||||
|
RUN cp target/release/backend 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
|
|
||||||
ENV APP_ENVIRONMENT production
|
ENV APP_ENVIRONMENT production
|
||||||
ENTRYPOINT ["./backend"]
|
EXPOSE 8000
|
||||||
|
ENTRYPOINT ["./backend"]
|
@ -1,10 +1,14 @@
|
|||||||
|
ROOT = "./scripts"
|
||||||
|
|
||||||
.PHONY: init_database add_migrations run_migrations reset_db
|
.PHONY: init_database add_migrations run_migrations reset_db
|
||||||
|
|
||||||
init_database:
|
init_database:
|
||||||
${ROOT}/init_database.sh
|
${ROOT}/init_database.sh
|
||||||
|
|
||||||
run_docker:
|
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:
|
reset_db:
|
||||||
#diesel database reset
|
#diesel database reset
|
@ -1,9 +0,0 @@
|
|||||||
application:
|
|
||||||
port: 8000
|
|
||||||
host: 0.0.0.0
|
|
||||||
database:
|
|
||||||
host: "localhost"
|
|
||||||
port: 5433
|
|
||||||
username: "postgres"
|
|
||||||
password: "password"
|
|
||||||
database_name: "flowy"
|
|
@ -1,4 +1,5 @@
|
|||||||
application:
|
application:
|
||||||
host: 0.0.0.0
|
host: 0.0.0.0
|
||||||
database:
|
database:
|
||||||
|
host: "db"
|
||||||
require_ssl: false
|
require_ssl: false
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
backend:
|
db:
|
||||||
build:
|
image: 'postgres:9.6-alpine'
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
environment:
|
environment:
|
||||||
APP_ENVIRONMENT: "production"
|
- POSTGRES_USER=${POSTGRES_USER}
|
||||||
|
- POSTGRES_DB=${POSTGRES_DB}
|
||||||
|
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||||
|
# network_mode: "host"
|
||||||
|
ports:
|
||||||
|
- 5433:5432
|
||||||
|
backend:
|
||||||
|
environment:
|
||||||
|
- 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:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
ports:
|
ports:
|
||||||
- 8000:8000
|
- 8000:8000
|
||||||
db:
|
|
||||||
image: 'postgres:14'
|
|
||||||
environment:
|
|
||||||
POSTGRES_USER: "${POSTGRES_USER}"
|
|
||||||
POSTGRES_DB: "${POSTGRES_DB}"
|
|
||||||
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
|
|
||||||
ports:
|
|
||||||
- 5433:5432
|
|
@ -1,9 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/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_USER="${POSTGRES_USER:=postgres}"
|
||||||
export DB_PASSWORD="${POSTGRES_PASSWORD:=password}"
|
export DB_PASSWORD="${POSTGRES_PASSWORD:=password}"
|
||||||
export DB_PORT="${POSTGRES_PORT:=5433}"
|
export DB_PORT="${POSTGRES_PORT:=5433}"
|
||||||
export DB_HOST="${POSTGRES_HOST:=localhost}"
|
export DB_HOST="${POSTGRES_HOST:=localhost}"
|
||||||
export DB_NAME="${POSTGRES_DB:=flowy}"
|
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}
|
export DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}
|
@ -18,7 +18,11 @@ if ! [ -x "$(command -v sqlx)" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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}" ]]
|
if [[ -z "${SKIP_DOCKER}" ]]
|
||||||
then
|
then
|
||||||
@ -34,14 +38,15 @@ then
|
|||||||
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
|
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
|
||||||
-e POSTGRES_DB="${DB_NAME}" \
|
-e POSTGRES_DB="${DB_NAME}" \
|
||||||
-p "${DB_PORT}":5432 \
|
-p "${DB_PORT}":5432 \
|
||||||
-d postgres \
|
-d \
|
||||||
--name "postgres_$(date '+%s')" \
|
--name "flowy_postgres_$(date '+%s')" \
|
||||||
postgres -N 1000
|
postgres -N 1000
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Keep pinging Postgres until it's ready to accept commands
|
# 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
|
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"
|
>&2 echo "Postgres is still unavailable - sleeping"
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
@ -32,6 +32,7 @@ pub struct Application {
|
|||||||
|
|
||||||
impl Application {
|
impl Application {
|
||||||
pub async fn build(configuration: Settings, app_ctx: AppContext) -> Result<Self, std::io::Error> {
|
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 address = format!("{}:{}", configuration.application.host, configuration.application.port);
|
||||||
let listener = TcpListener::bind(&address)?;
|
let listener = TcpListener::bind(&address)?;
|
||||||
let port = listener.local_addr().unwrap().port();
|
let port = listener.local_addr().unwrap().port();
|
||||||
|
@ -2,7 +2,7 @@ use serde_aux::field_attributes::deserialize_number_from_string;
|
|||||||
use sqlx::postgres::{PgConnectOptions, PgSslMode};
|
use sqlx::postgres::{PgConnectOptions, PgSslMode};
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Clone)]
|
#[derive(serde::Deserialize, Clone, Debug)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub database: DatabaseSettings,
|
pub database: DatabaseSettings,
|
||||||
pub application: ApplicationSettings,
|
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
|
// 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.
|
// it to 0.0.0.0 in our Docker images.
|
||||||
//
|
//
|
||||||
#[derive(serde::Deserialize, Clone)]
|
#[derive(serde::Deserialize, Clone, Debug)]
|
||||||
pub struct ApplicationSettings {
|
pub struct ApplicationSettings {
|
||||||
#[serde(deserialize_with = "deserialize_number_from_string")]
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user