Skip to content

Commit

Permalink
fix(upload-charm): Use resource revision from upload-resource command (
Browse files Browse the repository at this point in the history
…#147)

Use resource revision number returned by upload-resource command when
uploading a charm with resources. This replaces the previous behaviour
when the action was listing resources and was using the latest
available.

Closes #139
Ref canonical/bundle-kubeflow#962
  • Loading branch information
orfeas-k authored Jul 10, 2024
1 parent e924d25 commit 46fe0c6
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 78 deletions.
29 changes: 21 additions & 8 deletions dist/channel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42758,13 +42758,24 @@ class Charmcraft {
.filter(([name]) => !overrides || !Object.keys(overrides).includes(name))
.map(([name, image]) => __awaiter(this, void 0, void 0, function* () {
if (this.uploadImage) {
yield this.uploadResource(image, charmName, name);
const { exitCode, stdout, stderr } = yield this.uploadResource(image, charmName, name);
if (exitCode !== 0) {
throw new Error(`Could not upload resource with error ${stderr}`);
}
const { revision } = JSON.parse(stdout);
const flag = `--resource=${name}:${revision}`;
const info = ` - ${name}: ${image}\n` +
` resource-revision: ${revision}\n`;
flags.push(flag);
resourceInfo += info;
}
else {
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
}
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
})));
return { flags, resourceInfo };
});
Expand Down Expand Up @@ -42806,13 +42817,15 @@ class Charmcraft {
const resourceDigest = yield (0, docker_1.getImageDigest)(resource_image);
const args = [
'upload-resource',
'--quiet',
'--format',
'json',
name,
resource_name,
'--image',
resourceDigest,
];
yield (0, exec_1.exec)('charmcraft', args, this.execOptions);
const execOutput = yield (0, exec_1.getExecOutput)('charmcraft', args, this.execOptions);
return execOutput;
});
}
buildResourceFlag(charmName, name, image) {
Expand Down
29 changes: 21 additions & 8 deletions dist/check-libraries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42953,13 +42953,24 @@ class Charmcraft {
.filter(([name]) => !overrides || !Object.keys(overrides).includes(name))
.map(([name, image]) => __awaiter(this, void 0, void 0, function* () {
if (this.uploadImage) {
yield this.uploadResource(image, charmName, name);
const { exitCode, stdout, stderr } = yield this.uploadResource(image, charmName, name);
if (exitCode !== 0) {
throw new Error(`Could not upload resource with error ${stderr}`);
}
const { revision } = JSON.parse(stdout);
const flag = `--resource=${name}:${revision}`;
const info = ` - ${name}: ${image}\n` +
` resource-revision: ${revision}\n`;
flags.push(flag);
resourceInfo += info;
}
else {
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
}
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
})));
return { flags, resourceInfo };
});
Expand Down Expand Up @@ -43001,13 +43012,15 @@ class Charmcraft {
const resourceDigest = yield (0, docker_1.getImageDigest)(resource_image);
const args = [
'upload-resource',
'--quiet',
'--format',
'json',
name,
resource_name,
'--image',
resourceDigest,
];
yield (0, exec_1.exec)('charmcraft', args, this.execOptions);
const execOutput = yield (0, exec_1.getExecOutput)('charmcraft', args, this.execOptions);
return execOutput;
});
}
buildResourceFlag(charmName, name, image) {
Expand Down
29 changes: 21 additions & 8 deletions dist/promote-charm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42837,13 +42837,24 @@ class Charmcraft {
.filter(([name]) => !overrides || !Object.keys(overrides).includes(name))
.map(([name, image]) => __awaiter(this, void 0, void 0, function* () {
if (this.uploadImage) {
yield this.uploadResource(image, charmName, name);
const { exitCode, stdout, stderr } = yield this.uploadResource(image, charmName, name);
if (exitCode !== 0) {
throw new Error(`Could not upload resource with error ${stderr}`);
}
const { revision } = JSON.parse(stdout);
const flag = `--resource=${name}:${revision}`;
const info = ` - ${name}: ${image}\n` +
` resource-revision: ${revision}\n`;
flags.push(flag);
resourceInfo += info;
}
else {
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
}
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
})));
return { flags, resourceInfo };
});
Expand Down Expand Up @@ -42885,13 +42896,15 @@ class Charmcraft {
const resourceDigest = yield (0, docker_1.getImageDigest)(resource_image);
const args = [
'upload-resource',
'--quiet',
'--format',
'json',
name,
resource_name,
'--image',
resourceDigest,
];
yield (0, exec_1.exec)('charmcraft', args, this.execOptions);
const execOutput = yield (0, exec_1.getExecOutput)('charmcraft', args, this.execOptions);
return execOutput;
});
}
buildResourceFlag(charmName, name, image) {
Expand Down
29 changes: 21 additions & 8 deletions dist/release-charm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42849,13 +42849,24 @@ class Charmcraft {
.filter(([name]) => !overrides || !Object.keys(overrides).includes(name))
.map(([name, image]) => __awaiter(this, void 0, void 0, function* () {
if (this.uploadImage) {
yield this.uploadResource(image, charmName, name);
const { exitCode, stdout, stderr } = yield this.uploadResource(image, charmName, name);
if (exitCode !== 0) {
throw new Error(`Could not upload resource with error ${stderr}`);
}
const { revision } = JSON.parse(stdout);
const flag = `--resource=${name}:${revision}`;
const info = ` - ${name}: ${image}\n` +
` resource-revision: ${revision}\n`;
flags.push(flag);
resourceInfo += info;
}
else {
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
}
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
})));
return { flags, resourceInfo };
});
Expand Down Expand Up @@ -42897,13 +42908,15 @@ class Charmcraft {
const resourceDigest = yield (0, docker_1.getImageDigest)(resource_image);
const args = [
'upload-resource',
'--quiet',
'--format',
'json',
name,
resource_name,
'--image',
resourceDigest,
];
yield (0, exec_1.exec)('charmcraft', args, this.execOptions);
const execOutput = yield (0, exec_1.getExecOutput)('charmcraft', args, this.execOptions);
return execOutput;
});
}
buildResourceFlag(charmName, name, image) {
Expand Down
29 changes: 21 additions & 8 deletions dist/release-libraries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42980,13 +42980,24 @@ class Charmcraft {
.filter(([name]) => !overrides || !Object.keys(overrides).includes(name))
.map(([name, image]) => __awaiter(this, void 0, void 0, function* () {
if (this.uploadImage) {
yield this.uploadResource(image, charmName, name);
const { exitCode, stdout, stderr } = yield this.uploadResource(image, charmName, name);
if (exitCode !== 0) {
throw new Error(`Could not upload resource with error ${stderr}`);
}
const { revision } = JSON.parse(stdout);
const flag = `--resource=${name}:${revision}`;
const info = ` - ${name}: ${image}\n` +
` resource-revision: ${revision}\n`;
flags.push(flag);
resourceInfo += info;
}
else {
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
}
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
})));
return { flags, resourceInfo };
});
Expand Down Expand Up @@ -43028,13 +43039,15 @@ class Charmcraft {
const resourceDigest = yield (0, docker_1.getImageDigest)(resource_image);
const args = [
'upload-resource',
'--quiet',
'--format',
'json',
name,
resource_name,
'--image',
resourceDigest,
];
yield (0, exec_1.exec)('charmcraft', args, this.execOptions);
const execOutput = yield (0, exec_1.getExecOutput)('charmcraft', args, this.execOptions);
return execOutput;
});
}
buildResourceFlag(charmName, name, image) {
Expand Down
29 changes: 21 additions & 8 deletions dist/upload-bundle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42828,13 +42828,24 @@ class Charmcraft {
.filter(([name]) => !overrides || !Object.keys(overrides).includes(name))
.map(([name, image]) => __awaiter(this, void 0, void 0, function* () {
if (this.uploadImage) {
yield this.uploadResource(image, charmName, name);
const { exitCode, stdout, stderr } = yield this.uploadResource(image, charmName, name);
if (exitCode !== 0) {
throw new Error(`Could not upload resource with error ${stderr}`);
}
const { revision } = JSON.parse(stdout);
const flag = `--resource=${name}:${revision}`;
const info = ` - ${name}: ${image}\n` +
` resource-revision: ${revision}\n`;
flags.push(flag);
resourceInfo += info;
}
else {
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
}
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
})));
return { flags, resourceInfo };
});
Expand Down Expand Up @@ -42876,13 +42887,15 @@ class Charmcraft {
const resourceDigest = yield (0, docker_1.getImageDigest)(resource_image);
const args = [
'upload-resource',
'--quiet',
'--format',
'json',
name,
resource_name,
'--image',
resourceDigest,
];
yield (0, exec_1.exec)('charmcraft', args, this.execOptions);
const execOutput = yield (0, exec_1.getExecOutput)('charmcraft', args, this.execOptions);
return execOutput;
});
}
buildResourceFlag(charmName, name, image) {
Expand Down
29 changes: 21 additions & 8 deletions dist/upload-charm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42868,13 +42868,24 @@ class Charmcraft {
.filter(([name]) => !overrides || !Object.keys(overrides).includes(name))
.map(([name, image]) => __awaiter(this, void 0, void 0, function* () {
if (this.uploadImage) {
yield this.uploadResource(image, charmName, name);
const { exitCode, stdout, stderr } = yield this.uploadResource(image, charmName, name);
if (exitCode !== 0) {
throw new Error(`Could not upload resource with error ${stderr}`);
}
const { revision } = JSON.parse(stdout);
const flag = `--resource=${name}:${revision}`;
const info = ` - ${name}: ${image}\n` +
` resource-revision: ${revision}\n`;
flags.push(flag);
resourceInfo += info;
}
else {
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
}
const resourceFlag = yield this.buildResourceFlag(charmName, name, image);
if (!resourceFlag)
return;
flags.push(resourceFlag.flag);
resourceInfo += resourceFlag.info;
})));
return { flags, resourceInfo };
});
Expand Down Expand Up @@ -42916,13 +42927,15 @@ class Charmcraft {
const resourceDigest = yield (0, docker_1.getImageDigest)(resource_image);
const args = [
'upload-resource',
'--quiet',
'--format',
'json',
name,
resource_name,
'--image',
resourceDigest,
];
yield (0, exec_1.exec)('charmcraft', args, this.execOptions);
const execOutput = yield (0, exec_1.getExecOutput)('charmcraft', args, this.execOptions);
return execOutput;
});
}
buildResourceFlag(charmName, name, image) {
Expand Down
16 changes: 9 additions & 7 deletions src/services/charmcraft/charmcraft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,15 @@ describe('the charmcraft service', () => {
const digest = `somedigest`;
const charmcraft = new Charmcraft('token', true);

const mockedExec = jest.spyOn(exec, 'exec').mockResolvedValue(0);

jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
exitCode: 0,
stderr: '',
stdout: digest,
});
jest.spyOn(exec, 'exec').mockResolvedValue(0);

const mockedExec = jest
.spyOn(exec, 'getExecOutput')
.mockResolvedValue({
exitCode: 0,
stderr: '',
stdout: digest,
});

await charmcraft.uploadResource(
'placeholder-image',
Expand Down
Loading

0 comments on commit 46fe0c6

Please sign in to comment.