Skip to content

Commit

Permalink
feat(docker-manifest): apply additional image tags with crane (#51)
Browse files Browse the repository at this point in the history
* feat(docker-manifest): apply extra tags with crane

Signed-off-by: Cameron Smith <cameron.ray.smith@gmail.com>

* fix(docker-manifest): make firstTag a nix variable

Signed-off-by: Cameron Smith <cameron.ray.smith@gmail.com>

* docs(docker-manifest): note idempotency of crane tag

Signed-off-by: Cameron Smith <cameron.ray.smith@gmail.com>

---------

Signed-off-by: Cameron Smith <cameron.ray.smith@gmail.com>
  • Loading branch information
cameronraysmith authored Jul 9, 2024
1 parent f20c8eb commit e5d4bca
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/docker-manifest.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
writeShellScriptBin,
buildah,
coreutils,
crane,
git,
}: {
images,
Expand All @@ -23,6 +24,7 @@
optionalAttrPath = path: attrset: lib.flocken.attrByDottedPath path null attrset;

buildahExe = lib.getExe' buildah "buildah";
craneExe = lib.getExe' crane "crane";

_github =
{
Expand Down Expand Up @@ -117,6 +119,7 @@
++ (lib.optional (_autoTags.majorMinor && lib.flocken.isNotEmpty _version && !isPreRelease _version) (lib.versions.majorMinor _version))
++ (lib.optional (_autoTags.major && lib.flocken.isNotEmpty _version && !isPreRelease _version) (lib.versions.major _version))
);
firstTag = builtins.head _tags;

_annotations =
lib.filterAttrs
Expand Down Expand Up @@ -176,16 +179,27 @@ in
--username "${registryParams.username}" \
--password "${registryParams.password}" \
"${registryName}"
echo "crane login ${registryName}"
${craneExe} auth login "${registryName}" \
--username "${registryParams.username}" \
--password "${registryParams.password}"
set -x # echo on
${buildahExe} manifest push --all \
--format ${format} \
"$manifest" \
"${targetProtocol}${registryName}/${registryParams.repo}:${firstTag}"
# `crane tag` is idempotent so it is not necessary to use
# `builtins.tail` to remove the first tag from `_tags`
for tag in ${builtins.toString _tags}; do
${buildahExe} manifest push --all \
--format ${format} \
"$manifest" \
"${targetProtocol}${registryName}/${registryParams.repo}:$tag"
${craneExe} tag \
"${registryName}/${registryParams.repo}:${firstTag}" \
"$tag"
done
${buildahExe} logout "${registryName}"
${craneExe} auth logout "${registryName}"
'')
_registries)}
''

0 comments on commit e5d4bca

Please sign in to comment.