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

Commit 7558de1

Browse files
committed
Expose deployment labels using env vars
Addresses exoframejs/exoframe#212
1 parent e99b5ec commit 7558de1

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"start": "node index.js",
99
"test": "NODE_ENV=testing jest --coverage --silent --maxWorkers=2 --ci",
1010
"coveralls": "cat ./coverage/lcov.info | coveralls",
11-
"build-bundle": "ncc build src/index.js -o dist --no-cache",
11+
"build-bundle": "ncc build src/index.js -o dist",
1212
"build": "pkg -t node10.4.1-alpine -o exoframe-server ."
1313
},
1414
"pkg": {

src/docker/start.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ exports.startFromParams = async ({
5353
RestartPolicy.MaximumRetryCount = restartCount;
5454
}
5555

56+
// update env with exoframe variables
57+
const exoEnv = [
58+
`EXOFRAME_DEPLOYMENT=${name}`,
59+
`EXOFRAME_USER=${username}`,
60+
`EXOFRAME_PROJECT=${projectName}`,
61+
`EXOFRAME_HOST=${frontend}`,
62+
];
63+
Env = Env.concat(exoEnv);
64+
5665
// construct backend name from host (if available) or name
5766
const Labels = Object.assign({}, additionalLabels, {
5867
'exoframe.deployment': name,
@@ -164,14 +173,22 @@ exports.start = async ({image, username, folder, resultStream, existing = []}) =
164173
const defaultDomain = baseDomain ? `${name}${baseDomain}` : undefined;
165174
// construct host
166175
const host = config.domain === undefined ? defaultDomain : config.domain;
176+
// generate project name
177+
const project = projectFromConfig({username, config});
167178

168179
// replace env vars values with secrets if needed
169180
const secrets = getSecretsCollection().find({user: username});
170181
// generate env vars (with secrets)
171-
const Env = config.env ? Object.keys(config.env).map(key => `${key}=${valueOrSecret(config.env[key], secrets)}`) : [];
172-
173-
// generate project name
174-
const project = projectFromConfig({username, config});
182+
const userEnv = config.env
183+
? Object.keys(config.env).map(key => `${key}=${valueOrSecret(config.env[key], secrets)}`)
184+
: [];
185+
const exoEnv = [
186+
`EXOFRAME_DEPLOYMENT=${name}`,
187+
`EXOFRAME_USER=${username}`,
188+
`EXOFRAME_PROJECT=${project}`,
189+
`EXOFRAME_HOST=${host}`,
190+
];
191+
const Env = userEnv.concat(exoEnv);
175192

176193
// construct restart policy
177194
let RestartPolicy = {};

test/deploy.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ test('Should deploy simple docker project', async done => {
105105
const container = await containerData.inspect();
106106
expect(container.NetworkSettings.Networks.exoframe.Aliases.includes('test')).toBeTruthy();
107107
expect(container.HostConfig.RestartPolicy).toMatchObject({Name: 'no', MaximumRetryCount: 0});
108+
expect(container.Config.Env).toContain('EXOFRAME_USER=admin');
109+
expect(container.Config.Env).toContain('EXOFRAME_PROJECT=test-project');
110+
expect(
111+
container.Config.Env.find(env => env.startsWith('EXOFRAME_DEPLOYMENT=exo-admin-test-docker-deploy-'))
112+
).toBeDefined();
113+
expect(container.Config.Env.find(env => env.startsWith('EXOFRAME_HOST=exo-admin-test-docker-deploy-'))).toBeDefined();
108114

109115
// cleanup
110116
const instance = docker.getContainer(containerInfo.Id);

0 commit comments

Comments
 (0)