Skip to content
This repository was archived by the owner on Nov 23, 2022. It is now read-only.

Commit 0f7a010

Browse files
committed
Use server volume for traefik config mapping when running in docker
Addresses exoframejs/exoframe#268
1 parent 3a4375f commit 0f7a010

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

src/docker/traefik.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const {pullImage} = require('./util');
1212

1313
// config vars
1414
const baseFolder = path.join(os.homedir(), '.exoframe');
15-
const traefikPath = path.join(baseFolder, 'traefik');
1615

1716
// export traefik init function
1817
exports.initTraefik = async exoNet => {
@@ -28,15 +27,38 @@ exports.initTraefik = async exoNet => {
2827
return;
2928
}
3029

31-
// build traefik path
32-
try {
33-
fs.statSync(traefikPath);
34-
} catch (e) {
35-
mkdirp.sync(traefikPath);
36-
}
30+
// build local traefik path
31+
let traefikPath = path.join(baseFolder, 'traefik');
32+
let initLocal = true;
3733

3834
// get all containers
3935
const allContainers = await docker.listContainers({all: true});
36+
// find server container
37+
const server = allContainers.find(c => c.Names.find(n => n.startsWith('/exoframe-server')));
38+
// if server was found - extract traefik path from it
39+
if (server) {
40+
const serverContainer = docker.getContainer(server.Id);
41+
const serverInfo = await serverContainer.inspect();
42+
const volumes = serverInfo.HostConfig.Binds;
43+
const configVol = (volumes || []).find(v => v.endsWith(':/root/.exoframe'));
44+
if (configVol) {
45+
const configPath = configVol.replace(':/root/.exoframe', '');
46+
traefikPath = path.join(configPath, 'traefik');
47+
logger.info('Running in docker, using existing volume to mount traefik config:', traefikPath);
48+
initLocal = false;
49+
}
50+
}
51+
52+
// if server volume wasn't found - create local folder if needed
53+
if (initLocal) {
54+
try {
55+
fs.statSync(traefikPath);
56+
} catch (e) {
57+
mkdirp.sync(traefikPath);
58+
}
59+
logger.info('Running without docker, using local folder for traefik config:', traefikPath);
60+
}
61+
4062
// try to find traefik instance
4163
const traefik = allContainers.find(c => c.Names.find(n => n.startsWith(`/${config.traefikName}`)));
4264

0 commit comments

Comments
 (0)