Infra update
This commit is contained in:
parent
43bf90ebcc
commit
d545318aed
4
.dockerignore
Normal file
4
.dockerignore
Normal file
@ -0,0 +1,4 @@
|
||||
.secrets
|
||||
dev_postgres_data
|
||||
postgres_data
|
||||
config.json
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
config.json
|
||||
.secrets
|
||||
postgres_data
|
||||
dev_postgres_data
|
||||
|
||||
|
15
README.md
15
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": "<your_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": "<your_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,
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -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(
|
||||
|
5
dev.Dockerfile
Normal file
5
dev.Dockerfile
Normal file
@ -0,0 +1,5 @@
|
||||
FROM deno:2.0.3
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENTRYPOINT [ "deno", "run", "--watch=.", "--allow-all", "main.ts" ]
|
38
dev.docker-compose.yml
Normal file
38
dev.docker-compose.yml
Normal file
@ -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
|
@ -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
|
||||
|
@ -15,7 +15,7 @@ export type SetupDbOutput = {
|
||||
db: Kysely<Database>,
|
||||
}
|
||||
export const setupDB = async (cfg: CompiledConfig): Promise<SetupDbOutput> => {
|
||||
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<Database>({ dialect })
|
||||
|
Loading…
Reference in New Issue
Block a user