Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,24 @@ jobs:
- run: git diff --exit-code

build:
executor: golang
machine:
image: ubuntu-1604:201903-01
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we use 1804?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not listed in the docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
image: ubuntu-1604:201903-01
image: ubuntu-2204:2024.04.4

working_directory: /home/circleci/.go_workspace/src/github.com/prometheus/promu

steps:
- setup_remote_docker
- checkout
- run: make promu
- run: promu crossbuild -v
- run: go install .
- restore_cache:
keys:
- v01-gocache-{{ checksum "go.mod" }}
- v01-gocache-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the v01-gocache- key ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's for testing

- run: mkdir -p /home/circleci/.cache/go-build
- run: promu crossbuild -v --gocache-path /home/circleci/.cache/go-build
- run: du -sh /home/circleci/.cache/go-build
- save_cache:
key: v01-gocache-{{ checksum "go.mod" }}
paths:
- /home/circleci/.cache/go-build
- persist_to_workspace:
root: .
paths:
Expand Down
3 changes: 1 addition & 2 deletions .promu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go:
repository:
path: github.com/prometheus/promu
build:
flags: -mod=vendor -a -tags 'netgo static_build'
flags: -mod=vendor -tags 'netgo static_build'
ldflags: |
-s
-X github.com/prometheus/common/version.Version={{.Version}}
Expand All @@ -17,4 +17,3 @@ tarball:
files:
- LICENSE
- NOTICE

30 changes: 22 additions & 8 deletions cmd/crossbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ var (
platformsFlagSet = true
return nil
}).Strings()
goCachePath = crossbuildcmd.Flag("gocache-path", "Path to a Go cache directory on the local machine").String()
// kingpin doesn't currently support using the crossbuild command and the
// crossbuild tarball subcommand at the same time, so we treat the
// tarball subcommand as an optional arg
// tarball subcommand as an optional arg.
tarballsSubcommand = crossbuildcmd.Arg("tarballs", "Optionally pass the string \"tarballs\" from cross-built binaries").String()
)

func runCrossbuild() {
//Check required configuration
// Check required configuration.
if len(strings.TrimSpace(config.Repository.Path)) == 0 {
log.Fatalf("missing required '%s' configuration", "repository.path")
}
Expand Down Expand Up @@ -149,7 +150,7 @@ func runCrossbuild() {
}

if !cgo {
// In non-CGO, use the base image without any crossbuild toolchain
// In non-CGO, use the base image without any crossbuild toolchain.
var allPlatforms []string
allPlatforms = append(allPlatforms, mainPlatforms[:]...)
allPlatforms = append(allPlatforms, armPlatforms[:]...)
Expand All @@ -158,7 +159,7 @@ func runCrossbuild() {
allPlatforms = append(allPlatforms, s390xPlatforms[:]...)

pg := &platformGroup{"base", dockerBaseBuilderImage, allPlatforms}
if err := pg.Build(repoPath); err != nil {
if err := pg.Build(repoPath, *goCachePath); err != nil {
fatal(errors.Wrapf(err, "The %s builder docker image exited unexpectedly", pg.Name))
}
} else {
Expand All @@ -169,7 +170,7 @@ func runCrossbuild() {
{"MIPS", dockerMIPSBuilderImage, mipsPlatforms},
{"s390x", dockerS390XBuilderImage, s390xPlatforms},
} {
if err := pg.Build(repoPath); err != nil {
if err := pg.Build(repoPath, *goCachePath); err != nil {
fatal(errors.Wrapf(err, "The %s builder docker image exited unexpectedly", pg.Name))
}
}
Expand All @@ -182,7 +183,9 @@ type platformGroup struct {
Platforms []string
}

func (pg platformGroup) Build(repoPath string) error {
const containerGoCacheDir = "/root/.cache/go-build"

func (pg platformGroup) Build(repoPath string, goCachePath string) error {
platformsParam := strings.Join(pg.Platforms[:], " ")
if len(platformsParam) == 0 {
return nil
Expand All @@ -196,11 +199,22 @@ func (pg platformGroup) Build(repoPath string) error {
}

ctrName := "promu-crossbuild-" + pg.Name + strconv.FormatInt(time.Now().Unix(), 10)
err = sh.RunCommand("docker", "create", "-t",
args := []string{
"create", "-t",
"--name", ctrName,
}
if goCachePath != "" {
args = append(args,
"--env", fmt.Sprintf("GOCACHE=%s", containerGoCacheDir),
"-v", fmt.Sprintf("%s:%s", goCachePath, containerGoCacheDir),
)
}
args = append(args,
pg.DockerImage,
"-i", repoPath,
"-p", platformsParam)
"-p", platformsParam,
)
err = sh.RunCommand("docker", args...)
if err != nil {
return err
}
Expand Down