feat: add docker compose, use @fennec/configuration.
This commit is contained in:
20
docker/docker-compose.dev.yml
Normal file
20
docker/docker-compose.dev.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
version: "3.9"
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: 'postgres:14'
|
||||
restart: always
|
||||
environment:
|
||||
- POSTGRES_HOST_AUTH_METHOD=trust
|
||||
ports:
|
||||
- '${PG_PORT}:5432'
|
||||
redis:
|
||||
image: 'redis:6'
|
||||
restart: always
|
||||
ports:
|
||||
- '${REDIS_PORT}:6379'
|
||||
|
||||
networks:
|
||||
default:
|
||||
name: 'blog-dev'
|
||||
driver: bridge
|
61
docker/init-dev.mjs
Normal file
61
docker/init-dev.mjs
Normal file
@@ -0,0 +1,61 @@
|
||||
import execa from 'execa';
|
||||
import { URL } from 'url';
|
||||
import { findFreePorts } from 'find-free-ports';
|
||||
import YAML from 'js-yaml';
|
||||
import { readFile, writeFile } from 'fs/promises';
|
||||
|
||||
const [PG_PORT, REDIS_PORT] = await findFreePorts(2);
|
||||
|
||||
await execa(
|
||||
'docker-compose',
|
||||
[
|
||||
'-f',
|
||||
new URL('./docker-compose.dev.yml', import.meta.url).pathname,
|
||||
'up',
|
||||
'-d',
|
||||
],
|
||||
{
|
||||
env: {
|
||||
PG_PORT,
|
||||
REDIS_PORT,
|
||||
},
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
},
|
||||
);
|
||||
|
||||
console.log(`✅ Postgres is running on port ${PG_PORT}`);
|
||||
console.log(`✅ Redis is running on port ${REDIS_PORT}`);
|
||||
|
||||
const config = await YAML.load(
|
||||
await readFile(
|
||||
new URL('../config.yml.example', import.meta.url).pathname,
|
||||
'utf-8',
|
||||
),
|
||||
);
|
||||
config.db.postgres = {
|
||||
host: 'localhost',
|
||||
port: PG_PORT,
|
||||
database: 'postgres',
|
||||
username: 'postgres',
|
||||
password: '',
|
||||
};
|
||||
|
||||
config.db.redis = {
|
||||
host: 'localhost',
|
||||
port: REDIS_PORT,
|
||||
};
|
||||
|
||||
const configOutputPath = new URL('../config.yml', import.meta.url).pathname;
|
||||
|
||||
await writeFile(configOutputPath, YAML.dump(config), 'utf-8');
|
||||
|
||||
console.log(`✅ Config file is written to ${configOutputPath}`);
|
||||
|
||||
await execa.command('npm run typeorm -- migration:run', {
|
||||
cwd: new URL('../', import.meta.url).pathname,
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
console.log(`✅ Database Initiated!`);
|
Reference in New Issue
Block a user