Skip to content

Commit

Permalink
fix: set BUILDKIT_MULTI_PLATFORM only for image
Browse files Browse the repository at this point in the history
Only set `BUILDKIT_MULTI_PLATFORM` when an image is being generated.
Revert all other hacks.

Also fix renovate config to ignore github action yamls and `Dockerfile`
since it's managed by kres.

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed Dec 24, 2024
1 parent fcff05e commit aadf261
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 57 deletions.
18 changes: 18 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
"digest"
]
},
{
"enabled": false,
"matchFileNames": [
"Dockerfile"
]
},
{
"enabled": false,
"matchFileNames": [
".github/workflows/*.yaml"
]
},
{
"versioning": "regex:^(?<major>\\d+)\\.(?<minor>\\d+)\\.?(?<patch>\\d+)?$",
"matchPackageNames": [
Expand All @@ -52,6 +64,12 @@
"matchPackageNames": [
"potiuk/get-workflow-origin"
]
},
{
"enabled": false,
"matchFileNames": [
"internal/output/dockerfile/dockerfile_test.go"
]
}
],
"separateMajorMinor": false
Expand Down
3 changes: 3 additions & 0 deletions .kres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ spec:
- matchPackageNames:
- potiuk/get-workflow-origin
versioning: 'regex:^v(?<major>\d+)_(?<minor>\d+)_?(?<patch>\d+)?$'
- enabled: false
matchFileNames:
- internal/output/dockerfile/dockerfile_test.go
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-12-18T17:24:46Z by kres b9507d6-dirty.
# Generated on 2024-12-24T15:16:56Z by kres e482a37-dirty.

ARG TOOLCHAIN

Expand All @@ -11,7 +11,7 @@ FROM ghcr.io/siderolabs/ca-certificates:v1.9.0 AS image-ca-certificates
FROM ghcr.io/siderolabs/fhs:v1.9.0 AS image-fhs

# runs markdownlint
FROM docker.io/oven/bun:1.1.40-alpine AS lint-markdown
FROM docker.io/oven/bun:1.1.42-alpine AS lint-markdown
WORKDIR /src
RUN bun i [email protected] [email protected]
COPY .markdownlint.json .
Expand Down
21 changes: 5 additions & 16 deletions 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-12-18T17:24:46Z by kres b9507d6-dirty.
# Generated on 2024-12-24T15:16:56Z by kres e482a37-dirty.

# common variables

Expand All @@ -17,9 +17,9 @@ WITH_RACE ?= false
REGISTRY ?= ghcr.io
USERNAME ?= siderolabs
REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME)
PROTOBUF_GO_VERSION ?= 1.36.0
PROTOBUF_GO_VERSION ?= 1.36.1
GRPC_GO_VERSION ?= 1.5.1
GRPC_GATEWAY_VERSION ?= 2.24.0
GRPC_GATEWAY_VERSION ?= 2.25.1
VTPROTOBUF_VERSION ?= 0.6.0
GOIMPORTS_VERSION ?= 0.28.0
DEEPCOPY_VERSION ?= v0.5.6
Expand All @@ -41,13 +41,11 @@ PLATFORM ?= linux/amd64
PROGRESS ?= auto
PUSH ?= false
CI_ARGS ?=
BUILDKIT_MULTI_PLATFORM ?= 1
COMMON_ARGS = --file=Dockerfile
COMMON_ARGS += --provenance=false
COMMON_ARGS += --progress=$(PROGRESS)
COMMON_ARGS += --platform=$(PLATFORM)
COMMON_ARGS += --push=$(PUSH)
COMMON_ARGS += --build-arg=BUILDKIT_MULTI_PLATFORM=$(BUILDKIT_MULTI_PLATFORM)
COMMON_ARGS += --build-arg=ARTIFACTS="$(ARTIFACTS)"
COMMON_ARGS += --build-arg=SHA="$(SHA)"
COMMON_ARGS += --build-arg=TAG="$(TAG)"
Expand Down Expand Up @@ -147,18 +145,9 @@ 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) DEST=$(DEST) bash -c '\
for platform in $$(tr "," "\n" <<< "$$PLATFORM"); do \
echo $$platform; \
directory="$${platform//\//_}"; \
if [[ -d "$$DEST/$$directory" ]]; then \
mv -f "$$DEST/$$directory/"* $$DEST; \
rmdir "$$DEST/$$directory/"; \
fi; \
done'

generate: ## Generate .proto definitions.
@$(MAKE) local-$@ DEST=./ BUILDKIT_MULTI_PLATFORM=0
@$(MAKE) local-$@ DEST=./

lint-golangci-lint: ## Runs golangci-lint linter.
@$(MAKE) target-$@
Expand Down Expand Up @@ -229,7 +218,7 @@ lint: lint-golangci-lint lint-gofumpt lint-govulncheck lint-markdown ## Run all

.PHONY: image-kres
image-kres: ## Builds image for kres.
@$(MAKE) target-$@ TARGET_ARGS="--tag=$(REGISTRY)/$(USERNAME)/kres:$(IMAGE_TAG)"
@$(MAKE) target-$@ TARGET_ARGS="--tag=$(REGISTRY)/$(USERNAME)/kres:$(IMAGE_TAG) --build-arg=BUILDKIT_MULTI_PLATFORM=1"

.PHONY: rekres
rekres:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.23.4
require (
github.com/drone/drone-yaml v1.2.3
github.com/go-git/go-git/v5 v5.12.0
github.com/google/go-github/v67 v67.0.0
github.com/google/go-github/v68 v68.0.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/siderolabs/gen v0.8.0
github.com/spf13/cobra v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v67 v67.0.0 h1:g11NDAmfaBaCO8qYdI9fsmbaRipHNWRIU/2YGvlh4rg=
github.com/google/go-github/v67 v67.0.0/go.mod h1:zH3K7BxjFndr9QSeFibx4lTKkYS3K9nDanoI1NjaOtY=
github.com/google/go-github/v68 v68.0.0 h1:ZW57zeNZiXTdQ16qrDiZ0k6XucrxZ2CGmoTvcCyQG6s=
github.com/google/go-github/v68 v68.0.0/go.mod h1:K9HAUBovM2sLwM408A18h+wd9vqdLOEqTUCbnRIcx68=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
Expand Down
6 changes: 3 additions & 3 deletions internal/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const (
GoVersion = "1.23.4"
// GrpcGatewayVersion is the version of grpc-gateway.
// renovate: datasource=go depName=github.com/grpc-ecosystem/grpc-gateway
GrpcGatewayVersion = "v2.24.0"
GrpcGatewayVersion = "v2.25.1"
// GrpcGoVersion is the version of grpc.
// renovate: datasource=go depName=google.golang.org/grpc/cmd/protoc-gen-go-grpc
GrpcGoVersion = "v1.5.1"
Expand All @@ -72,13 +72,13 @@ const (
MarkdownLintCLIVersion = "0.43.0"
// BunContainerImageVersion is the default bun container image.
// renovate: datasource=docker versioning=docker depName=oven/bun
BunContainerImageVersion = "1.1.40-alpine"
BunContainerImageVersion = "1.1.42-alpine"
// PkgsVersion is the version of pkgs.
// renovate: datasource=github-tags depName=siderolabs/pkgs
PkgsVersion = "v1.9.0"
// ProtobufGoVersion is the version of protobuf.
// renovate: datasource=go depName=google.golang.org/protobuf/cmd/protoc-gen-go
ProtobufGoVersion = "v1.36.0"
ProtobufGoVersion = "v1.36.1"
// ProtobufTSGatewayVersion is the version of protobuf-ts.
// renovate: datasource=go depName=github.com/siderolabs/protoc-gen-grpc-gateway-ts
ProtobufTSGatewayVersion = "v1.2.1"
Expand Down
2 changes: 1 addition & 1 deletion internal/output/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"fmt"
"os"

"github.com/google/go-github/v67/github"
"github.com/google/go-github/v68/github"
"golang.org/x/oauth2"
)

Expand Down
17 changes: 17 additions & 0 deletions internal/project/common/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/siderolabs/kres/internal/output/gitignore"
"github.com/siderolabs/kres/internal/output/makefile"
"github.com/siderolabs/kres/internal/output/release"
"github.com/siderolabs/kres/internal/output/renovate"
"github.com/siderolabs/kres/internal/project/meta"
)

Expand Down Expand Up @@ -104,3 +105,19 @@ func (build *Build) CompileRelease(output *release.Output) error {

return nil
}

// CompileRenovate implements renovate.Compiler.
func (build *Build) CompileRenovate(output *renovate.Output) error {
output.PackageRules([]renovate.PackageRule{
{
Enabled: &[]bool{false}[0],
MatchFileNames: []string{"Dockerfile"},
},
{
Enabled: &[]bool{false}[0],
MatchFileNames: []string{".github/workflows/*.yaml"},
},
})

return nil
}
25 changes: 2 additions & 23 deletions internal/project/common/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,6 @@ import (
"github.com/siderolabs/kres/internal/project/meta"
)

// FixLocalDestLocationsScript moves the local build artifacts from the <os>_<arch> subdirectories to the build output root directory.
//
// This is to revert the behavior of buildkit on multi-platform builds.
//
// As we force buildkit to always do multi-platform builds (via `BUILDKIT_MULTI_PLATFORM=1`), we need this fix to restore old output behavior.
//
// This script is appended to the local output build targets.
const FixLocalDestLocationsScript = `
@PLATFORM=$(PLATFORM) DEST=$(DEST) bash -c '\
for platform in $$(tr "," "\n" <<< "$$PLATFORM"); do \
echo $$platform; \
directory="$${platform//\//_}"; \
if [[ -d "$$DEST/$$directory" ]]; then \
mv -f "$$DEST/$$directory/"* $$DEST; \
rmdir "$$DEST/$$directory/"; \
fi; \
done'
`

// Docker provides build infrastructure via docker buildx.
type Docker struct { //nolint:govet
dag.BaseNode
Expand Down Expand Up @@ -136,8 +117,7 @@ func (docker *Docker) CompileMakefile(output *makefile.Output) error {
Push("--provenance=false").
Push("--progress=$(PROGRESS)").
Push("--platform=$(PLATFORM)").
Push("--push=$(PUSH)").
Push("--build-arg=BUILDKIT_MULTI_PLATFORM=$(BUILDKIT_MULTI_PLATFORM)")
Push("--push=$(PUSH)")

for _, arg := range docker.meta.BuildArgs {
buildArgs.Push(fmt.Sprintf("--build-arg=%s=\"$(%s)\"", arg, arg))
Expand All @@ -158,7 +138,6 @@ func (docker *Docker) CompileMakefile(output *makefile.Output) error {
Variable(makefile.OverridableVariable("PROGRESS", "auto")).
Variable(makefile.OverridableVariable("PUSH", "false")).
Variable(makefile.OverridableVariable("CI_ARGS", "")).
Variable(makefile.OverridableVariable("BUILDKIT_MULTI_PLATFORM", "1")).
Variable(buildArgs)

output.Target("target-%").
Expand All @@ -167,7 +146,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)"` + FixLocalDestLocationsScript)
Script(`@$(MAKE) target-$* TARGET_ARGS="--output=type=local,dest=$(DEST) $(TARGET_ARGS)"`)

return nil
}
2 changes: 1 addition & 1 deletion internal/project/common/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (image *Image) CompileGitHubWorkflow(output *ghworkflow.Output) error {
func (image *Image) CompileMakefile(output *makefile.Output) error {
target := output.Target(image.Name()).
Description(fmt.Sprintf("Builds image for %s.", image.ImageName)).
Script(fmt.Sprintf(`@$(MAKE) target-$@ TARGET_ARGS="--tag=$(REGISTRY)/$(USERNAME)/%s:$(IMAGE_TAG)"`, image.ImageName)).
Script(fmt.Sprintf(`@$(MAKE) target-$@ TARGET_ARGS="--tag=$(REGISTRY)/$(USERNAME)/%s:$(IMAGE_TAG) --build-arg=BUILDKIT_MULTI_PLATFORM=1"`, image.ImageName)).
Phony()

for _, dependsOn := range image.DependsOn {
Expand Down
2 changes: 1 addition & 1 deletion internal/project/common/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/http"
"slices"

"github.com/google/go-github/v67/github"
"github.com/google/go-github/v68/github"
"github.com/siderolabs/gen/xslices"

"github.com/siderolabs/kres/internal/config"
Expand Down
2 changes: 1 addition & 1 deletion internal/project/golang/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (generate *Generate) CompileMakefile(output *makefile.Output) error {
}

output.Target("generate").Description("Generate .proto definitions.").
Script(`@$(MAKE) local-$@ DEST=./ BUILDKIT_MULTI_PLATFORM=0`)
Script(`@$(MAKE) local-$@ DEST=./`)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/project/js/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (proto *Protobuf) CompileMakefile(output *makefile.Output) error {

output.Target("generate-" + proto.Name()).
Description("Generate .proto definitions.").
Script("@$(MAKE) local-$@ DEST=./ BUILDKIT_MULTI_PLATFORM=0")
Script("@$(MAKE) local-$@ DEST=./")

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

Expand Down Expand Up @@ -90,8 +89,7 @@ func (pkgfile *Build) CompileMakefile(output *makefile.Output) error {
Push("--provenance=false").
Push("--progress=$(PROGRESS)").
Push("--platform=$(PLATFORM)").
Push("--build-arg=SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH)").
Push("--build-arg=BUILDKIT_MULTI_PLATFORM=$(BUILDKIT_MULTI_PLATFORM)")
Push("--build-arg=SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH)")

for _, arg := range pkgfile.ExtraBuildArgs {
buildArgs.Push(fmt.Sprintf("--build-arg=%s=\"$(%s)\"", arg, arg))
Expand All @@ -108,7 +106,6 @@ func (pkgfile *Build) CompileMakefile(output *makefile.Output) error {
Variable(makefile.OverridableVariable("PROGRESS", "auto")).
Variable(makefile.OverridableVariable("PUSH", "false")).
Variable(makefile.OverridableVariable("CI_ARGS", "")).
Variable(makefile.OverridableVariable("BUILDKIT_MULTI_PLATFORM", "1")).
Variable(buildArgs)

for _, arg := range pkgfile.Makefile.ExtraVariables {
Expand All @@ -122,7 +119,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)"` + common.FixLocalDestLocationsScript)
Script(`@$(MAKE) target-$* TARGET_ARGS="--output=type=local,dest=$(DEST) $(TARGET_ARGS)"`)

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 aadf261

Please sign in to comment.