@squiz/dxp-cli-next 5.17.0-develop.2 → 5.17.0-develop.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,5 +25,7 @@ Commands:
25
25
  job-runner Job Runner Service Commands
26
26
  datastore Datastore Service Commands
27
27
  cdp Customer Data Platform Service Commands
28
- porter Porter Service Commands
29
28
  ```
29
+
30
+ <!-- TODO: porter command is hidden behind feature flag -->
31
+ <!-- porter Porter Service Commands -->
@@ -9,6 +9,22 @@ describe('dxp', () => {
9
9
  it('should show all available commands', () => {
10
10
  var _a;
11
11
  const { stdout } = (0, helpers_1.runCLI)(process.cwd(), ['--help']);
12
+ const commandsText = (_a = stdout
13
+ .match(/Commands\:(.*)/is)) === null || _a === void 0 ? void 0 : _a[1].split('\n').map(a => a.trim()).filter(a => !!a);
14
+ expect(commandsText).toEqual([
15
+ 'auth Authenticate into the DXP-Next CLI',
16
+ 'cmp Component Service Commands',
17
+ 'job-runner Job Runner Service Commands',
18
+ 'datastore Datastore Service Commands',
19
+ 'cdp Customer Data Platform Service Commands',
20
+ // TODO: Porter is hidden behind feature flag.
21
+ // 'porter Porter Service Commands',
22
+ ]);
23
+ });
24
+ it('if ENABLE_PORTER set to true, porter command should be visible', () => {
25
+ var _a;
26
+ process.env.ENABLE_PORTER = 'true';
27
+ const { stdout } = (0, helpers_1.runCLI)(process.cwd(), ['--help']);
12
28
  const commandsText = (_a = stdout
13
29
  .match(/Commands\:(.*)/is)) === null || _a === void 0 ? void 0 : _a[1].split('\n').map(a => a.trim()).filter(a => !!a);
14
30
  expect(commandsText).toEqual([
@@ -95,10 +95,6 @@ const createAddCommand = () => {
95
95
  }
96
96
  }
97
97
  spinner.text = 'Installing and simulating new blueprint.';
98
- const installCommand = yield (0, utils_2.executeCommand)(`docker exec -i ${containerName} install simulator:${yamlFile} --output=json`);
99
- const obj = JSON.parse(installCommand);
100
- const url = obj[0].URL;
101
- const jwtUrl = obj[0].jwtURL;
102
98
  const versionDetailsCommand = yield (0, utils_2.executeCommand)(`docker image inspect ${utils_2.datastoreRepo} --format "{{ index .RepoDigests }}"`);
103
99
  versionDetails.digest = versionDetailsCommand.replace(/\r?\n|\r/g, '');
104
100
  versionDetails.digest = versionDetails.digest.slice(20, -1);
@@ -107,21 +103,11 @@ const createAddCommand = () => {
107
103
  ' --format \'{{ or (index .Config.Labels "squiz.datastore.version") (printf "Unknown") }}\'';
108
104
  const imageVersion = yield (0, utils_2.executeCommand)(simulatorVersionCmd);
109
105
  versionDetails.version = imageVersion.replace(/\r?\n|\r/g, '');
110
- // Store those info in a file on container, easier to fetch.
111
- const data = {
112
- blueprint: `${fullPath}`,
113
- container: `${containerName}`,
114
- imageDigest: `${versionDetails.digest}`,
115
- imageVersion: `${versionDetails.version}`,
116
- jwt: `${jwtUrl}`,
117
- url: `${url}`,
118
- };
119
- const jsonData = JSON.stringify(data, null, 4).replace(/"/g, '\\"');
120
- yield (0, utils_2.executeCommand)(`docker exec -i ${containerName} bash -c "echo '${jsonData}' > /var/www/data/containerData.json"`);
106
+ const response = yield (0, utils_2.writeSimulatorContainerData)(containerName, fullPath, versionDetails.digest, versionDetails.version);
121
107
  spinner.succeed('Done! Use these details for local querying:');
122
108
  console.log('');
123
- console.log(` URL: ${url}`);
124
- console.log(` JWT URL: ${jwtUrl}`);
109
+ console.log(` URL: ${response.url}`);
110
+ console.log(` JWT URL: ${response.jwtUrl}`);
125
111
  console.log('');
126
112
  return;
127
113
  }
@@ -50,6 +50,14 @@ describe('datastoreSimulatorAdd', () => {
50
50
  .mockImplementation(() => {
51
51
  return Promise.resolve(null);
52
52
  });
53
+ const writeSimulatorContainerDataSpy = jest
54
+ .spyOn(utils, 'writeSimulatorContainerData')
55
+ .mockImplementation((containerName, fullPath, digest, version) => {
56
+ return Promise.resolve({
57
+ url: 'http://0.0.0.0:9999',
58
+ jwtUrl: 'http://0.0.0.0:9999/__JWT/issueToken',
59
+ });
60
+ });
53
61
  let executeCommandCount = 0;
54
62
  const executeCommandSpy = jest
55
63
  .spyOn(utils, 'executeCommand')
@@ -68,29 +76,11 @@ describe('datastoreSimulatorAdd', () => {
68
76
  expect(cmd).toStrictEqual('docker run -l "blueprint=/path/to/blueprint.yaml" -l "port=9999" -itd --name datastore-sim-119726bb -p 0.0.0.0:9999:80 -e MYHOST=0.0.0.0 -e MYPORT=9999 -e BLUEPRINT=/path/to/blueprint.yaml -v "/path/to":/var/www/instances squizdxp/datastore:latest');
69
77
  return Promise.resolve('');
70
78
  case 4:
71
- expect(cmd).toStrictEqual('docker exec -i datastore-sim-119726bb install simulator:blueprint.yaml --output=json');
72
- return Promise.resolve(JSON.stringify([
73
- {
74
- URL: 'http://0.0.0.0:9999',
75
- jwtURL: 'http://0.0.0.0:9999/__JWT/issueToken',
76
- },
77
- ]));
78
- case 5:
79
79
  expect(cmd).toStrictEqual('docker image inspect squizdxp/datastore:latest --format "{{ index .RepoDigests }}"');
80
80
  return Promise.resolve('[squizdxp/datastore@sha256:bd61f8f80d9f235d81477454cf512a6edede0ae6d2d0a8c0508956db2418dbe0]');
81
- case 6:
81
+ case 5:
82
82
  expect(cmd).toStrictEqual('docker image inspect squizdxp/datastore:latest --format \'{{ or (index .Config.Labels "squiz.datastore.version") (printf "Unknown") }}\'');
83
- return Promise.resolve('4.0.1');
84
- case 7:
85
- expect(cmd).toStrictEqual(`docker exec -i datastore-sim-119726bb bash -c "echo '${JSON.stringify({
86
- blueprint: '/path/to/blueprint.yaml',
87
- container: 'datastore-sim-119726bb',
88
- imageDigest: 'sha256:bd61f8f80d9f235d81477454cf512a6edede0ae6d2d0a8c0508956db2418dbe0',
89
- imageVersion: '4.0.1',
90
- jwt: 'http://0.0.0.0:9999/__JWT/issueToken',
91
- url: 'http://0.0.0.0:9999',
92
- }, null, 4).replace(/"/g, '\\"')}' > /var/www/data/containerData.json"`);
93
- return Promise.resolve('');
83
+ return Promise.resolve('4.01');
94
84
  }
95
85
  return Promise.reject(false);
96
86
  });
@@ -119,5 +109,6 @@ describe('datastoreSimulatorAdd', () => {
119
109
  expect(logSpy).toHaveBeenCalledWith(' URL: http://0.0.0.0:9999');
120
110
  expect(logSpy).toHaveBeenCalledWith(' JWT URL: http://0.0.0.0:9999/__JWT/issueToken');
121
111
  expect(logSpy).toHaveBeenCalledWith('');
112
+ expect(writeSimulatorContainerDataSpy).toHaveBeenCalledWith('datastore-sim-119726bb', '/path/to/blueprint.yaml', 'sha256:bd61f8f80d9f235d81477454cf512a6edede0ae6d2d0a8c0508956db2418dbe0', '4.01');
122
113
  }));
123
114
  });
@@ -69,12 +69,7 @@ function upgradeContainer(container, tempFolder, dockerDigest) {
69
69
  yield (0, utils_2.executeCommand)(`docker cp ${tempFolder}/${containerName}/data ${containerName}:/var/www/`);
70
70
  const simulatorVersion = yield (0, utils_2.executeCommand)(`docker image inspect ${utils_2.datastoreRepo} --format '{{ or (index .Config.Labels "squiz.datastore.version") (printf "Unknown") }}'`);
71
71
  const upgradedVersion = simulatorVersion.replace(/\r?\n|\r/g, '');
72
- const containerDataCmd = yield (0, utils_2.executeCommand)(`docker exec ${containerName} cat /var/www/data/containerData.json`);
73
- const containerData = JSON.parse(containerDataCmd);
74
- containerData.imageVersion = upgradedVersion;
75
- containerData.imageDigest = dockerDigest;
76
- const jsonData = JSON.stringify(containerData, null, 4).replace(/"/g, '\\"');
77
- yield (0, utils_2.executeCommand)(`docker exec -i ${containerName} bash -c "echo '${jsonData}' > /var/www/data/containerData.json"`);
72
+ yield (0, utils_2.writeSimulatorContainerData)(containerName, blueprint, dockerDigest, upgradedVersion);
78
73
  }
79
74
  catch (error) {
80
75
  (0, utils_1.logDebug)(`ERROR: ${JSON.stringify(error)}`);
@@ -121,6 +121,7 @@ describe('datastoreSimulatorUpgrade', () => {
121
121
  const forcePromptSpy = jest
122
122
  .spyOn(utils, 'forcePrompt')
123
123
  .mockResolvedValue(true);
124
+ const writeSimulatorContainerDataSpy = jest.spyOn(utils, 'writeSimulatorContainerData');
124
125
  let executeCommandCount = 0;
125
126
  const executeCommandSpy = jest
126
127
  .spyOn(utils, 'executeCommand')
@@ -170,26 +171,10 @@ describe('datastoreSimulatorUpgrade', () => {
170
171
  case 14:
171
172
  expect(cmd).toStrictEqual('docker exec datastore-sim-6909fc2c cat /var/www/data/containerData.json');
172
173
  return Promise.resolve('{}');
173
- case 15:
174
- expect(cmd).toStrictEqual(`docker exec -i datastore-sim-6909fc2c bash -c "echo '{
175
- \\"imageVersion\\": \\"4.0.1\\",
176
- \\"imageDigest\\": \\"[squizdxp/datastore@sha256:bd61f8f80d9f235d81477454cf512a6edede0ae6d2d0a8c0508956db2418dbe1]\\"
177
- }' > /var/www/data/containerData.json"`);
178
- return Promise.resolve('');
179
- case 16:
180
- expect(cmd).toStrictEqual('docker exec datastore-sim-6909fc2c bash -c "rm -rf /var/www/data/storage; rm -rf /var/www/data/provision/**/oven"');
181
- return Promise.resolve('');
182
- case 17:
183
- expect(cmd).toStrictEqual('docker image inspect squizdxp/datastore:latest --format \'{{ or (index .Config.Labels "squiz.datastore.version") (printf "Unknown") }}\'');
184
- return Promise.resolve('4.0.1');
185
- case 18:
186
- expect(cmd).toStrictEqual('rm -rf /tmp/datastore-XXXXXXXXXX');
187
- return Promise.resolve('');
188
174
  }
189
175
  return Promise.reject(false);
190
176
  });
191
177
  const program = (0, upgrade_1.default)();
192
- const commandErrorSpy = jest.spyOn(program, 'error');
193
178
  yield program.parseAsync([
194
179
  'node',
195
180
  'dxp-cli',
@@ -197,8 +182,9 @@ describe('datastoreSimulatorUpgrade', () => {
197
182
  'simulator',
198
183
  'upgrade',
199
184
  ]);
200
- expect(forcePromptSpy).toHaveBeenCalledWith('This will wipe all test data for all of your simulated blueprints. Are you sure you want to continue? (y/N)', false);
201
185
  expect(logSpy).toHaveBeenCalledTimes(2);
202
- expect(executeCommandSpy).toHaveBeenCalledTimes(18);
186
+ expect(executeCommandSpy).toHaveBeenCalledTimes(14);
187
+ expect(forcePromptSpy).toHaveBeenCalledWith('This will wipe all test data for all of your simulated blueprints. Are you sure you want to continue? (y/N)', false);
188
+ expect(writeSimulatorContainerDataSpy).toHaveBeenCalledWith('datastore-sim-6909fc2c', '/Users/pnolland/Documents/Work/GitRepos/blueprints/boilerplate/api.yaml', '[squizdxp/datastore@sha256:bd61f8f80d9f235d81477454cf512a6edede0ae6d2d0a8c0508956db2418dbe1]', '4.0.1');
203
189
  }));
204
190
  });
@@ -4,6 +4,10 @@ declare type datastoreVersionCache = {
4
4
  updatedAt: number;
5
5
  version: string;
6
6
  };
7
+ interface WriteSimulatorContainerDataResponse {
8
+ url: string;
9
+ jwtUrl: string;
10
+ }
7
11
  export declare const datastoreSimulatorCache: FileStore;
8
12
  export declare const datastoreRepo = "squizdxp/datastore:latest";
9
13
  export declare const allowedExtensions: string[];
@@ -21,4 +25,5 @@ export declare function getSimulatorDetails(blueprint: string): {
21
25
  yamlFile: string;
22
26
  containerName: string;
23
27
  };
28
+ export declare const writeSimulatorContainerData: (containerName: string, blueprintPath: string, digest: string, version: string) => Promise<WriteSimulatorContainerDataResponse>;
24
29
  export {};
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.getSimulatorDetails = exports.checkUpdateAvailable = exports.checkDockerInstalled = exports.forcePrompt = exports.promptForContinue = exports.stringHashShort = exports.executeCommand = exports.availablePorts = exports.host = exports.allowedExtensions = exports.datastoreRepo = exports.datastoreSimulatorCache = void 0;
35
+ exports.writeSimulatorContainerData = exports.getSimulatorDetails = exports.checkUpdateAvailable = exports.checkDockerInstalled = exports.forcePrompt = exports.promptForContinue = exports.stringHashShort = exports.executeCommand = exports.availablePorts = exports.host = exports.allowedExtensions = exports.datastoreRepo = exports.datastoreSimulatorCache = void 0;
36
36
  const child_process_1 = require("child_process");
37
37
  const ApplicationStore_1 = require("../../ApplicationStore");
38
38
  const ApiService_1 = require("../../ApiService");
@@ -194,3 +194,23 @@ function getSimulatorDetails(blueprint) {
194
194
  };
195
195
  }
196
196
  exports.getSimulatorDetails = getSimulatorDetails;
197
+ const writeSimulatorContainerData = (containerName, blueprintPath, digest, version) => __awaiter(void 0, void 0, void 0, function* () {
198
+ const yamlFile = (0, path_1.basename)(blueprintPath);
199
+ const installCommand = yield (0, exports.executeCommand)(`docker exec -i ${containerName} install simulator:${yamlFile} --output=json`);
200
+ const obj = JSON.parse(installCommand);
201
+ const url = obj[0].URL;
202
+ const jwtUrl = obj[0].jwtURL;
203
+ // Store those info in a file on container, easier to fetch.
204
+ const data = {
205
+ blueprint: `${blueprintPath}`,
206
+ container: `${containerName}`,
207
+ imageDigest: `${digest}`,
208
+ imageVersion: `${version}`,
209
+ jwt: `${jwtUrl}`,
210
+ url: `${url}`,
211
+ };
212
+ const jsonData = JSON.stringify(data, null, 4).replace(/"/g, '\\"');
213
+ yield (0, exports.executeCommand)(`docker exec -i ${containerName} bash -c "echo '${jsonData}' > /var/www/data/containerData.json"`);
214
+ return { url, jwtUrl };
215
+ });
216
+ exports.writeSimulatorContainerData = writeSimulatorContainerData;
package/lib/dxp.js CHANGED
@@ -28,8 +28,11 @@ program
28
28
  .addCommand(cmp_1.default)
29
29
  .addCommand(job_runner_1.default)
30
30
  .addCommand(datastore_1.default)
31
- .addCommand(cdp_1.default)
32
- .addCommand(porter_1.default)
31
+ .addCommand(cdp_1.default);
32
+ if (process.env.ENABLE_PORTER === 'true') {
33
+ program.addCommand(porter_1.default);
34
+ }
35
+ program
33
36
  .action(() => {
34
37
  program.help();
35
38
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "5.17.0-develop.2",
3
+ "version": "5.17.0-develop.4",
4
4
  "repository": {
5
5
  "url": "https://gitlab.squiz.net/dxp/dxp-cli-next"
6
6
  },