@@ -886,51 +886,100 @@ func (Cloud) Image(ctx context.Context) {
886886 Package (ctx )
887887}
888888
889+ << << << < HEAD
890+ == == == =
891+ // Load loads an artifact as a docker image.
892+ // Looks in build/distributions for an elastic-agent-cloud*.docker.tar.gz artifact and imports it as docker.elastic.co/beats-ci/elastic-agent-cloud:$VERSION
893+ // DOCKER_IMPORT_SOURCE - override source for import
894+ func (Cloud ) Load () error {
895+ agentVersion , err := mage .AgentPackageVersion ()
896+ if err != nil {
897+ return fmt .Errorf ("failed to get agent package version: %w" , err )
898+ }
899+
900+ // Need to get the FIPS env var flag to see if we are using the normal source cloud image name, or the FIPS variant
901+ fips := os .Getenv (fipsEnv )
902+ defer os .Setenv (fipsEnv , fips )
903+ fipsVal , err := strconv .ParseBool (fips )
904+ if err != nil {
905+ fipsVal = false
906+ }
907+ if err := os .Setenv (fipsEnv , strconv .FormatBool (fipsVal )); err != nil {
908+ return fmt .Errorf ("failed to set fips env var: %w" , err )
909+ }
910+ devtools .FIPSBuild = fipsVal
911+
912+ source := "build/distributions/elastic-agent-cloud-" + agentVersion + "-SNAPSHOT-linux-" + runtime .GOARCH + ".docker.tar.gz"
913+ if fipsVal {
914+ source = "build/distributions/elastic-agent-cloud-fips-" + agentVersion + "-SNAPSHOT-linux-" + runtime .GOARCH + ".docker.tar.gz"
915+ }
916+ if envSource , ok := os .LookupEnv ("DOCKER_IMPORT_SOURCE" ); ok && envSource != "" {
917+ source = envSource
918+ }
919+
920+ return sh .RunV ("docker" , "image" , "load" , "-i" , source )
921+ }
922+
923+ >> >> >> > 5 c5b174ae (ci : pin elastic - agent version (#8736 ))
889924// Push builds a cloud image tags it correctly and pushes to remote image repo.
890925// Previous login to elastic registry is required!
891926func (Cloud ) Push () error {
892- snapshot := os .Getenv (snapshotEnv )
893- defer os .Setenv (snapshotEnv , snapshot )
927+ agentVersion , err := mage .AgentPackageVersion ()
928+ if err != nil {
929+ return fmt .Errorf ("failed to get agent package version: %w" , err )
930+ }
894931
895- os .Setenv (snapshotEnv , "true" )
932+ << << << < HEAD
933+ sourceCloudImageName := fmt .Sprintf ("docker.elastic.co/beats-ci/elastic-agent-cloud:%s" , version )
934+ == == == =
935+ // Need to get the FIPS env var flag to see if we are using the normal source cloud image name, or the FIPS variant
936+ fips := os .Getenv (fipsEnv )
937+ defer os .Setenv (fipsEnv , fips )
938+ fipsVal , err := strconv .ParseBool (fips )
939+ if err != nil {
940+ fipsVal = false
941+ }
942+ if err := os .Setenv (fipsEnv , strconv .FormatBool (fipsVal )); err != nil {
943+ return fmt .Errorf ("failed to set fips env var: %w" , err )
944+ }
945+ devtools .FIPSBuild = fipsVal
896946
897- version := getVersion ()
898- var tag string
947+ sourceCloudImageName := fmt .Sprintf ("docker.elastic.co/beats-ci/elastic-agent-cloud:%s-SNAPSHOT" , agentVersion )
948+ if fipsVal {
949+ sourceCloudImageName = fmt .Sprintf ("docker.elastic.co/beats-ci/elastic-agent-cloud-fips:%s-SNAPSHOT" , agentVersion )
950+ }
951+ var targetTag string
899952 if envTag , isPresent := os .LookupEnv ("CUSTOM_IMAGE_TAG" ); isPresent && len (envTag ) > 0 {
900- tag = envTag
953+ targetTag = envTag
901954 } else {
902- commit := dockerCommitHash ()
903- time := time .Now ().Unix ()
904-
905- tag = fmt .Sprintf ("%s-%s-%d" , version , commit , time )
955+ targetTag = fmt .Sprintf ("%s-%s-%d" , agentVersion , dockerCommitHash (), time .Now ().Unix ())
906956 }
907-
908- sourceCloudImageName := fmt .Sprintf ("docker.elastic.co/beats-ci/elastic-agent-cloud:%s" , version )
957+ >> >> >> > 5 c5b174ae (ci : pin elastic - agent version (#8736 ))
909958 var targetCloudImageName string
910959 if customImage , isPresent := os .LookupEnv ("CI_ELASTIC_AGENT_DOCKER_IMAGE" ); isPresent && len (customImage ) > 0 {
911- targetCloudImageName = fmt .Sprintf ("%s:%s" , customImage , tag )
960+ targetCloudImageName = fmt .Sprintf ("%s:%s" , customImage , targetTag )
912961 } else {
913- targetCloudImageName = fmt .Sprintf (cloudImageTmpl , tag )
962+ targetCloudImageName = fmt .Sprintf (cloudImageTmpl , targetTag )
914963 }
915964
916965 fmt .Printf (">> Setting a docker image tag to %s\n " , targetCloudImageName )
917966 err := sh .RunV ("docker" , "tag" , sourceCloudImageName , targetCloudImageName )
918967 if err != nil {
919- return fmt .Errorf ("Failed setting a docker image tag: %w" , err )
968+ return fmt .Errorf ("failed setting a docker image tag: %w" , err )
920969 }
921970 fmt .Println (">> Docker image tag updated successfully" )
922971
923972 fmt .Println (">> Pushing a docker image to remote registry" )
924973 err = sh .RunV ("docker" , "image" , "push" , targetCloudImageName )
925974 if err != nil {
926- return fmt .Errorf ("Failed pushing docker image: %w" , err )
975+ return fmt .Errorf ("failed pushing docker image: %w" , err )
927976 }
928977 fmt .Printf (">> Docker image pushed to remote registry successfully: %s\n " , targetCloudImageName )
929978
930979 return nil
931980}
932981
933- // Creates a new devmachine that will be auto-deleted in 6 hours.
982+ // Create a new devmachine that will be auto-deleted in 6 hours.
934983// Example: MACHINE_IMAGE="family/platform-ingest-elastic-agent-ubuntu-2204" ZONE="us-central1-a" mage devmachine:create "pavel-dev-machine"
935984// ZONE defaults to 'us-central1-a', MACHINE_IMAGE defaults to 'family/platform-ingest-elastic-agent-ubuntu-2204'
936985func (Devmachine ) Create (instanceName string ) error {
0 commit comments