Skip to content

Commit 7da3f69

Browse files
fix: package fleet-server using golang-crossbuild (#5392)
* fix: package fleet-server using golang-crossbuild and introduce packaging steps on every PR * feat: save artifacts during packaging for DRA * fix: disable CGO and buildmode pie * doc: add changelog fragment
1 parent 1d8dafd commit 7da3f69

File tree

6 files changed

+94
-29
lines changed

6 files changed

+94
-29
lines changed

.buildkite/pipeline.package.mbp.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ steps:
2626
provider: "gcp"
2727
image: "${IMAGE_UBUNTU_X86_64}"
2828
machineType: "c2-standard-16"
29+
artifact_paths:
30+
- build/distributions/**
2931
plugins:
3032
- *oidc_plugin
3133

@@ -38,6 +40,8 @@ steps:
3840
provider: "gcp"
3941
image: "${IMAGE_UBUNTU_X86_64}"
4042
machineType: "c2-standard-16"
43+
artifact_paths:
44+
- build/distributions/**
4145
plugins:
4246
- *oidc_plugin
4347

@@ -51,6 +55,8 @@ steps:
5155
provider: "gcp"
5256
image: "${IMAGE_UBUNTU_X86_64}"
5357
machineType: "c2-standard-16"
58+
artifact_paths:
59+
- build/distributions/**
5460
plugins:
5561
- *oidc_plugin
5662

@@ -65,6 +71,8 @@ steps:
6571
provider: "gcp"
6672
image: "${IMAGE_UBUNTU_X86_64}"
6773
machineType: "c2-standard-16"
74+
artifact_paths:
75+
- build/distributions/**
6876
plugins:
6977
- *oidc_plugin
7078

@@ -76,6 +84,8 @@ steps:
7684
provider: "aws"
7785
imagePrefix: "${IMAGE_UBUNTU_ARM_64}"
7886
instanceType: "t4g.2xlarge"
87+
artifact_paths:
88+
- build/distributions/**
7989
plugins:
8090
- *oidc_plugin
8191

@@ -88,6 +98,8 @@ steps:
8898
provider: "aws"
8999
imagePrefix: "${IMAGE_UBUNTU_ARM_64}"
90100
instanceType: "t4g.2xlarge"
101+
artifact_paths:
102+
- build/distributions/**
91103
plugins:
92104
- *oidc_plugin
93105

@@ -101,6 +113,8 @@ steps:
101113
provider: "aws"
102114
imagePrefix: "${IMAGE_UBUNTU_ARM_64}"
103115
instanceType: "t4g.2xlarge"
116+
artifact_paths:
117+
- build/distributions/**
104118
plugins:
105119
- *oidc_plugin
106120

@@ -115,6 +129,8 @@ steps:
115129
provider: "aws"
116130
imagePrefix: "${IMAGE_UBUNTU_ARM_64}"
117131
instanceType: "t4g.2xlarge"
132+
artifact_paths:
133+
- build/distributions/**
118134
plugins:
119135
- *oidc_plugin
120136

.buildkite/pipeline.yml

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
env:
44
DOCKER_COMPOSE_VERSION: "1.25.5"
55
TERRAFORM_VERSION: "1.6.4"
6+
IMAGE_UBUNTU_X86_64: "family/core-ubuntu-2204"
7+
IMAGE_UBUNTU_ARM_64: "core-ubuntu-2204-aarch64"
68
IMAGE_UBUNTU_X86_64_FIPS: "platform-ingest-fleet-server-ubuntu-2204-fips"
79

810
# This section is used to define the plugins that will be used in the pipeline.
@@ -22,6 +24,13 @@ common:
2224
- docker_elastic_login_plugin: &docker_elastic_login_plugin
2325
elastic/vault-docker-login#v0.6.0:
2426
secret_path: 'kv/ci-shared/platform-ingest/elastic_docker_registry'
27+
# See https://github.com/elastic/oblt-infra/blob/main/conf/resources/repos/fleet-server/01-gcp-buildkite-oidc.tf
28+
# This plugin authenticates to Google Cloud using the OIDC token.
29+
- oidc_plugin: &oidc_plugin
30+
elastic/oblt-google-auth#v1.2.0:
31+
lifetime: 10800 # seconds
32+
project-id: "elastic-observability-ci"
33+
project-number: "911195782929"
2534

2635
steps:
2736
- group: "Check and build"
@@ -33,18 +42,63 @@ steps:
3342
agents:
3443
provider: "gcp"
3544

36-
- label: ":building_construction: Run local build"
37-
key: make-local
38-
command: ".buildkite/scripts/local_build.sh"
45+
- label: "Package x86_64"
46+
key: "package-x86-64-pr"
47+
env:
48+
PLATFORMS: "linux/amd64,darwin/amd64,windows/amd64"
49+
command: ".buildkite/scripts/release_test.sh"
50+
artifact_paths:
51+
- build/distributions/**
3952
agents:
4053
provider: "gcp"
54+
image: "${IMAGE_UBUNTU_X86_64}"
55+
machineType: "c2-standard-16"
56+
plugins:
57+
- *oidc_plugin
4158

42-
- label: ":building_construction: Run local build: MacOS"
43-
key: make-local-macos
44-
command: ".buildkite/scripts/local_build.sh"
59+
- label: "Package x86_64 FIPS"
60+
key: "package-fips-x86-64-pr"
61+
env:
62+
FIPS: "true"
63+
PLATFORMS: "linux/amd64"
64+
command: ".buildkite/scripts/release_test.sh"
65+
artifact_paths:
66+
- build/distributions/**
4567
agents:
46-
provider: orka
47-
imagePrefix: generic-13-ventura-arm
68+
provider: "gcp"
69+
image: "${IMAGE_UBUNTU_X86_64}"
70+
machineType: "c2-standard-16"
71+
plugins:
72+
- *oidc_plugin
73+
74+
- label: "Package aarch64"
75+
key: "package-arm64-pr"
76+
env:
77+
PLATFORMS: "linux/arm64,darwin/arm64"
78+
command: ".buildkite/scripts/release_test.sh"
79+
artifact_paths:
80+
- build/distributions/**
81+
agents:
82+
provider: "aws"
83+
imagePrefix: "${IMAGE_UBUNTU_ARM_64}"
84+
instanceType: "t4g.2xlarge"
85+
plugins:
86+
- *oidc_plugin
87+
88+
- label: "Package aarch64 FIPS"
89+
key: "package-fips-arm64-pr"
90+
env:
91+
FIPS: "true"
92+
PLATFORMS: "linux/arm64"
93+
command: ".buildkite/scripts/release_test.sh"
94+
artifact_paths:
95+
- build/distributions/**
96+
agents:
97+
provider: "aws"
98+
imagePrefix: "${IMAGE_UBUNTU_ARM_64}"
99+
instanceType: "t4g.2xlarge"
100+
plugins:
101+
- *oidc_plugin
48102

49103
- group: "Performance test"
50104
key: "performance-test"
@@ -295,22 +349,6 @@ steps:
295349
depends_on:
296350
- step: "publish"
297351

298-
- label: ":gcloud: Release test"
299-
key: "release-test"
300-
command: ".buildkite/scripts/release_test.sh"
301-
agents:
302-
provider: "gcp"
303-
depends_on:
304-
- step: "tests"
305-
allow_failure: false
306-
plugins:
307-
# See https://github.com/elastic/oblt-infra/blob/main/conf/resources/repos/fleet-server/01-gcp-buildkite-oidc.tf
308-
# This plugin authenticates to Google Cloud using the OIDC token.
309-
- elastic/oblt-google-auth#v1.2.0:
310-
lifetime: 10800 # seconds
311-
project-id: "elastic-observability-ci"
312-
project-number: "911195782929"
313-
314352
- label: ":jenkins: Release - Package Registry Distribution"
315353
key: "release-package-registry"
316354
trigger: "package-registry-release-package-registry-distribution"

.buildkite/scripts/package.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ with_mage
3535
case "${TYPE}" in
3636
"snapshot")
3737
export SNAPSHOT=true
38-
mage build:release
38+
mage docker:release
3939
;;
4040
"staging")
41-
mage build:release
41+
mage docker:release
4242
;;
4343
*)
4444
echo "The option is unsupported yet"

Dockerfile.fips

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ARG SUFFIX
2929
FROM docker.elastic.co/beats-dev/golang-crossbuild:${GO_VERSION}-${SUFFIX} AS builder
3030

3131
WORKDIR /fleet-server
32-
32+
ENV PATH="$PATH:/go/bin"
3333
COPY go.mod go.sum ./
3434
RUN go mod download && go mod verify
3535
RUN go install github.com/magefile/mage # uses version in go.mod
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: bug-fix
2+
summary: Build fleet-server as fully static binary to restore OS matrix compatibility
3+
component: fleet-server
4+
pr: https://github.com/elastic/fleet-server/pull/5392
5+
issue: https://github.com/elastic/fleet-server/issues/5262

magefile.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ const (
9090

9191
// const and vars used by magefile.
9292
const (
93-
buildMode = "pie"
9493
binaryName = "fleet-server"
9594
binaryExe = "fleet-server.exe"
9695

@@ -671,6 +670,7 @@ func (Check) All() {
671670
// FIPS creates a FIPS capable binary.
672671
func (Build) Local() error {
673672
env := environMap()
673+
env["CGO_ENABLED"] = "0"
674674
if isFIPS() {
675675
addFIPSEnvVars(env)
676676
}
@@ -704,6 +704,7 @@ func goBuild(osArg, archArg string, cover bool) error {
704704
env := environMap()
705705
env["GOOS"] = osArg
706706
env["GOARCH"] = archArg
707+
env["CGO_ENABLED"] = "0"
707708
distArr := []string{"fleet-server"}
708709
if isFIPS() {
709710
addFIPSEnvVars(env)
@@ -729,7 +730,6 @@ func goBuild(osArg, archArg string, cover bool) error {
729730
"-tags=" + getTagsString(),
730731
"-gcflags=" + getGCFlags(),
731732
"-ldflags=" + getLDFlags(),
732-
"-buildmode=" + buildMode,
733733
"-o", outFile,
734734
}
735735
if cover {
@@ -1007,9 +1007,14 @@ func (Docker) Image() error {
10071007
} else if isDEV() {
10081008
version += "-dev"
10091009
}
1010+
suffix := dockerSuffix
1011+
if runtime.GOARCH == "arm64" {
1012+
suffix = dockerArmSuffix
1013+
}
10101014
if isFIPS() {
10111015
dockerFile = dockerBuilderFIPS
10121016
image += "-fips"
1017+
suffix += "-fips"
10131018
}
10141019
if v, ok := os.LookupEnv(envDockerImage); ok && v != "" {
10151020
image = v
@@ -1023,6 +1028,7 @@ func (Docker) Image() error {
10231028
"--build-arg", "VERSION="+getVersion(),
10241029
"--build-arg", "GCFLAGS="+getGCFlags(),
10251030
"--build-arg", "LDFLAGS="+getLDFlags(),
1031+
"--build-arg", "SUFFIX="+suffix,
10261032
"-f", dockerFile,
10271033
"-t", image+":"+version,
10281034
".",

0 commit comments

Comments
 (0)