Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .buildkite/scripts/build_push_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ with_mage
echo "Building the docker image..."
if ! docker pull -q ${DOCKER_IMAGE}:${DOCKER_IMAGE_SHA_TAG} 2> /dev/null; then
DOCKER_IMAGE_TAG="${DOCKER_IMAGE_SHA_TAG}"
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} mage docker:image docker:push
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} mage docker:publish
fi

if [[ "${DOCKER_IMAGE_GIT_TAG}" == "main" ]]; then
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_LATEST_TAG}" mage docker:image docker:push
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_LATEST_TAG}" mage docker:publish
elif [[ ${BUILDKITE_PULL_REQUEST} == "false" ]]; then
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_GIT_TAG}" mage docker:image docker:push
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_GIT_TAG}" mage docker:publish
fi
70 changes: 70 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const (
dockerBuilderName = "fleet-server-builder"
dockerImage = "docker.elastic.co/beats-ci/elastic-agent-cloud-fleet"
dockerAgentImage = "fleet-server-e2e-agent"
dockerFleetImage = "docker.elastic.co/observability-ci/fleet-server"
)

// e2e test certs
Expand Down Expand Up @@ -128,6 +129,12 @@ var (
"linux/arm64",
}

// platformsDocker is the list of all platforms that are supported by docker multiplatform builds.
platformsDocker = []string{
"linux/amd64",
"linux/arm64",
}

// platformRemap contains mappings for platforms where if the GOOS/GOARCH key is used, artifacts should use the value instead. Missing keys are unalted.
platformRemap = map[string]string{
"darwin/amd64": "darwin/x86_64",
Expand Down Expand Up @@ -278,6 +285,26 @@ var (
return list
})

// getDockerPlatforms returns a list of supported docker multiplatform targets.
getDockerPlatforms = sync.OnceValue(func() []string {
list := platformsDocker
if pList, ok := os.LookupEnv(envPlatforms); ok {
filtered := make([]string, 0)
for _, plat := range strings.Split(pList, ",") {
if slices.Contains(list, plat) {
filtered = append(filtered, plat)
} else {
log.Printf("Skipping %q platform is not in the list of allowed platforms.", plat)
}
}
if len(filtered) > 0 {
return filtered
}
log.Printf("%s env var detected but value %q does not contain valid platforms. Using default list.", envPlatforms, pList)
}
return list
})

// isFIPS returns a bool indicator of the FIPS env var.
isFIPS = sync.OnceValue(func() bool {
return envToBool(envFIPS)
Expand Down Expand Up @@ -1002,6 +1029,49 @@ func (Docker) Image() error {
)
}

// Publish creates a multiplatform images and pushes them to the registry.
// The name of the image is docker.elastic.co/observability-ci/fleet-server by default.
// FIPS creates a FIPS capable image, adds the -fips suffix to the image name.
// DEV creates a development image.
// SNAPSHOT creates a snapshot image.
// VERSION_QUALIFIER may be used to manually specify a version qualifer for the image tag.
// DOCKER_IMAGE may be used to completely specify the image name.
// DOCKER_IMAGE_TAG may be used to completely specify the image tag.
// PLATFORMS may be used to specify multiplatform build targets. Defaults to [linux/amd64, linux/arm64].
func (Docker) Publish() error {
dockerFile := "Dockerfile"
image := dockerFleetImage
version := getVersion()
if v, ok := os.LookupEnv(envDockerTag); ok && v != "" {
version = v
}
if isFIPS() {
dockerFile = dockerBuilderFIPS
image += "-fips"
}
if v, ok := os.LookupEnv(envDockerImage); ok && v != "" {
image = v
}
dockerEnv := map[string]string{"DOCKER_BUILDKIT": "1"}
if err := sh.RunWithV(dockerEnv, "docker", "buildx", "create", "--use"); err != nil {
return fmt.Errorf("docker buildx create failed: %w", err)
}

return sh.RunWithV(dockerEnv, "docker", "buildx", "build", "--push",
"--platform", strings.Join(getDockerPlatforms(), ","),
"--build-arg", "GO_VERSION="+getGoVersion(),
"--build-arg", "DEV="+strconv.FormatBool(isDEV()),
"--build-arg", "FIPS="+strconv.FormatBool(isFIPS()),
"--build-arg", "SNAPSHOT="+strconv.FormatBool(isSnapshot()),
"--build-arg", "VERSION="+getVersion(),
"--build-arg", "GCFLAGS="+getGCFlags(),
"--build-arg", "LDFLAGS="+getLDFlags(),
"-f", dockerFile,
"-t", image+":"+version,
".",
)
}

// Push pushs an image created by docker:image to the registry.
// FIPS may be used to push a FIPS capable image.
// DOCKER_IMAGE may be used to specify the image name.
Expand Down
Loading