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

Commit 2253d50

Browse files
committed
Merge branch 'develop', prepare 3.0.1
2 parents 150e9a7 + ab2826c commit 2253d50

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@
4141
"get-port": "^3.2.0",
4242
"jest": "^22.4.4",
4343
"pkg": "^4.3.1"
44+
},
45+
"jest": {
46+
"testEnvironment": "node"
4447
}
4548
}

src/docker/init.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ exports.pullImage = pullImage;
3434

3535
// join swarm network
3636
const joinSwarmNetwork = async config => {
37+
if (!config.swarm) {
38+
logger.debug('Not running in swarm, no need to join network..');
39+
return;
40+
}
41+
3742
const allServices = await docker.listServices();
3843
// try to find traefik instance
3944
const exoframeServer = allServices.find(c => c.Spec.Name.startsWith('exoframe-server'));

src/docker/start.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ exports.startFromParams = async ({
6464
'exoframe.project': projectName,
6565
'traefik.backend': backend,
6666
'traefik.docker.network': serverConfig.swarm ? serverConfig.exoframeNetworkSwarm : serverConfig.exoframeNetwork,
67+
'traefik.enable': 'true',
6768
});
6869

6970
// if host is set - add it to config
@@ -230,6 +231,8 @@ exports.start = async ({image, username, resultStream, existing = []}) => {
230231
'exoframe.user': username,
231232
'exoframe.project': project,
232233
'traefik.backend': backend,
234+
'traefik.docker.network': serverConfig.swarm ? serverConfig.exoframeNetworkSwarm : serverConfig.exoframeNetwork,
235+
'traefik.enable': 'true',
233236
});
234237

235238
// if host is set - add it to config

src/docker/templates/compose.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const updateCompose = ({username, baseName, serverConfig, composePath, util, res
6767
'traefik.port': '80',
6868
'traefik.backend': backend,
6969
'traefik.docker.network': network,
70+
'traefik.enable': 'true',
7071
};
7172
if (serverConfig.swarm) {
7273
if (!compose.services[svcKey].deploy) {

test/deploy.swarm.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const streamBrokenNode = tar.pack(path.join(__dirname, 'fixtures', 'broken-node-
2929
const streamAdditionalLabels = tar.pack(path.join(__dirname, 'fixtures', 'additional-labels'));
3030
const streamTemplate = tar.pack(path.join(__dirname, 'fixtures', 'template-project'));
3131

32+
// mock config
33+
const mockConfig = config.getConfig();
34+
3235
// options base
3336
const optionsBase = {
3437
method: 'POST',
@@ -101,6 +104,8 @@ test('Should deploy simple docker project to swarm', async done => {
101104
expect(serviceInfo.Spec.Labels['exoframe.user']).toEqual('admin');
102105
expect(serviceInfo.Spec.Labels['exoframe.project']).toEqual('test-project');
103106
expect(serviceInfo.Spec.Labels['traefik.backend']).toEqual(`${name}.test`);
107+
expect(serviceInfo.Spec.Labels['traefik.docker.network']).toEqual(mockConfig.exoframeNetworkSwarm);
108+
expect(serviceInfo.Spec.Labels['traefik.enable']).toEqual('true');
104109
expect(serviceInfo.Spec.Networks.length).toEqual(1);
105110
expect(serviceInfo.Spec.Networks[0].Aliases.includes('test')).toBeTruthy();
106111
expect(serviceInfo.Spec.TaskTemplate.RestartPolicy).toMatchObject({Condition: 'none', MaxAttempts: 1});
@@ -148,6 +153,8 @@ test('Should deploy simple node project to swarm', async done => {
148153
expect(serviceInfo.Spec.Labels['exoframe.user']).toEqual('admin');
149154
expect(serviceInfo.Spec.Labels['exoframe.project']).toEqual(name.replace(`-${deployId}`, ''));
150155
expect(serviceInfo.Spec.Labels['traefik.backend']).toEqual('localhost');
156+
expect(serviceInfo.Spec.Labels['traefik.docker.network']).toEqual(mockConfig.exoframeNetworkSwarm);
157+
expect(serviceInfo.Spec.Labels['traefik.enable']).toEqual('true');
151158
expect(serviceInfo.Spec.Labels['traefik.frontend.rule']).toEqual('Host:localhost');
152159
expect(serviceInfo.Spec.Networks.length).toEqual(1);
153160

@@ -189,6 +196,8 @@ test('Should deploy simple HTML project to swarm', async done => {
189196
expect(serviceInfo.Spec.Labels['exoframe.user']).toEqual('admin');
190197
expect(serviceInfo.Spec.Labels['exoframe.project']).toEqual('simple-html');
191198
expect(serviceInfo.Spec.Labels['traefik.backend']).toEqual(name);
199+
expect(serviceInfo.Spec.Labels['traefik.docker.network']).toEqual(mockConfig.exoframeNetworkSwarm);
200+
expect(serviceInfo.Spec.Labels['traefik.enable']).toEqual('true');
192201
expect(serviceInfo.Spec.Labels['traefik.frontend.rule']).toBeUndefined();
193202
expect(serviceInfo.Spec.Networks.length).toEqual(1);
194203

@@ -228,6 +237,8 @@ test('Should update simple HTML project in swarm', async done => {
228237
expect(serviceInfo.ID).toEqual(simpleHtmlInitialDeploy);
229238
expect(serviceInfo.Spec.Labels['exoframe.user']).toEqual('admin');
230239
expect(serviceInfo.Spec.Labels['exoframe.project']).toEqual('simple-html');
240+
expect(serviceInfo.Spec.Labels['traefik.docker.network']).toEqual(mockConfig.exoframeNetworkSwarm);
241+
expect(serviceInfo.Spec.Labels['traefik.enable']).toEqual('true');
231242
expect(serviceInfo.Spec.Labels['traefik.frontend.rule']).toBeUndefined();
232243
expect(serviceInfo.Spec.Networks.length).toEqual(1);
233244

@@ -278,6 +289,10 @@ test('Should deploy simple compose project to swarm', async done => {
278289
expect(serviceTwo.Spec.Labels['exoframe.project']).toEqual(nameTwo.replace('_redis', ''));
279290
expect(serviceOne.Spec.Labels['traefik.backend']).toEqual(nameOne.replace('_web', '-web'));
280291
expect(serviceTwo.Spec.Labels['traefik.backend']).toEqual(nameTwo.replace('_redis', '-redis'));
292+
expect(serviceOne.Spec.Labels['traefik.docker.network']).toEqual(mockConfig.exoframeNetworkSwarm);
293+
expect(serviceTwo.Spec.Labels['traefik.docker.network']).toEqual(mockConfig.exoframeNetworkSwarm);
294+
expect(serviceOne.Spec.Labels['traefik.enable']).toEqual('true');
295+
expect(serviceTwo.Spec.Labels['traefik.enable']).toEqual('true');
281296
expect(serviceOne.Spec.Labels['traefik.frontend.rule']).toEqual('Host:test.dev');
282297
expect(serviceOne.Spec.TaskTemplate.Networks.length).toEqual(2);
283298
expect(serviceTwo.Spec.TaskTemplate.Networks.length).toEqual(2);
@@ -330,6 +345,10 @@ test('Should update simple compose project in swarm', async done => {
330345
expect(serviceTwo.Spec.Labels['exoframe.project']).toEqual(nameTwo.replace('_redis', ''));
331346
expect(serviceOne.Spec.Labels['traefik.backend']).toEqual(nameOne.replace('_web', '-web'));
332347
expect(serviceTwo.Spec.Labels['traefik.backend']).toEqual(nameTwo.replace('_redis', '-redis'));
348+
expect(serviceOne.Spec.Labels['traefik.docker.network']).toEqual(mockConfig.exoframeNetworkSwarm);
349+
expect(serviceTwo.Spec.Labels['traefik.docker.network']).toEqual(mockConfig.exoframeNetworkSwarm);
350+
expect(serviceOne.Spec.Labels['traefik.enable']).toEqual('true');
351+
expect(serviceTwo.Spec.Labels['traefik.enable']).toEqual('true');
333352
expect(serviceOne.Spec.Labels['traefik.frontend.rule']).toEqual('Host:test.dev');
334353
expect(serviceOne.Spec.TaskTemplate.Networks.length).toEqual(2);
335354
expect(serviceTwo.Spec.TaskTemplate.Networks.length).toEqual(2);
@@ -489,6 +508,8 @@ test('Should deploy project with configured template to swarm', async done => {
489508
expect(serviceInfo.Spec.Labels['exoframe.user']).toEqual('admin');
490509
expect(serviceInfo.Spec.Labels['exoframe.project']).toEqual(name.replace(`-${deployId}`, ''));
491510
expect(serviceInfo.Spec.Labels['traefik.backend']).toEqual('localhost');
511+
expect(serviceInfo.Spec.Labels['traefik.docker.network']).toEqual(mockConfig.exoframeNetworkSwarm);
512+
expect(serviceInfo.Spec.Labels['traefik.enable']).toEqual('true');
492513
expect(serviceInfo.Spec.Labels['traefik.frontend.rule']).toEqual('Host:localhost');
493514
expect(serviceInfo.Spec.Networks.length).toEqual(1);
494515

test/deploy.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ test('Should deploy simple docker project', async done => {
8989
expect(containerInfo.Labels['exoframe.user']).toEqual('admin');
9090
expect(containerInfo.Labels['exoframe.project']).toEqual('test-project');
9191
expect(containerInfo.Labels['traefik.backend']).toEqual(`${name}.test`);
92+
expect(containerInfo.Labels['traefik.docker.network']).toEqual('exoframe');
93+
expect(containerInfo.Labels['traefik.enable']).toEqual('true');
9294
expect(containerInfo.NetworkSettings.Networks.exoframe).toBeDefined();
9395

9496
const containerData = docker.getContainer(containerInfo.Id);
@@ -138,6 +140,8 @@ test('Should deploy simple node project', async done => {
138140
expect(container.Labels['exoframe.user']).toEqual('admin');
139141
expect(container.Labels['exoframe.project']).toEqual(name.replace(`-${deployId}`, ''));
140142
expect(container.Labels['traefik.backend']).toEqual('localhost');
143+
expect(container.Labels['traefik.docker.network']).toEqual('exoframe');
144+
expect(container.Labels['traefik.enable']).toEqual('true');
141145
expect(container.Labels['traefik.frontend.rule']).toEqual('Host:localhost');
142146
expect(container.NetworkSettings.Networks.exoframe).toBeDefined();
143147

@@ -178,6 +182,8 @@ test('Should deploy simple HTML project', async done => {
178182
expect(container.Labels['exoframe.user']).toEqual('admin');
179183
expect(container.Labels['exoframe.project']).toEqual('simple-html');
180184
expect(container.Labels['traefik.backend']).toEqual(name);
185+
expect(container.Labels['traefik.docker.network']).toEqual('exoframe');
186+
expect(container.Labels['traefik.enable']).toEqual('true');
181187
expect(container.Labels['traefik.frontend.rule']).toBeUndefined();
182188
expect(container.NetworkSettings.Networks.exoframe).toBeDefined();
183189

@@ -218,6 +224,8 @@ test('Should update simple HTML project', async done => {
218224
expect(container.Labels['exoframe.user']).toEqual('admin');
219225
expect(container.Labels['exoframe.project']).toEqual('simple-html');
220226
expect(container.Labels['traefik.backend']).toEqual(name);
227+
expect(container.Labels['traefik.docker.network']).toEqual('exoframe');
228+
expect(container.Labels['traefik.enable']).toEqual('true');
221229
expect(container.Labels['traefik.frontend.rule']).toBeUndefined();
222230
expect(container.NetworkSettings.Networks.exoframe).toBeDefined();
223231

@@ -282,6 +290,10 @@ test('Should deploy simple compose project', async done => {
282290
expect(containerTwo.Labels['exoframe.project']).toEqual(nameTwo.replace(`-redis-${deployIdTwo}`, ''));
283291
expect(containerOne.Labels['traefik.backend']).toEqual(nameOne.replace(`-${deployIdOne}`, ''));
284292
expect(containerTwo.Labels['traefik.backend']).toEqual(nameTwo.replace(`-${deployIdTwo}`, ''));
293+
expect(containerOne.Labels['traefik.docker.network']).toEqual('exoframe');
294+
expect(containerTwo.Labels['traefik.docker.network']).toEqual('exoframe');
295+
expect(containerOne.Labels['traefik.enable']).toEqual('true');
296+
expect(containerTwo.Labels['traefik.enable']).toEqual('true');
285297
expect(containerOne.Labels['traefik.frontend.rule']).toEqual('Host:test.dev');
286298
expect(containerOne.NetworkSettings.Networks.exoframe).toBeDefined();
287299
expect(containerTwo.NetworkSettings.Networks.exoframe).toBeDefined();
@@ -340,6 +352,10 @@ test('Should update simple compose project', async done => {
340352
expect(containerTwo.Labels['exoframe.project']).toEqual(nameTwo.replace(`-redis-${deployIdTwo}`, ''));
341353
expect(containerOne.Labels['traefik.backend']).toEqual(nameOne.replace(`-${deployIdOne}`, ''));
342354
expect(containerTwo.Labels['traefik.backend']).toEqual(nameTwo.replace(`-${deployIdTwo}`, ''));
355+
expect(containerOne.Labels['traefik.docker.network']).toEqual('exoframe');
356+
expect(containerTwo.Labels['traefik.docker.network']).toEqual('exoframe');
357+
expect(containerOne.Labels['traefik.enable']).toEqual('true');
358+
expect(containerTwo.Labels['traefik.enable']).toEqual('true');
343359
expect(containerOne.Labels['traefik.frontend.rule']).toEqual('Host:test.dev');
344360
expect(containerOne.NetworkSettings.Networks.exoframe).toBeDefined();
345361
expect(containerTwo.NetworkSettings.Networks.exoframe).toBeDefined();
@@ -495,6 +511,8 @@ test('Should deploy project with configured template', async done => {
495511
expect(container.Labels['exoframe.user']).toEqual('admin');
496512
expect(container.Labels['exoframe.project']).toEqual(name.replace(`-${deployId}`, ''));
497513
expect(container.Labels['traefik.backend']).toEqual('localhost');
514+
expect(container.Labels['traefik.docker.network']).toEqual('exoframe');
515+
expect(container.Labels['traefik.enable']).toEqual('true');
498516
expect(container.Labels['traefik.frontend.rule']).toEqual('Host:localhost');
499517
expect(container.NetworkSettings.Networks.exoframe).toBeDefined();
500518

0 commit comments

Comments
 (0)