Skip to content

Commit

Permalink
Merge pull request #4 from moby/hcl-cleanup
Browse files Browse the repository at this point in the history
remove funcs in HCL definition
  • Loading branch information
crazy-max authored Aug 20, 2024
2 parents b788ea0 + 6957e8d commit 7cc0116
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@ function "sanitize_target" {
result = regex_replace(in, "[^a-zA-Z0-9_-]+", "-")
}

# generate named context for each ref
function "buildkit_build_contexts" {
params = [refs]
result = { for ref in split(",", refs) :
format("buildkit-build-%s", sanitize_target(ref)) => format("target:buildkit-build-%s", sanitize_target(ref))
}
}

# generate COPY instructions for each ref
function "buildkit_build_copy_froms" {
params = [refs]
result = join("\n", [for ref in split(",", refs) :
format("COPY --link --from=buildkit-build-%s / /%s", sanitize_target(ref), ref)
])
}

group "default" {
targets = ["tests"]
}
Expand All @@ -58,10 +42,14 @@ target "buildkit-build" {
}

target "buildkit-binaries" {
contexts = buildkit_build_contexts(BUILDKIT_REFS)
contexts = { for ref in split(",", BUILDKIT_REFS) :
format("buildkit-build-%s", sanitize_target(ref)) => format("target:buildkit-build-%s", sanitize_target(ref))
}
dockerfile-inline = <<EOT
FROM scratch
${buildkit_build_copy_froms(BUILDKIT_REFS)}
${join("\n", [for ref in split(",", BUILDKIT_REFS) :
format("COPY --link --from=buildkit-build-%s / /%s", sanitize_target(ref), ref)
])}
EOT
}

Expand Down

0 comments on commit 7cc0116

Please sign in to comment.