Skip to content

Commit e42dfc4

Browse files
smiratalos-bot
authored andcommitted
feat: build bldr for linux/amd64 and linux/arm64
`bldr` frontend auto-detects build/target platform and adjusts for it. Add integration tests for multi-platform builds. Bump Go, golangci-lint, dependencies, etc. Clean up linting errors. Signed-off-by: Andrey Smirnov <[email protected]>
1 parent 39b6665 commit e42dfc4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+753
-283
lines changed

.drone.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ steps:
2727
image: autonomy/build-container:latest
2828
pull: always
2929
environment:
30-
REGISTRY: registry.ci.svc:5000
31-
PLATFORM: linux/amd64
32-
BUILDKIT_HOST: ${BUILDKIT_HOST=tcp://buildkitd.ci.svc:1234}
30+
PLATFORM: linux/amd64,linux/arm64
31+
SSH_KEY:
32+
from_secret: ssh_key
33+
DOCKER_USERNAME:
34+
from_secret: docker_username
35+
DOCKER_PASSWORD:
36+
from_secret: docker_password
3337
commands:
34-
- docker buildx create --driver docker-container --platform linux/amd64 --name local --config hack/buildkit.conf --use
38+
- install-ci-key
39+
- setup-buildx-amd64-arm64
40+
- docker login --username "$${DOCKER_USERNAME}" --password "$${DOCKER_PASSWORD}"
3541
- make # build everything
3642
- make frontend PUSH=true # push only frontend for integration tests
3743
- make integration
@@ -47,14 +53,15 @@ steps:
4753
image: autonomy/build-container:latest
4854
pull: always
4955
environment:
50-
PLATFORM: linux/amd64
56+
PLATFORM: linux/amd64,linux/arm64
5157
BUILDKIT_HOST: ${BUILDKIT_HOST=tcp://buildkitd.ci.svc:1234}
5258
DOCKER_USERNAME:
5359
from_secret: docker_username
5460
DOCKER_PASSWORD:
5561
from_secret: docker_password
5662
commands:
57-
- docker buildx create --driver docker-container --platform linux/amd64 --name local --use
63+
- install-ci-key
64+
- setup-buildx-amd64-arm64
5865
- docker login --username "$${DOCKER_USERNAME}" --password "$${DOCKER_PASSWORD}"
5966
- make PUSH=true
6067
- make integration

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# syntax = docker/dockerfile-upstream:1.1.2-experimental
22

3-
FROM golang:1.13.6-alpine AS base
3+
FROM golang:1.14-alpine AS base
44
ENV GO111MODULE on
55
ENV GOPROXY https://proxy.golang.org
66
ENV CGO_ENABLED 0
77
RUN apk --update --no-cache add bash curl
8-
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /bin v1.20.0
8+
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /bin v1.27.0
99
WORKDIR /src
1010
COPY ./go.mod ./
1111
COPY ./go.sum ./

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ TAG ?= $(shell git describe --tag --always --dirty)
44
REGISTRY_AND_USERNAME := $(REGISTRY)/$(USERNAME)
55
RUN_TESTS ?= TestIntegration
66

7-
PLATFORM ?= linux/amd64
7+
BUILD_PLATFORM ?= linux/amd64
8+
PLATFORM ?= linux/amd64,linux/arm64
89
PROGRESS ?= auto
910
PUSH ?= false
1011

@@ -55,4 +56,4 @@ frontend:
5556

5657
.PHONY: integration
5758
integration: integration.test bldr
58-
cd internal/pkg/integration && PATH="$$PWD/../../../out:$$PATH" integration.test -test.v -test.run $(RUN_TESTS)
59+
cd internal/pkg/integration && PATH="$$PWD/../../../out/$(subst /,_,$(BUILD_PLATFORM)):$$PATH" integration.test -test.v -test.run $(RUN_TESTS)

cmd/frontend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/talos-systems/bldr/internal/pkg/pkgfile"
1616
)
1717

18-
// frontendCmd represents the frontend command
18+
// frontendCmd represents the frontend command.
1919
var frontendCmd = &cobra.Command{
2020
Use: "frontend",
2121
Short: "Buildkit frontend for Pkgfile",

cmd/graph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/talos-systems/bldr/internal/pkg/solver"
1313
)
1414

15-
// graphCmd represents the graph command
15+
// graphCmd represents the graph command.
1616
var graphCmd = &cobra.Command{
1717
Use: "graph",
1818
Short: "Graph dependencies between pkgs",

cmd/llb.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/talos-systems/bldr/internal/pkg/solver"
1616
)
1717

18-
// llbCmd represents the llb command
18+
// llbCmd represents the llb command.
1919
var llbCmd = &cobra.Command{
2020
Use: "llb",
2121
Short: "Dump buildkit LLB for the build",
@@ -38,12 +38,7 @@ and outputs buildkit LLB to stdout. This can be used as 'bldr pack ... | buildct
3838
log.Fatal(err)
3939
}
4040

41-
out, err := convert.BuildLLB(graph, options)
42-
if err != nil {
43-
log.Fatal(err)
44-
}
45-
46-
dt, err := out.Marshal(options.BuildPlatform.LLBPlatform)
41+
dt, err := convert.MarshalLLB(graph, options)
4742
if err != nil {
4843
log.Fatal(err)
4944
}

cmd/root.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ package cmd
88
import (
99
"fmt"
1010
"os"
11+
"runtime"
1112

1213
"github.com/spf13/cobra"
1314
"github.com/talos-systems/bldr/internal/pkg/environment"
1415
)
1516

17+
const defaultPlatform = (runtime.GOOS + "/" + runtime.GOARCH)
18+
1619
var (
1720
pkgRoot string
1821
options = &environment.Options{
@@ -21,7 +24,7 @@ var (
2124
}
2225
)
2326

24-
// rootCmd represents the base command when called without any subcommands
27+
// rootCmd represents the base command when called without any subcommands.
2528
var rootCmd = &cobra.Command{
2629
Use: "bldr",
2730
Short: "A tool to build and manage software via Pkgfile and pkg.yaml",
@@ -35,6 +38,7 @@ output LLB directly which is useful for development or debugging.`,
3538
}
3639

3740
// Execute adds all child commands to the root command and sets flags appropriately.
41+
//
3842
// This is called by main.main(). It only needs to happen once to the rootCmd.
3943
func Execute() {
4044
if err := rootCmd.Execute(); err != nil {
@@ -46,4 +50,7 @@ func Execute() {
4650
func init() {
4751
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
4852
rootCmd.PersistentFlags().StringVarP(&pkgRoot, "root", "", ".", "The path to a pkg root")
53+
54+
options.BuildPlatform.Set(defaultPlatform) //nolint: errcheck
55+
options.TargetPlatform.Set(defaultPlatform) //nolint: errcheck
4956
}

cmd/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/talos-systems/bldr/internal/pkg/solver"
1212
)
1313

14-
// validateCmd represents the graph command
14+
// validateCmd represents the validate command.
1515
var validateCmd = &cobra.Command{
1616
Use: "validate",
1717
Short: "Validate syntax of pkg.yaml files",

go.mod

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
module github.com/talos-systems/bldr
22

3-
go 1.13
3+
go 1.14
44

55
require (
66
github.com/Masterminds/goutils v1.1.0 // indirect
77
github.com/Masterminds/semver v1.5.0 // indirect
88
github.com/Masterminds/sprig v2.22.0+incompatible
9-
github.com/alessio/shellescape v0.0.0-20190409004728-b115ca0f9053
10-
github.com/emicklei/dot v0.10.1
11-
github.com/google/uuid v1.1.1 // indirect
12-
github.com/hashicorp/go-multierror v1.0.0
13-
github.com/huandu/xstrings v1.2.0 // indirect
9+
github.com/alessio/shellescape v1.2.2
10+
github.com/containerd/containerd v1.4.0-0
11+
github.com/emicklei/dot v0.11.0
12+
github.com/hashicorp/go-multierror v1.1.0
13+
github.com/huandu/xstrings v1.3.1 // indirect
1414
github.com/mitchellh/copystructure v1.0.0 // indirect
15-
github.com/moby/buildkit v0.6.2-0.20190921015714-10cef0c6e178
16-
github.com/opencontainers/go-digest v1.0.0-rc1
17-
github.com/otiai10/copy v1.0.2
18-
github.com/spf13/cobra v0.0.4
19-
golang.org/x/text v0.3.2 // indirect
20-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
21-
gopkg.in/yaml.v2 v2.2.2
15+
github.com/moby/buildkit v0.7.1
16+
github.com/opencontainers/go-digest v1.0.0
17+
github.com/opencontainers/image-spec v1.0.1
18+
github.com/otiai10/copy v1.2.0
19+
github.com/spf13/cobra v1.0.0
20+
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
21+
gopkg.in/yaml.v2 v2.3.0
2222
)
2323

24-
replace github.com/docker/docker v1.14.0-0.20190319215453-e7b5f7dbe98c => github.com/docker/docker v1.4.2-0.20190319215453-e7b5f7dbe98c
25-
26-
replace golang.org/x/crypto v0.0.0-20190129210102-0709b304e793 => golang.org/x/crypto v0.0.0-20180904163835-0709b304e793
24+
replace (
25+
github.com/containerd/containerd => github.com/containerd/containerd v1.3.1-0.20200512144102-f13ba8f2f2fd
26+
github.com/docker/docker => github.com/docker/docker v17.12.0-ce-rc1.0.20200310163718-4634ce647cf2+incompatible
27+
)

0 commit comments

Comments
 (0)