Skip to content

Commit 81ebe3c

Browse files
container-update-image: Support image_digest
1 parent 04f370a commit 81ebe3c

5 files changed

Lines changed: 51 additions & 14 deletions

File tree

.changeset/orange-roses-smash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"container-update-image": minor
3+
---
4+
5+
Support image_digest

container-update-image/.lib-action/index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24962,6 +24962,7 @@ function run() {
2496224962
const appId = core.getInput("app_id", { required: true });
2496324963
const containerName = core.getInput("container", { required: true });
2496424964
const imageTag = core.getInput("image_tag", { required: true });
24965+
const imageDigest = core.getInput("image_digest");
2496524966
try {
2496624967
const appConfig = yield getAppConfiguration(apiKey, appId);
2496724968
const containers = appConfig.containerTemplates.filter(v => v.name === containerName);
@@ -24972,8 +24973,13 @@ function run() {
2497224973
throw new Error(`Found more than one container named "${containerName}".`);
2497324974
}
2497424975
const containerId = containers[0].id;
24975-
console.log(`Updating container "${containerName}" (${containerId}) with tag "${imageTag}"`);
24976-
patchAppContainer(apiKey, appId, containerId, imageTag);
24976+
if (imageDigest === '') {
24977+
console.log(`Updating container "${containerName}" (${containerId}) with tag "${imageTag}"`);
24978+
}
24979+
else {
24980+
console.log(`Updating container "${containerName}" (${containerId}) with tag "${imageTag}", digest "${imageDigest}"`);
24981+
}
24982+
patchAppContainer(apiKey, appId, containerId, imageTag, imageDigest);
2497724983
}
2497824984
catch (e) {
2497924985
if (typeof e === 'string' || e instanceof Error) {
@@ -25020,19 +25026,23 @@ function getAppConfiguration(apiKey, appId) {
2502025026
});
2502125027
});
2502225028
}
25023-
function patchAppContainer(apiKey, appId, containerId, imageTag) {
25029+
function patchAppContainer(apiKey, appId, containerId, imageTag, imageDigest) {
2502425030
return __awaiter(this, void 0, void 0, function* () {
25031+
const body = {
25032+
id: containerId,
25033+
imageTag: imageTag,
25034+
};
25035+
if (imageDigest !== undefined && imageDigest.length > 0) {
25036+
body.imageDigest = imageDigest;
25037+
}
2502525038
return new Promise((resolve, reject) => {
2502625039
fetch(`https://api.bunny.net/mc/apps/${appId}/containers/${containerId}`, {
2502725040
method: 'PATCH',
2502825041
headers: {
2502925042
'Content-Type': 'application/json',
2503025043
'AccessKey': apiKey,
2503125044
},
25032-
body: JSON.stringify({
25033-
id: containerId,
25034-
imageTag: imageTag,
25035-
}),
25045+
body: JSON.stringify(body),
2503625046
})
2503725047
.then(response => {
2503825048
if (response.status !== 200) {

container-update-image/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ This action requires the following inputs:
5252
- *api_key* (required): The [API Key](https://dash.bunny.net/account/api-key) for your Bunny account. Team accounts are not supported at the moment;
5353
- *container* (required): The name of the container within the Magic Containers App;
5454
- *image_tag* (required): The new image tag;
55+
- *image_digest* (required): The digest of new image;

container-update-image/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ inputs:
2222
description: The new image.
2323
required: true
2424

25+
image_digest:
26+
description: The digest of the new image.
27+
required: false
28+
2529
runs:
2630
using: 'node20'
2731
main: '.lib-action/index.js'

container-update-image/src/action.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export async function run() {
55
const appId = core.getInput("app_id", { required: true });
66
const containerName = core.getInput("container", { required: true });
77
const imageTag = core.getInput("image_tag", { required: true });
8+
const imageDigest = core.getInput("image_digest");
89

910
try {
1011
const appConfig = await getAppConfiguration(apiKey, appId);
@@ -19,9 +20,13 @@ export async function run() {
1920
}
2021

2122
const containerId = containers[0].id;
22-
console.log(`Updating container "${containerName}" (${containerId}) with tag "${imageTag}"`);
23+
if (imageDigest === '') {
24+
console.log(`Updating container "${containerName}" (${containerId}) with tag "${imageTag}"`);
25+
} else {
26+
console.log(`Updating container "${containerName}" (${containerId}) with tag "${imageTag}", digest "${imageDigest}"`);
27+
}
2328

24-
patchAppContainer(apiKey, appId, containerId, imageTag);
29+
patchAppContainer(apiKey, appId, containerId, imageTag, imageDigest);
2530
} catch (e) {
2631
if (typeof e === 'string' || e instanceof Error) {
2732
core.setFailed(e);
@@ -69,18 +74,30 @@ async function getAppConfiguration(apiKey: string, appId: string): Promise<AppCo
6974
});
7075
}
7176

72-
async function patchAppContainer(apiKey: string, appId: string, containerId: string, imageTag: string): Promise<void> {
77+
type PatchBody = {
78+
id: string;
79+
imageTag: string;
80+
imageDigest?: string;
81+
}
82+
83+
async function patchAppContainer(apiKey: string, appId: string, containerId: string, imageTag: string, imageDigest?: string): Promise<void> {
84+
const body : PatchBody = {
85+
id: containerId,
86+
imageTag: imageTag,
87+
};
88+
89+
if (imageDigest !== undefined && imageDigest.length > 0) {
90+
body.imageDigest = imageDigest;
91+
}
92+
7393
return new Promise((resolve, reject) => {
7494
fetch(`https://api.bunny.net/mc/apps/${appId}/containers/${containerId}`, {
7595
method: 'PATCH',
7696
headers: {
7797
'Content-Type': 'application/json',
7898
'AccessKey': apiKey,
7999
},
80-
body: JSON.stringify({
81-
id: containerId,
82-
imageTag: imageTag,
83-
}),
100+
body: JSON.stringify(body),
84101
})
85102
.then(response => {
86103
if (response.status !== 200) {

0 commit comments

Comments
 (0)