Skip to content

Commit 73a821a

Browse files
Use seperate docker:publish target for multiarch builds
1 parent df98112 commit 73a821a

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

.buildkite/scripts/build_push_docker_image.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ with_mage
1313
echo "Building the docker image..."
1414
if ! docker pull -q ${DOCKER_IMAGE}:${DOCKER_IMAGE_SHA_TAG} 2> /dev/null; then
1515
DOCKER_IMAGE_TAG="${DOCKER_IMAGE_SHA_TAG}"
16-
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} mage docker:image docker:push
16+
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} mage docker:publish
1717
fi
1818

1919
if [[ "${DOCKER_IMAGE_GIT_TAG}" == "main" ]]; then
20-
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_LATEST_TAG}" mage docker:image docker:push
20+
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_LATEST_TAG}" mage docker:publish
2121
elif [[ ${BUILDKITE_PULL_REQUEST} == "false" ]]; then
22-
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_GIT_TAG}" mage docker:image docker:push
22+
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_GIT_TAG}" mage docker:publish
2323
fi

magefile.go

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const (
101101
dockerBuilderName = "fleet-server-builder"
102102
dockerImage = "docker.elastic.co/beats-ci/elastic-agent-cloud-fleet"
103103
dockerAgentImage = "fleet-server-e2e-agent"
104+
dockerFleetImage = "docker.elastic.co/observability-ci/fleet-server"
104105
)
105106

106107
// e2e test certs
@@ -997,7 +998,6 @@ func (Docker) Cover() error {
997998
// VERSION_QUALIFIER may be used to manually specify a version qualifer for the image tag.
998999
// DOCKER_IMAGE may be used to completely specify the image name.
9991000
// DOCKER_IMAGE_TAG may be used to completely specify the image tag.
1000-
// PLATFORMS may be used to specify multiplatform build targets. Defaults to [linux/amd64, linux/arm64].
10011001
func (Docker) Image() error {
10021002
dockerFile := "Dockerfile"
10031003
image := dockerImage
@@ -1014,12 +1014,50 @@ func (Docker) Image() error {
10141014
if v, ok := os.LookupEnv(envDockerImage); ok && v != "" {
10151015
image = v
10161016
}
1017+
1018+
return sh.RunWithV(map[string]string{"DOCKER_BUILDKIT": "1"}, "docker", "build",
1019+
"--build-arg", "GO_VERSION="+getGoVersion(),
1020+
"--build-arg", "DEV="+strconv.FormatBool(isDEV()),
1021+
"--build-arg", "FIPS="+strconv.FormatBool(isFIPS()),
1022+
"--build-arg", "SNAPSHOT="+strconv.FormatBool(isSnapshot()),
1023+
"--build-arg", "VERSION="+getVersion(),
1024+
"--build-arg", "GCFLAGS="+getGCFlags(),
1025+
"--build-arg", "LDFLAGS="+getLDFlags(),
1026+
"-f", dockerFile,
1027+
"-t", image+":"+version,
1028+
".",
1029+
)
1030+
}
1031+
1032+
// Publish creates a multiplatform images and pushes them to the registry.
1033+
// The name of the image is docker.elastic.co/observability-ci/fleet-server by default.
1034+
// FIPS creates a FIPS capable image, adds the -fips suffix to the image name.
1035+
// DEV creates a development image.
1036+
// SNAPSHOT creates a snapshot image.
1037+
// VERSION_QUALIFIER may be used to manually specify a version qualifer for the image tag.
1038+
// DOCKER_IMAGE may be used to completely specify the image name.
1039+
// DOCKER_IMAGE_TAG may be used to completely specify the image tag.
1040+
// PLATFORMS may be used to specify multiplatform build targets. Defaults to [linux/amd64, linux/arm64].
1041+
func (Docker) Publish() error {
1042+
dockerFile := "Dockerfile"
1043+
image := dockerFleetImage
1044+
version := getVersion()
1045+
if v, ok := os.LookupEnv(envDockerTag); ok && v != "" {
1046+
version = v
1047+
}
1048+
if isFIPS() {
1049+
dockerFile = dockerBuilderFIPS
1050+
image += "-fips"
1051+
}
1052+
if v, ok := os.LookupEnv(envDockerImage); ok && v != "" {
1053+
image = v
1054+
}
10171055
dockerEnv := map[string]string{"DOCKER_BUILDKIT": "1"}
10181056
if err := sh.RunWithV(dockerEnv, "docker", "buildx", "create", "--use"); err != nil {
10191057
return fmt.Errorf("docker buildx create failed: %w", err)
10201058
}
10211059

1022-
return sh.RunWithV(dockerEnv, "docker", "buildx", "build",
1060+
return sh.RunWithV(dockerEnv, "docker", "buildx", "build", "--push",
10231061
"--platform", strings.Join(getDockerPlatforms(), ","),
10241062
"--build-arg", "GO_VERSION="+getGoVersion(),
10251063
"--build-arg", "DEV="+strconv.FormatBool(isDEV()),
@@ -1038,7 +1076,6 @@ func (Docker) Image() error {
10381076
// FIPS may be used to push a FIPS capable image.
10391077
// DOCKER_IMAGE may be used to specify the image name.
10401078
// DOCKER_IMAGE_TAG may be used to specify the image tag.
1041-
// PLATFORMS may be used to specify multiplatform build targets. Defaults to [linux/amd64, linux/arm64].
10421079
func (Docker) Push() error {
10431080
image := dockerImage
10441081
if isFIPS() {
@@ -1053,10 +1090,7 @@ func (Docker) Push() error {
10531090
version = v
10541091
}
10551092

1056-
return sh.RunV("docker", "push",
1057-
"--platform", strings.Join(getDockerPlatforms(), ","),
1058-
image+":"+version,
1059-
)
1093+
return sh.RunV("docker", "push", image+":"+version)
10601094
}
10611095

10621096
// CustomAgentImage creates a custom elastic-agent image where the fleet-server component has been replaced by one built locally.

0 commit comments

Comments
 (0)