diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e321c86 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.secrets +dev_postgres_data +postgres_data +config.json diff --git a/.gitignore b/.gitignore index ed3964a..114e832 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ config.json .secrets -postgres_data \ No newline at end of file +postgres_data +dev_postgres_data + diff --git a/README.md b/README.md index 847d4ff..3077f6b 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,23 @@ and it will find images for you. Before running **MIC** create file `./config.json` that contains ```json { + // BOT_TOKEN env variable has more priority + // that the config value + "bot_token": "" // to run in Docker set the value to // "/run/secrets/db_password" // If wasn't set -- POSTGRES_PASSWORD env // variable will be used instead "db_password_file": "~/.secrets/mic", - // BOT_TOKEN env variable has more priority - // that the config value - "bot_token": "" + // other optional db config parameters + + // Defaults can be seen/changed inside the config.ts file + "db_user": string, + "db_name": string, + "db_port": number, + // if you are running under docker -- set host to postgres + "db_host": string, + "db_tls": boolean, } ``` @@ -78,4 +87,4 @@ deno compile -o ./bin/mic ./main.ts deno run ./main.ts # Dev run with autorestart deno run ./main.ts -``` \ No newline at end of file +``` diff --git a/cfg/config.ts b/cfg/config.ts index 88559b0..e0d4363 100644 --- a/cfg/config.ts +++ b/cfg/config.ts @@ -89,6 +89,9 @@ export const getConfig = (): Config => { const decoder = new TextDecoder("utf-8") const data = Deno.readFileSync(fileCfg.db_password_file) db_password = decoder.decode(data).toString() + if (db_password[db_password.length - 1] === '\n') { + db_password = db_password.slice(0, -1) + } } else if (envCfg.db_password) { db_password = envCfg.db_password } else throw new BadConfigErr( @@ -119,4 +122,4 @@ export const getConfig = (): Config => { bot_token, } -} \ No newline at end of file +} diff --git a/dev.Dockerfile b/dev.Dockerfile new file mode 100644 index 0000000..16dda47 --- /dev/null +++ b/dev.Dockerfile @@ -0,0 +1,5 @@ +FROM deno:2.0.3 + +WORKDIR /app + +ENTRYPOINT [ "deno", "run", "--watch=.", "--allow-all", "main.ts" ] diff --git a/dev.docker-compose.yml b/dev.docker-compose.yml new file mode 100644 index 0000000..b9db1c1 --- /dev/null +++ b/dev.docker-compose.yml @@ -0,0 +1,38 @@ +secrets: + db_password: + file: .secrets/db_password.txt + +networks: + mic_bot_dev: + driver: bridge + +services: + bot: + build: . + container_name: mic_bot_dev + restart: always + depends_on: + - postgres + environment: + - MIC_APPLY_MIGRATIONS=y + networks: + - mic_bot_dev + secrets: + - db_password + volumes: + - ./:/app + postgres: + container_name: mic_bot_postgres_dev + image: postgres:latest + restart: always + volumes: + - ./dev_postgres_data:/var/lib/postgresql/data:rw + environment: + POSTGRES_USER: mic + POSTGRES_DB: mic + POSTGRES_PASSWORD_FILE: /run/secrets/db_password + user: "${USER_ID:-1000}:${GID:-1000}" + networks: + - mic_bot_dev + secrets: + - db_password diff --git a/docker-compose.yml b/docker-compose.yml index 34a0021..ec6846e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,6 +19,8 @@ services: - mic_bot secrets: - db_password + volumes: + - ./config.json:/app/config.json postgres: container_name: mic_bot_postgres image: postgres:latest @@ -33,4 +35,4 @@ services: networks: - mic_bot secrets: - - db_password \ No newline at end of file + - db_password diff --git a/repo/setup_db.ts b/repo/setup_db.ts index 66ae2af..7cb236d 100644 --- a/repo/setup_db.ts +++ b/repo/setup_db.ts @@ -15,7 +15,7 @@ export type SetupDbOutput = { db: Kysely, } export const setupDB = async (cfg: CompiledConfig): Promise => { - console.log("creating db instance") + console.log("creating db instance: ", cfg.pgPoolCfg) const pool = new pg.Pool(cfg.pgPoolCfg) const dialect = new PostgresDialect({ pool }) const db = new Kysely({ dialect }) @@ -60,4 +60,4 @@ export const setupDB = async (cfg: CompiledConfig): Promise => { } return { pool, db } -} \ No newline at end of file +}