@squiz/dxp-cli-next 5.17.0-develop.3 → 5.17.0-develop.5

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.
@@ -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')
@@ -171,25 +172,18 @@ describe('datastoreSimulatorUpgrade', () => {
171
172
  expect(cmd).toStrictEqual('docker exec datastore-sim-6909fc2c cat /var/www/data/containerData.json');
172
173
  return Promise.resolve('{}');
173
174
  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
175
  expect(cmd).toStrictEqual('docker exec datastore-sim-6909fc2c bash -c "rm -rf /var/www/data/storage; rm -rf /var/www/data/provision/**/oven"');
181
176
  return Promise.resolve('');
182
- case 17:
177
+ case 16:
183
178
  expect(cmd).toStrictEqual('docker image inspect squizdxp/datastore:latest --format \'{{ or (index .Config.Labels "squiz.datastore.version") (printf "Unknown") }}\'');
184
179
  return Promise.resolve('4.0.1');
185
- case 18:
180
+ case 17:
186
181
  expect(cmd).toStrictEqual('rm -rf /tmp/datastore-XXXXXXXXXX');
187
182
  return Promise.resolve('');
188
183
  }
189
184
  return Promise.reject(false);
190
185
  });
191
186
  const program = (0, upgrade_1.default)();
192
- const commandErrorSpy = jest.spyOn(program, 'error');
193
187
  yield program.parseAsync([
194
188
  'node',
195
189
  'dxp-cli',
@@ -197,8 +191,9 @@ describe('datastoreSimulatorUpgrade', () => {
197
191
  'simulator',
198
192
  'upgrade',
199
193
  ]);
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
194
  expect(logSpy).toHaveBeenCalledTimes(2);
202
- expect(executeCommandSpy).toHaveBeenCalledTimes(18);
195
+ expect(executeCommandSpy).toHaveBeenCalledTimes(14);
196
+ 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);
197
+ expect(writeSimulatorContainerDataSpy).toHaveBeenCalledWith('datastore-sim-6909fc2c', '/Users/pnolland/Documents/Work/GitRepos/blueprints/boilerplate/api.yaml', '[squizdxp/datastore@sha256:bd61f8f80d9f235d81477454cf512a6edede0ae6d2d0a8c0508956db2418dbe1]', '4.0.1');
203
198
  }));
204
199
  });
@@ -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;
@@ -163,3 +163,39 @@ describe('checkUpdateAvailable', () => {
163
163
  expect(promptSpy).toHaveBeenCalled();
164
164
  }));
165
165
  });
166
+ describe('writeSimulatorContainerData', () => {
167
+ const containerName = 'test-container';
168
+ const blueprintPath = '/path/to/blueprint.yaml';
169
+ const digest = 'sha256:abcdef1234567890';
170
+ const version = '1.0.0';
171
+ it('should write simulator container data correctly', () => __awaiter(void 0, void 0, void 0, function* () {
172
+ const expectedInstallCommandResponse = JSON.stringify([
173
+ {
174
+ URL: 'http://localhost:7001',
175
+ jwtURL: 'http://localhost:7001/jwt',
176
+ },
177
+ ]);
178
+ const execSpy = jest
179
+ .spyOn(utils, 'executeCommand')
180
+ .mockResolvedValue(expectedInstallCommandResponse);
181
+ const expectedResponse = {
182
+ url: 'http://localhost:7001',
183
+ jwtUrl: 'http://localhost:7001/jwt',
184
+ };
185
+ const response = yield utils.writeSimulatorContainerData(containerName, blueprintPath, digest, version);
186
+ expect(execSpy).toHaveBeenNthCalledWith(1, `docker exec -i ${containerName} install simulator:blueprint.yaml --output=json`);
187
+ const jsonObject = {
188
+ blueprint: blueprintPath,
189
+ container: containerName,
190
+ imageDigest: digest,
191
+ imageVersion: version,
192
+ jwt: 'http://localhost:7001/jwt',
193
+ url: 'http://localhost:7001',
194
+ };
195
+ const jsonString = JSON.stringify(jsonObject, null, 4).replace(/"/g, '\\"');
196
+ const expectedEchoCommand = `docker exec -i ${containerName} bash -c "echo '${jsonString}' > /var/www/data/containerData.json"`;
197
+ const actualEchoCommand = execSpy.mock.calls[1][0];
198
+ expect(actualEchoCommand).toBe(expectedEchoCommand);
199
+ expect(response).toStrictEqual(expectedResponse);
200
+ }));
201
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "5.17.0-develop.3",
3
+ "version": "5.17.0-develop.5",
4
4
  "repository": {
5
5
  "url": "https://gitlab.squiz.net/dxp/dxp-cli-next"
6
6
  },