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

Commit 35d54ac

Browse files
committed
Construct unique deployments backend strings,
Use host urls or deployment names. This prevents unique deployments from being loadbalanced when deploying same project. Addresses: exoframejs/exoframe#113
1 parent 8875057 commit 35d54ac

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/docker/start.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// our modules
22
const docker = require('./docker');
33
const {initNetwork} = require('../docker/init');
4-
const {getProjectConfig, baseNameFromImage, nameFromImage, projectFromConfig, writeStatus} = require('../util');
4+
const {getProjectConfig, nameFromImage, projectFromConfig, writeStatus} = require('../util');
55
const {getConfig} = require('../config');
66

77
module.exports = async ({image, username, resultStream}) => {
8-
const baseName = baseNameFromImage(image);
98
const name = nameFromImage(image);
109

1110
// get server config
@@ -41,6 +40,9 @@ module.exports = async ({image, username, resultStream}) => {
4140
}
4241
const additionalLabels = config.labels || {};
4342

43+
// construct backend name from host (if available) or name
44+
const backend = host && host.length ? host : name;
45+
4446
// create config
4547
const containerConfig = {
4648
Image: image,
@@ -50,7 +52,7 @@ module.exports = async ({image, username, resultStream}) => {
5052
'exoframe.deployment': name,
5153
'exoframe.user': username,
5254
'exoframe.project': project,
53-
'traefik.backend': baseName,
55+
'traefik.backend': backend,
5456
}),
5557
HostConfig: {
5658
RestartPolicy,

src/util/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ exports.nameFromImage = image => {
4343
};
4444

4545
exports.projectFromConfig = ({username, config}) => {
46-
const tag = exports.tagFromConfig({username, config});
47-
const baseName = tag.split(':').shift();
46+
const image = exports.tagFromConfig({username, config});
47+
const baseName = exports.baseNameFromImage(image);
4848
return config.project || baseName;
4949
};
5050

test/deploy.test.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,13 @@ test('Should deploy simple docker project', async done => {
7575
// check docker services
7676
const allContainers = await docker.listContainers();
7777
const containerInfo = allContainers.find(c => c.Names.includes(completeDeployments[0].Name));
78-
const deployId = completeDeployments[0].Name.split('-')
79-
.slice(-1)
80-
.shift();
8178
const name = completeDeployments[0].Name.slice(1);
8279

8380
expect(containerInfo).toBeDefined();
8481
expect(containerInfo.Labels['exoframe.deployment']).toEqual(name);
8582
expect(containerInfo.Labels['exoframe.user']).toEqual('admin');
8683
expect(containerInfo.Labels['exoframe.project']).toEqual('test-project');
87-
expect(containerInfo.Labels['traefik.backend']).toEqual(name.replace(`-${deployId}`, ''));
84+
expect(containerInfo.Labels['traefik.backend']).toEqual(`${name}.test`);
8885
expect(containerInfo.NetworkSettings.Networks.exoframe).toBeDefined();
8986

9087
const containerData = docker.getContainer(containerInfo.Id);
@@ -133,7 +130,7 @@ test('Should deploy simple node project', async done => {
133130
expect(container.Labels['exoframe.deployment']).toEqual(name);
134131
expect(container.Labels['exoframe.user']).toEqual('admin');
135132
expect(container.Labels['exoframe.project']).toEqual(name.replace(`-${deployId}`, ''));
136-
expect(container.Labels['traefik.backend']).toEqual(name.replace(`-${deployId}`, ''));
133+
expect(container.Labels['traefik.backend']).toEqual('localhost');
137134
expect(container.Labels['traefik.frontend.rule']).toEqual('Host:localhost');
138135
expect(container.NetworkSettings.Networks.exoframe).toBeDefined();
139136

@@ -177,7 +174,7 @@ test('Should deploy simple HTML project', async done => {
177174
expect(container.Labels['exoframe.deployment']).toEqual(name);
178175
expect(container.Labels['exoframe.user']).toEqual('admin');
179176
expect(container.Labels['exoframe.project']).toEqual('simple-html');
180-
expect(container.Labels['traefik.backend']).toEqual(name.replace(`-${deployId}`, ''));
177+
expect(container.Labels['traefik.backend']).toEqual(name);
181178
expect(container.Labels['traefik.frontend.rule']).toBeUndefined();
182179
expect(container.NetworkSettings.Networks.exoframe).toBeDefined();
183180

@@ -221,7 +218,7 @@ test('Should update simple HTML project', async done => {
221218
expect(container.Labels['exoframe.deployment']).toEqual(name);
222219
expect(container.Labels['exoframe.user']).toEqual('admin');
223220
expect(container.Labels['exoframe.project']).toEqual('simple-html');
224-
expect(container.Labels['traefik.backend']).toEqual(name.replace(`-${deployId}`, ''));
221+
expect(container.Labels['traefik.backend']).toEqual(name);
225222
expect(container.Labels['traefik.frontend.rule']).toBeUndefined();
226223
expect(container.NetworkSettings.Networks.exoframe).toBeDefined();
227224

@@ -498,7 +495,7 @@ test('Should deploy project with configured template', async done => {
498495
expect(container.Labels['exoframe.deployment']).toEqual(name);
499496
expect(container.Labels['exoframe.user']).toEqual('admin');
500497
expect(container.Labels['exoframe.project']).toEqual(name.replace(`-${deployId}`, ''));
501-
expect(container.Labels['traefik.backend']).toEqual(name.replace(`-${deployId}`, ''));
498+
expect(container.Labels['traefik.backend']).toEqual('localhost');
502499
expect(container.Labels['traefik.frontend.rule']).toEqual('Host:localhost');
503500
expect(container.NetworkSettings.Networks.exoframe).toBeDefined();
504501

0 commit comments

Comments
 (0)