Skip to content

Commit 664fd32

Browse files
committed
fix: take image refs out of meta-images attributes
metadata-action lines like name=org/app,enable=false were wrapped in another name=, so buildx tried to parse name=name=... Signed-off-by: Dean Chen <862469039@qq.com>
1 parent 2cac3a4 commit 664fd32

2 files changed

Lines changed: 78 additions & 4 deletions

File tree

‎.github/workflows/bake.yml‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,37 @@ jobs:
890890
};
891891
const renderTemplate = value => Util.compileHandlebars(value, {noEscape: true}, {meta});
892892
893+
// metadata-action lines are either "org/app" or "name=org/app,enable=...".
894+
// buildx name= wants the ref only, and enable=false should not be a destination.
895+
const metaImageName = entry => {
896+
const line = entry.trim();
897+
if (!line) {
898+
return '';
899+
}
900+
let name = '';
901+
let enable = 'true';
902+
for (const part of line.split(',')) {
903+
const eq = part.indexOf('=');
904+
if (eq === -1) {
905+
if (!name) {
906+
name = part.trim();
907+
}
908+
continue;
909+
}
910+
const key = part.slice(0, eq).trim();
911+
const value = part.slice(eq + 1).trim();
912+
if (key === 'name') {
913+
name = value;
914+
} else if (key === 'enable') {
915+
enable = value;
916+
}
917+
}
918+
if (!name || enable === 'false') {
919+
return '';
920+
}
921+
return name;
922+
};
923+
893924
const gitContextAttrs = GitHub.context.ref.startsWith('refs/tags/') ? {checksum: GitHub.context.sha} : {'fetch-by-commit': 'true'};
894925
const bakeSource = await new Build().gitContext({subdir: inpContext, attrs: gitContextAttrs});
895926
await core.group(`Set source output`, async () => {
@@ -946,13 +977,19 @@ jobs:
946977
947978
let outputOverride = '';
948979
switch (inpOutput) {
949-
case 'image':
980+
case 'image': {
950981
if (inpMetaImages.length == 0) {
951982
core.setFailed('meta-images is required when output is image');
952983
return;
953984
}
954-
outputOverride = `*.output=type=image,"name=${inpMetaImages.join(',')}",oci-artifact=true,push-by-digest=true,name-canonical=true,push=${inpPush}`;
985+
const imageNames = inpMetaImages.map(metaImageName).filter(Boolean);
986+
if (imageNames.length === 0) {
987+
core.setFailed('meta-images did not contain an enabled image');
988+
return;
989+
}
990+
outputOverride = `*.output=type=image,"name=${imageNames.join(',')}",oci-artifact=true,push-by-digest=true,name-canonical=true,push=${inpPush}`;
955991
break;
992+
}
956993
case 'local':
957994
outputOverride = `*.output=type=local,platform-split=true,dest=${inpLocalExportDir}`;
958995
break;

‎.github/workflows/build.yml‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,19 +817,56 @@ jobs:
817817
tags: inpMetaTags
818818
};
819819
const renderTemplate = value => Util.compileHandlebars(value, {noEscape: true}, {meta});
820+
821+
// metadata-action lines are either "org/app" or "name=org/app,enable=...".
822+
// buildx name= wants the ref only, and enable=false should not be a destination.
823+
const metaImageName = entry => {
824+
const line = entry.trim();
825+
if (!line) {
826+
return '';
827+
}
828+
let name = '';
829+
let enable = 'true';
830+
for (const part of line.split(',')) {
831+
const eq = part.indexOf('=');
832+
if (eq === -1) {
833+
if (!name) {
834+
name = part.trim();
835+
}
836+
continue;
837+
}
838+
const key = part.slice(0, eq).trim();
839+
const value = part.slice(eq + 1).trim();
840+
if (key === 'name') {
841+
name = value;
842+
} else if (key === 'enable') {
843+
enable = value;
844+
}
845+
}
846+
if (!name || enable === 'false') {
847+
return '';
848+
}
849+
return name;
850+
};
820851
821852
const gitContextAttrs = GitHub.context.ref.startsWith('refs/tags/') ? {checksum: GitHub.context.sha} : {'fetch-by-commit': 'true'};
822853
const buildContext = await new Build().gitContext({subdir: inpContext, attrs: gitContextAttrs});
823854
core.setOutput('context', buildContext);
824855
825856
switch (inpOutput) {
826-
case 'image':
857+
case 'image': {
827858
if (inpMetaImages.length == 0) {
828859
core.setFailed('meta-images is required when output is image');
829860
return;
830861
}
831-
core.setOutput('output', `type=image,"name=${inpMetaImages.join(',')}",oci-artifact=true,push-by-digest=true,name-canonical=true,push=${inpPush}`);
862+
const imageNames = inpMetaImages.map(metaImageName).filter(Boolean);
863+
if (imageNames.length === 0) {
864+
core.setFailed('meta-images did not contain an enabled image');
865+
return;
866+
}
867+
core.setOutput('output', `type=image,"name=${imageNames.join(',')}",oci-artifact=true,push-by-digest=true,name-canonical=true,push=${inpPush}`);
832868
break;
869+
}
833870
case 'local':
834871
core.setOutput('output', `type=local,platform-split=true,dest=${inpLocalExportDir}`);
835872
break;

0 commit comments

Comments
 (0)