diff --git a/.buildkite/pipeline.package.mbp.yml b/.buildkite/pipeline.package.mbp.yml index 21636efaff..130e524c97 100644 --- a/.buildkite/pipeline.package.mbp.yml +++ b/.buildkite/pipeline.package.mbp.yml @@ -1,8 +1,8 @@ # yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json name: "fleet server package mbp" env: - IMAGE_UBUNTU_X86_64: "family/core-ubuntu-2204" - IMAGE_UBUNTU_ARM_64: "core-ubuntu-2204-aarch64" + IMAGE_UBUNTU_X86_64: "platform-ingest-fleets-ubuntu-2204-1770381074" + IMAGE_UBUNTU_ARM_64: "platform-ingest-fleet-server-ubuntu-2204-aarch64-1770381074" # This section is used to define the plugins that will be used in the pipeline. # See https://buildkite.com/docs/pipelines/integrations/plugins/using#using-yaml-anchors-with-plugins @@ -91,7 +91,7 @@ steps: command: ".buildkite/scripts/package.sh snapshot" agents: provider: "aws" - imagePrefix: "${IMAGE_UBUNTU_ARM_64}" + image: "${IMAGE_UBUNTU_ARM_64}" instanceType: "t4g.2xlarge" artifact_paths: - build/distributions/** @@ -106,7 +106,7 @@ steps: .buildkite/scripts/package.sh staging agents: provider: "aws" - imagePrefix: "${IMAGE_UBUNTU_ARM_64}" + image: "${IMAGE_UBUNTU_ARM_64}" instanceType: "t4g.2xlarge" artifact_paths: - build/distributions/** @@ -122,7 +122,7 @@ steps: FIPS: "true" agents: provider: "aws" - imagePrefix: "${IMAGE_UBUNTU_ARM_64}" + image: "${IMAGE_UBUNTU_ARM_64}" instanceType: "t4g.2xlarge" artifact_paths: - build/distributions/** @@ -139,7 +139,7 @@ steps: FIPS: "true" agents: provider: "aws" - imagePrefix: "${IMAGE_UBUNTU_ARM_64}" + image: "${IMAGE_UBUNTU_ARM_64}" instanceType: "t4g.2xlarge" artifact_paths: - build/distributions/** diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index d9e5d8a3ce..c8e8bf67b5 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -3,9 +3,9 @@ env: DOCKER_COMPOSE_VERSION: "1.25.5" TERRAFORM_VERSION: "1.6.4" - IMAGE_UBUNTU_X86_64: "platform-ingest-elastic-agent-ubuntu-2204-1767879728" - IMAGE_UBUNTU_ARM_64: "platform-ingest-elastic-agent-ubuntu-2204-aarch64-1767879728" - IMAGE_UBUNTU_X86_64_FIPS: "platform-ingest-fleet-server-ubuntu-2204-fips" + IMAGE_UBUNTU_X86_64: "platform-ingest-fleets-ubuntu-2204-1770381074" + IMAGE_UBUNTU_ARM_64: "platform-ingest-fleet-server-ubuntu-2204-aarch64-1770381074" + IMAGE_UBUNTU_X86_64_FIPS: "platform-ingest-fleet-server-ubuntu-2204-fips-1770381074" # This section is used to define the plugins that will be used in the pipeline. # See https://buildkite.com/docs/pipelines/integrations/plugins/using#using-yaml-anchors-with-plugins @@ -173,7 +173,7 @@ steps: GO_DISTRO: "microsoft" agents: provider: "aws" - imagePrefix: "${IMAGE_UBUNTU_X86_64_FIPS}" + image: "${IMAGE_UBUNTU_X86_64_FIPS}" instanceType: "m5.xlarge" artifact_paths: - build/*.xml @@ -187,7 +187,7 @@ steps: GO_DISTRO: "stdlib" agents: provider: "aws" - imagePrefix: "${IMAGE_UBUNTU_X86_64_FIPS}" + image: "${IMAGE_UBUNTU_X86_64_FIPS}" instanceType: "m5.xlarge" artifact_paths: - build/*.xml diff --git a/magefile.go b/magefile.go index 06aecf9878..21f3833cff 100644 --- a/magefile.go +++ b/magefile.go @@ -706,7 +706,7 @@ func (Build) Local() error { outFile = filepath.Join("bin", binaryExe) } - return sh.RunWithV(env, "go", "build", "-tags="+getTagsString(), "-gcflags="+getGCFlags(), "-ldflags="+getLDFlags(), "-o", outFile, ".") + return sh.RunWithV(env, "go", "build", "-buildvcs=false", "-tags="+getTagsString(), "-gcflags="+getGCFlags(), "-ldflags="+getLDFlags(), "-o", outFile, ".") } // Binary builds release binaries for the specified platforms. @@ -753,6 +753,7 @@ func goBuild(osArg, archArg string, cover bool) error { args := []string{ "build", + "-buildvcs=false", "-tags=" + getTagsString(), "-gcflags=" + getGCFlags(), "-ldflags=" + getLDFlags(), @@ -973,6 +974,8 @@ func (Docker) Release() error { } // dockerRun runs the target on a container produced by docker:builder. +// When .git/objects/info/alternates exists and points to paths on the host (e.g. CI git mirrors), +// those paths are mounted into the container at the same location so Go's VCS stamping can read them. func dockerRun(target string) error { userInfo, err := user.Current() if err != nil { @@ -982,17 +985,56 @@ func dockerRun(target string) error { if err != nil { return fmt.Errorf("unable to get wd: %w", err) } - return sh.RunV("docker", "run", "--rm", - "-u", userInfo.Uid+":"+userInfo.Gid, + args := []string{"run", "--rm", + "-u", userInfo.Uid + ":" + userInfo.Gid, "--env=GOCACHE=/go/cache", - "--volume", pwd+":/fleet-server/", - "-e", envPlatforms+"="+strings.Join(getPlatforms(), ","), - "-e", envDev+"="+strconv.FormatBool(isDEV()), - "-e", envFIPS+"="+strconv.FormatBool(isFIPS()), - "-e", envSnapshot+"="+strconv.FormatBool(isSnapshot()), - "-e", envVersionQualifier+"="+os.Getenv(envVersionQualifier), - dockerBuilderName+":"+getGoVersion(), target, - ) + "--volume", pwd + ":/fleet-server/", + "-e", envPlatforms + "=" + strings.Join(getPlatforms(), ","), + "-e", envDev + "=" + strconv.FormatBool(isDEV()), + "-e", envFIPS + "=" + strconv.FormatBool(isFIPS()), + "-e", envSnapshot + "=" + strconv.FormatBool(isSnapshot()), + "-e", envVersionQualifier + "=" + os.Getenv(envVersionQualifier), + } + for _, vol := range gitAlternatesVolumeMounts() { + args = append(args, "--volume", vol) + } + args = append(args, dockerBuilderName+":"+getGoVersion(), target) + return sh.RunV("docker", args...) +} + +// gitAlternatesVolumeMounts returns docker --volume args for paths listed in +// .git/objects/info/alternates that exist on the host, so the container can +// access them at the same path (required for Go VCS stamping when using git alternates). +func gitAlternatesVolumeMounts() []string { + alternatesPath := filepath.Join(".git", "objects", "info", "alternates") + data, err := os.ReadFile(alternatesPath) + if err != nil { + return nil + } + infoDir := filepath.Dir(alternatesPath) + var mounts []string + scanner := bufio.NewScanner(bytes.NewReader(data)) + for scanner.Scan() { + path := strings.TrimSpace(scanner.Text()) + if path == "" || strings.HasPrefix(path, "#") { + continue + } + // Path in alternates is relative to .git/objects/info or absolute. + if !filepath.IsAbs(path) { + path = filepath.Join(infoDir, path) + } + path, err = filepath.Abs(path) + if err != nil { + continue + } + info, err := os.Stat(path) + if err != nil || !info.IsDir() { + continue + } + // Mount host path to same path in container so Go's VCS resolution works. + mounts = append(mounts, path+":"+path) + } + return mounts } // Binary builds binaries within a docker image produced by docker:builder.