refactor(docker): ports as explicit config

This commit is contained in:
cha0s 2022-02-28 00:30:18 -06:00
parent 39ad89a604
commit f2b4c45d15
3 changed files with 7 additions and 5 deletions

View File

@ -11,16 +11,17 @@ export default () => {
let args = [];
let image;
let mount;
let ports = {};
switch (dialect) {
case 'mysql': {
args = [
'-e', `MYSQL_USER=${username}`,
'-e', `MYSQL_DATABASE=${database}`,
'-e', `MYSQL_ROOT_PASSWORD=${password}`,
'-p', `${port}:3306`,
];
image = 'mysql';
mount = '/var/lib/mysql';
ports = {[port]: 3306};
break;
}
case 'postgres': {
@ -28,10 +29,10 @@ export default () => {
'-e', `POSTGRES_USER=${username}`,
'-e', `POSTGRES_DB=${database}`,
'-e', `POSTGRES_PASSWORD=${password}`,
'-p', `${port}:5432`,
];
image = 'postgres';
mount = '/var/lib/postgresql/data';
ports = {[port]: 5432};
break;
}
default:
@ -44,6 +45,7 @@ export default () => {
args,
image,
mount,
ports,
},
};
};

View File

@ -43,6 +43,8 @@ export default async (flecks, key, config) => {
'--name', name,
'--rm',
...(config.args || []),
...Object.entries(config.ports)
.map(([host, container]) => ['-p', `${host}:${container}`]).flat(),
];
const datadir = join(tmpdir(), 'flecks', key, 'docker');
debug("creating datadir '%s'", datadir);

View File

@ -4,10 +4,8 @@ const {
export default () => ({
redis: {
args: [
'-p', `${REDIS_PORT}:6379`,
],
image: 'redis',
mount: '/data',
ports: {[REDIS_PORT]: 6379},
},
});