Skip to content

Commit cc756ed

Browse files
committed
[exoframe-server] Completely remove randomness from deployment ID
1 parent b0c8d1a commit cc756ed

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

packages/exoframe-server/src/docker/start.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
import { getConfig } from '../config/index.js';
33
import { createNetwork, initNetwork } from '../docker/network.js';
44
import logger from '../logger/index.js';
5-
import { getEnv, getHost, getProjectConfig, nameFromImage, projectFromConfig, writeStatus } from '../util/index.js';
5+
import {
6+
baseNameFromImage,
7+
getEnv,
8+
getHost,
9+
getProjectConfig,
10+
nameFromImage,
11+
projectFromConfig,
12+
writeStatus,
13+
} from '../util/index.js';
614
import docker from './docker.js';
715

816
/**
@@ -141,6 +149,7 @@ export async function startFromParams({
141149

142150
export async function start({ image, username, folder, resultStream, existing = [] }) {
143151
const name = nameFromImage(image);
152+
const deploymentName = baseNameFromImage(image);
144153

145154
// get server config
146155
const serverConfig = getConfig();
@@ -155,7 +164,7 @@ export async function start({ image, username, folder, resultStream, existing =
155164
const host = getHost({ serverConfig, name: config.name, config });
156165

157166
// generate env vars
158-
const Env = getEnv({ username, config, name, project, host }).map((pair) => pair.join('='));
167+
const Env = getEnv({ username, config, name: deploymentName, project, host }).map((pair) => pair.join('='));
159168

160169
// construct restart policy
161170
let RestartPolicy = {};
@@ -186,7 +195,7 @@ export async function start({ image, username, folder, resultStream, existing =
186195
.concat(config.middlewares || []);
187196

188197
const Labels = Object.assign({}, additionalLabels, {
189-
'exoframe.deployment': name,
198+
'exoframe.deployment': deploymentName,
190199
'exoframe.user': username,
191200
'exoframe.project': project,
192201
'traefik.docker.network': serverConfig.exoframeNetwork,

packages/exoframe-server/test/deploy.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test('Should deploy simple docker project', async () => {
8585
const name = completeDeployments[0].Name.slice(1);
8686

8787
expect(containerInfo).toBeDefined();
88-
expect(containerInfo.Labels['exoframe.deployment']).toEqual(name);
88+
expect(containerInfo.Labels['exoframe.deployment']).toEqual(name.split('-').slice(0, -1).join('-'));
8989
expect(containerInfo.Labels['exoframe.user']).toEqual('admin');
9090
expect(containerInfo.Labels['exoframe.project']).toEqual('test-project');
9191
expect(containerInfo.Labels['traefik.docker.network']).toEqual('exoframe');
@@ -103,7 +103,7 @@ test('Should deploy simple docker project', async () => {
103103
expect(container.Config.Env).toContain('EXOFRAME_USER=admin');
104104
expect(container.Config.Env).toContain('EXOFRAME_PROJECT=test-project');
105105
expect(
106-
container.Config.Env.find((env) => env.startsWith('EXOFRAME_DEPLOYMENT=exo-admin-test-docker-deploy-'))
106+
container.Config.Env.find((env) => env.startsWith('EXOFRAME_DEPLOYMENT=exo-admin-test-docker-deploy'))
107107
).toBeDefined();
108108
expect(container.Config.Env.find((env) => env.startsWith('EXOFRAME_HOST=test-docker-deploy'))).toBeDefined();
109109

@@ -136,7 +136,7 @@ test('Should deploy simple docker project with custom mount type', async () => {
136136
const name = completeDeployments[0].Name.slice(1);
137137

138138
expect(containerInfo).toBeDefined();
139-
expect(containerInfo.Labels['exoframe.deployment']).toEqual(name);
139+
expect(containerInfo.Labels['exoframe.deployment']).toEqual(name.split('-').slice(0, -1).join('-'));
140140
expect(containerInfo.Labels['exoframe.user']).toEqual('admin');
141141
expect(containerInfo.Labels['exoframe.project']).toEqual('test-mount-project');
142142
expect(containerInfo.Labels['traefik.docker.network']).toEqual('exoframe');
@@ -155,7 +155,7 @@ test('Should deploy simple docker project with custom mount type', async () => {
155155
expect(container.Config.Env).toContain('EXOFRAME_PROJECT=test-mount-project');
156156
expect(
157157
container.Config.Env.find((env) =>
158-
env.startsWith('EXOFRAME_DEPLOYMENT=exo-admin-test-docker-deploy-with-custom-mount-')
158+
env.startsWith('EXOFRAME_DEPLOYMENT=exo-admin-test-docker-deploy-with-custom-mount')
159159
)
160160
).toBeDefined();
161161
expect(
@@ -191,7 +191,7 @@ test('Should deploy simple docker project with buildargs', async () => {
191191
const name = completeDeployments[0].Name.slice(1);
192192

193193
expect(containerInfo).toBeDefined();
194-
expect(containerInfo.Labels['exoframe.deployment']).toEqual(name);
194+
expect(containerInfo.Labels['exoframe.deployment']).toEqual(name.split('-').slice(0, -1).join('-'));
195195
expect(containerInfo.Labels['exoframe.user']).toEqual('admin');
196196
expect(containerInfo.Labels['exoframe.project']).toEqual('test-project-buildargs');
197197
expect(containerInfo.Labels['traefik.docker.network']).toEqual('exoframe');
@@ -233,7 +233,7 @@ test('Should deploy simple project from image and image tar', async () => {
233233
const name = completeDeployments[0].Name.slice(1);
234234

235235
expect(containerInfo).toBeDefined();
236-
expect(containerInfo.Labels['exoframe.deployment']).toEqual(name);
236+
expect(containerInfo.Labels['exoframe.deployment']).toEqual(name.split('-').slice(0, -1).join('-'));
237237
expect(containerInfo.Labels['exoframe.user']).toEqual('admin');
238238
expect(containerInfo.Labels['exoframe.project']).toEqual('test-image-project');
239239
expect(containerInfo.Labels['traefik.docker.network']).toEqual('exoframe');
@@ -274,7 +274,7 @@ test('Should deploy simple project from external image', async () => {
274274
const name = completeDeployments[0].Name.slice(1);
275275

276276
expect(containerInfo).toBeDefined();
277-
expect(containerInfo.Labels['exoframe.deployment']).toEqual(name);
277+
expect(containerInfo.Labels['exoframe.deployment']).toEqual(name.split('-').slice(0, -1).join('-'));
278278
expect(containerInfo.Labels['exoframe.user']).toEqual('admin');
279279
expect(containerInfo.Labels['exoframe.project']).toEqual('test-extimage-project');
280280
expect(containerInfo.Labels['traefik.docker.network']).toEqual('exoframe');
@@ -316,7 +316,7 @@ test('Should deploy simple node project', async () => {
316316
const deployId = name.split('-').slice(-1).shift();
317317

318318
expect(container).toBeDefined();
319-
expect(container.Labels['exoframe.deployment']).toEqual(name);
319+
expect(container.Labels['exoframe.deployment']).toEqual(name.split('-').slice(0, -1).join('-'));
320320
expect(container.Labels['exoframe.user']).toEqual('admin');
321321
expect(container.Labels['exoframe.project']).toEqual(name.replace(`-${deployId}`, ''));
322322
expect(container.Labels['traefik.docker.network']).toEqual('exoframe');
@@ -354,7 +354,7 @@ test('Should deploy simple node project with package-lock', async () => {
354354
const deployId = name.split('-').slice(-1).shift();
355355

356356
expect(container).toBeDefined();
357-
expect(container.Labels['exoframe.deployment']).toEqual(name);
357+
expect(container.Labels['exoframe.deployment']).toEqual(name.split('-').slice(0, -1).join('-'));
358358
expect(container.Labels['exoframe.user']).toEqual('admin');
359359
expect(container.Labels['exoframe.project']).toEqual(name.replace(`-${deployId}`, ''));
360360
expect(container.Labels['traefik.docker.network']).toEqual('exoframe');
@@ -391,7 +391,7 @@ test('Should deploy simple HTML project', async () => {
391391
const container = allContainers.find((c) => c.Names.includes(`/${name}`));
392392

393393
expect(container).toBeDefined();
394-
expect(container.Labels['exoframe.deployment']).toEqual(name);
394+
expect(container.Labels['exoframe.deployment']).toEqual(name.split('-').slice(0, -1).join('-'));
395395
expect(container.Labels['exoframe.user']).toEqual('admin');
396396
expect(container.Labels['exoframe.project']).toEqual('simple-html');
397397
expect(container.Labels['traefik.docker.network']).toEqual('exoframe');
@@ -432,7 +432,7 @@ test('Should update simple HTML project', async () => {
432432
const container = allContainers.find((c) => c.Names.includes(`/${name}`));
433433

434434
expect(container).toBeDefined();
435-
expect(container.Labels['exoframe.deployment']).toEqual(name);
435+
expect(container.Labels['exoframe.deployment']).toEqual(name.split('-').slice(0, -1).join('-'));
436436
expect(container.Labels['exoframe.user']).toEqual('admin');
437437
expect(container.Labels['exoframe.project']).toEqual('simple-html');
438438
expect(container.Labels['traefik.docker.network']).toEqual('exoframe');
@@ -590,7 +590,7 @@ test('Should deploy project with configured template', async () => {
590590
const deployId = name.split('-').slice(-1).shift();
591591

592592
expect(container).toBeDefined();
593-
expect(container.Labels['exoframe.deployment']).toEqual(name);
593+
expect(container.Labels['exoframe.deployment']).toEqual(name.split('-').slice(0, -1).join('-'));
594594
expect(container.Labels['exoframe.user']).toEqual('admin');
595595
expect(container.Labels['exoframe.project']).toEqual(name.replace(`-${deployId}`, ''));
596596
expect(container.Labels['traefik.docker.network']).toEqual('exoframe');

0 commit comments

Comments
 (0)