@@ -99,6 +99,7 @@ const (
9999 dockerBuilderName = "fleet-server-builder"
100100 dockerImage = "docker.elastic.co/beats-ci/elastic-agent-cloud-fleet"
101101 dockerAgentImage = "fleet-server-e2e-agent"
102+ dockerFleetImage = "docker.elastic.co/observability-ci/fleet-server"
102103)
103104
104105// e2e test certs
@@ -126,6 +127,12 @@ var (
126127 "linux/arm64" ,
127128 }
128129
130+ // platformsDocker is the list of all platforms that are supported by docker multiplatform builds.
131+ platformsDocker = []string {
132+ "linux/amd64" ,
133+ "linux/arm64" ,
134+ }
135+
129136 // platformRemap contains mappings for platforms where if the GOOS/GOARCH key is used, artifacts should use the value instead. Missing keys are unalted.
130137 platformRemap = map [string ]string {
131138 "darwin/amd64" : "darwin/x86_64" ,
@@ -276,6 +283,26 @@ var (
276283 return list
277284 })
278285
286+ // getDockerPlatforms returns a list of supported docker multiplatform targets.
287+ getDockerPlatforms = sync .OnceValue (func () []string {
288+ list := platformsDocker
289+ if pList , ok := os .LookupEnv (envPlatforms ); ok {
290+ filtered := make ([]string , 0 )
291+ for _ , plat := range strings .Split (pList , "," ) {
292+ if slices .Contains (list , plat ) {
293+ filtered = append (filtered , plat )
294+ } else {
295+ log .Printf ("Skipping %q platform is not in the list of allowed platforms." , plat )
296+ }
297+ }
298+ if len (filtered ) > 0 {
299+ return filtered
300+ }
301+ log .Printf ("%s env var detected but value %q does not contain valid platforms. Using default list." , envPlatforms , pList )
302+ }
303+ return list
304+ })
305+
279306 // isFIPS returns a bool indicator of the FIPS env var.
280307 isFIPS = sync .OnceValue (func () bool {
281308 return envToBool (envFIPS )
@@ -999,6 +1026,49 @@ func (Docker) Image() error {
9991026 )
10001027}
10011028
1029+ // Publish creates a multiplatform images and pushes them to the registry.
1030+ // The name of the image is docker.elastic.co/observability-ci/fleet-server by default.
1031+ // FIPS creates a FIPS capable image, adds the -fips suffix to the image name.
1032+ // DEV creates a development image.
1033+ // SNAPSHOT creates a snapshot image.
1034+ // VERSION_QUALIFIER may be used to manually specify a version qualifer for the image tag.
1035+ // DOCKER_IMAGE may be used to completely specify the image name.
1036+ // DOCKER_IMAGE_TAG may be used to completely specify the image tag.
1037+ // PLATFORMS may be used to specify multiplatform build targets. Defaults to [linux/amd64, linux/arm64].
1038+ func (Docker ) Publish () error {
1039+ dockerFile := "Dockerfile"
1040+ image := dockerFleetImage
1041+ version := getVersion ()
1042+ if v , ok := os .LookupEnv (envDockerTag ); ok && v != "" {
1043+ version = v
1044+ }
1045+ if isFIPS () {
1046+ dockerFile = dockerBuilderFIPS
1047+ image += "-fips"
1048+ }
1049+ if v , ok := os .LookupEnv (envDockerImage ); ok && v != "" {
1050+ image = v
1051+ }
1052+ dockerEnv := map [string ]string {"DOCKER_BUILDKIT" : "1" }
1053+ if err := sh .RunWithV (dockerEnv , "docker" , "buildx" , "create" , "--use" ); err != nil {
1054+ return fmt .Errorf ("docker buildx create failed: %w" , err )
1055+ }
1056+
1057+ return sh .RunWithV (dockerEnv , "docker" , "buildx" , "build" , "--push" ,
1058+ "--platform" , strings .Join (getDockerPlatforms (), "," ),
1059+ "--build-arg" , "GO_VERSION=" + getGoVersion (),
1060+ "--build-arg" , "DEV=" + strconv .FormatBool (isDEV ()),
1061+ "--build-arg" , "FIPS=" + strconv .FormatBool (isFIPS ()),
1062+ "--build-arg" , "SNAPSHOT=" + strconv .FormatBool (isSnapshot ()),
1063+ "--build-arg" , "VERSION=" + getVersion (),
1064+ "--build-arg" , "GCFLAGS=" + getGCFlags (),
1065+ "--build-arg" , "LDFLAGS=" + getLDFlags (),
1066+ "-f" , dockerFile ,
1067+ "-t" , image + ":" + version ,
1068+ "." ,
1069+ )
1070+ }
1071+
10021072// Push pushs an image created by docker:image to the registry.
10031073// FIPS may be used to push a FIPS capable image.
10041074// DOCKER_IMAGE_TAG may be used to specify the image tag.
0 commit comments