Skip to content

Commit

Permalink
fix: fix local artifact output locations when `BUILDKIT_MULTI_PLATFOR…
Browse files Browse the repository at this point in the history
…M=1`

Passing `BUILDKIT_MULTI_PLATFORM=1` to buildkit for each build (introduced in 7db4f5e) in `COMMON_ARGS` caused some unwanted changes in the output behavior when we ran a single-platform build: it started to output the files to locations same as to multi-platform format, `<os>_<arch>/<filename>`, instead of just `<filename>`.

Fix this by running a small script to move these files to one upper directory after a local build.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
  • Loading branch information
utkuozdemir committed Nov 6, 2024
1 parent 398a599 commit c8d2ffa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-11-05T11:16:22Z by kres 5fa0b38-dirty.
# Generated on 2024-11-06T12:40:22Z by kres 1becf29d-dirty.

# common variables

Expand Down Expand Up @@ -146,6 +146,15 @@ target-%: ## Builds the specified target defined in the Dockerfile. The build r

local-%: ## Builds the specified target defined in the Dockerfile using the local output type. The build result will be output to the specified local destination.
@$(MAKE) target-$* TARGET_ARGS="--output=type=local,dest=$(DEST) $(TARGET_ARGS)"
@PLATFORM=$(PLATFORM) ARTIFACTS=$(ARTIFACTS) bash -c '\
for platform in $$(tr "," "\n" <<< "$$PLATFORM"); do \
echo $$platform; \
directory="$${platform//\//_}"; \
if [[ -d "$$ARTIFACTS/$$directory" ]]; then \
mv "$$ARTIFACTS/$$directory/"* $$ARTIFACTS; \
rmdir "$$ARTIFACTS/$$directory/"; \
fi; \
done'

generate: ## Generate .proto definitions.
@$(MAKE) local-$@ DEST=./
Expand Down
14 changes: 13 additions & 1 deletion internal/project/common/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ import (
"github.com/siderolabs/kres/internal/project/meta"
)

const FixLocalArtifactLocationsScript = `
@PLATFORM=$(PLATFORM) ARTIFACTS=$(ARTIFACTS) bash -c '\
for platform in $$(tr "," "\n" <<< "$$PLATFORM"); do \
echo $$platform; \
directory="$${platform//\//_}"; \
if [[ -d "$$ARTIFACTS/$$directory" ]]; then \
mv "$$ARTIFACTS/$$directory/"* $$ARTIFACTS; \
rmdir "$$ARTIFACTS/$$directory/"; \
fi; \
done'
`

// Docker provides build infrastructure via docker buildx.
type Docker struct { //nolint:govet
dag.BaseNode
Expand Down Expand Up @@ -147,7 +159,7 @@ func (docker *Docker) CompileMakefile(output *makefile.Output) error {

output.Target("local-%").
Description("Builds the specified target defined in the Dockerfile using the local output type. The build result will be output to the specified local destination.").
Script(`@$(MAKE) target-$* TARGET_ARGS="--output=type=local,dest=$(DEST) $(TARGET_ARGS)"`)
Script(`@$(MAKE) target-$* TARGET_ARGS="--output=type=local,dest=$(DEST) $(TARGET_ARGS)"` + FixLocalArtifactLocationsScript)

return nil
}
3 changes: 2 additions & 1 deletion internal/project/pkgfile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/siderolabs/kres/internal/output/dockerignore"
"github.com/siderolabs/kres/internal/output/ghworkflow"
"github.com/siderolabs/kres/internal/output/makefile"
"github.com/siderolabs/kres/internal/project/common"
"github.com/siderolabs/kres/internal/project/meta"
)

Expand Down Expand Up @@ -114,7 +115,7 @@ func (pkgfile *Build) CompileMakefile(output *makefile.Output) error {

output.Target("local-%").
Description("Builds the specified target defined in the Pkgfile using the local output type. The build result will be output to the specified local destination.").
Script(`@$(MAKE) target-$* TARGET_ARGS="--output=type=local,dest=$(DEST) $(TARGET_ARGS)"`)
Script(`@$(MAKE) target-$* TARGET_ARGS="--output=type=local,dest=$(DEST) $(TARGET_ARGS)"` + common.FixLocalArtifactLocationsScript)

output.Target("docker-%").
Description("Builds the specified target defined in the Pkgfile using the docker output type. The build result will be loaded into Docker.").
Expand Down

0 comments on commit c8d2ffa

Please sign in to comment.