From e9f0d458350074b6e9869c64e653751bfff06d57 Mon Sep 17 00:00:00 2001 From: n0str Date: Wed, 18 Oct 2023 12:25:54 +0300 Subject: [PATCH 1/3] Add postgres.yml for local run and docs --- DEVELOPMENT.md | 17 +++++++++++------ postgres.yml | 10 ++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 postgres.yml diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index cd8b898c..aafcdef5 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -5,18 +5,23 @@ To run application in development mode you need to run `npm run dev` command. It will start application with `nodemon` and restart it on any changes in source code. -You can try to build and run it in local Docker: +You can try to build and run it in local Docker (see `postgres.yml`): ``` version: "3.2" services: - api: - build: - dockerfile: Dockerfile - context: . + postgres: + image: postgres + environment: + POSTGRES_PASSWORD: pass ports: - - "127.0.0.1:3000:3000" + - 127.0.0.1:5432:5432 + volumes: + - ./database:/var/lib/postgresql/data ``` +To run it execute: `docker compose -f postgres.yml up -d` where `-d` is used for background run. +If you have outdated version of docker, try use `docker-compose` instead of `docker compose` (https://docs.docker.com/compose/) + ## Configuration Default application configuration is stored in `app-config.yaml` file. diff --git a/postgres.yml b/postgres.yml new file mode 100644 index 00000000..318fe372 --- /dev/null +++ b/postgres.yml @@ -0,0 +1,10 @@ +version: "3.2" +services: + postgres: + image: postgres + environment: + POSTGRES_PASSWORD: pass + ports: + - 127.0.0.1:5432:5432 + volumes: + - ./database:/var/lib/postgresql/data \ No newline at end of file From bf2660f0269013b3bb0a1928cb84bbb2c68031a5 Mon Sep 17 00:00:00 2001 From: n0str Date: Wed, 18 Oct 2023 12:33:17 +0300 Subject: [PATCH 2/3] separate docker db setup and docker app build --- DEVELOPMENT.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index aafcdef5..c63e7a81 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -1,11 +1,8 @@ # Development -## Running in development mode +## Setup local database -To run application in development mode you need to run `npm run dev` command. -It will start application with `nodemon` and restart it on any changes in source code. - -You can try to build and run it in local Docker (see `postgres.yml`): +You can install PostgreSQL local https://www.postgresql.org/download/ or use Docker (see `postgres.yml`): ``` version: "3.2" services: @@ -22,6 +19,23 @@ services: To run it execute: `docker compose -f postgres.yml up -d` where `-d` is used for background run. If you have outdated version of docker, try use `docker-compose` instead of `docker compose` (https://docs.docker.com/compose/) +## Running application in development mode + +To run application in development mode you need to run `npm run dev` command. +It will start application with `nodemon` and restart it on any changes in source code. + +You can try to build and run it in local Docker: +``` +version: "3.2" +services: + api: + build: + dockerfile: Dockerfile + context: . + ports: + - "127.0.0.1:3000:3000" +``` + ## Configuration Default application configuration is stored in `app-config.yaml` file. From d9de9656b8bdacc5118ed98c527ef782f3595c6f Mon Sep 17 00:00:00 2001 From: n0str Date: Thu, 19 Oct 2023 23:30:53 +0300 Subject: [PATCH 3/3] impove docs and make app-config docker slave by default --- DEVELOPMENT.md | 18 ++++++++++++++---- app-config.yaml | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index c63e7a81..be4bcb30 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -9,7 +9,7 @@ services: postgres: image: postgres environment: - POSTGRES_PASSWORD: pass + POSTGRES_PASSWORD: example ports: - 127.0.0.1:5432:5432 volumes: @@ -28,18 +28,28 @@ You can try to build and run it in local Docker: ``` version: "3.2" services: - api: + api: build: dockerfile: Dockerfile context: . ports: - "127.0.0.1:3000:3000" + volumes: + - ./app-config.yaml:/usr/app/app-config.yaml + restart: unless-stopped ``` ## Configuration -Default application configuration is stored in `app-config.yaml` file. -To override default configuration you can create `app-config.local.yaml` file and override any configuration value. +Default application configuration is stored in `app-config.yaml` file. This file is intended for docker configuration since it's using `dsn: 'postgres://postgres:example@postgres:5432/codex-notes'`. + +To override default configuration you can create `app-config.local.yaml` file and override any configuration value locally. +You can also override settings in docker by overriding `app-config.local.yaml` via volumes: +``` + volumes: + - ./app-config.yaml:/usr/app/app-config.yaml + - ./app-config.local.yaml:/usr/app/app-config.local.yaml +``` ## Logging diff --git a/app-config.yaml b/app-config.yaml index 3edd88f6..b7ab31f9 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -28,7 +28,7 @@ logging: database: info database: - dsn: 'postgres://postgres:pass@localhost:5432/codex-notes' + dsn: 'postgres://postgres:example@postgres:5432/codex-notes' openai: token: 'token'