@@ -996,10 +996,11 @@ func (Cloud) Image(ctx context.Context) {
996996// 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
997997// DOCKER_IMPORT_SOURCE - override source for import
998998func (Cloud ) Load () error {
999- agentVersion , err := mage .AgentPackageVersion ()
1000- if err != nil {
1001- return fmt .Errorf ("failed to get agent package version: %w" , err )
1002- }
999+ snapshot := os .Getenv (snapshotEnv )
1000+ defer os .Setenv (snapshotEnv , snapshot )
1001+ os .Setenv (snapshotEnv , "true" )
1002+
1003+ version := getVersion ()
10031004
10041005 // Need to get the FIPS env var flag to see if we are using the normal source cloud image name, or the FIPS variant
10051006 fips := os .Getenv (fipsEnv )
@@ -1008,14 +1009,12 @@ func (Cloud) Load() error {
10081009 if err != nil {
10091010 fipsVal = false
10101011 }
1011- if err := os .Setenv (fipsEnv , strconv .FormatBool (fipsVal )); err != nil {
1012- return fmt .Errorf ("failed to set fips env var: %w" , err )
1013- }
1012+ os .Setenv (fipsEnv , strconv .FormatBool (fipsVal ))
10141013 devtools .FIPSBuild = fipsVal
10151014
1016- source := "build/distributions/elastic-agent-cloud-" + agentVersion + "-SNAPSHOT -linux-" + runtime .GOARCH + ".docker.tar.gz"
1015+ source := "build/distributions/elastic-agent-cloud-" + version + "-linux-" + runtime .GOARCH + ".docker.tar.gz"
10171016 if fipsVal {
1018- source = "build/distributions/elastic-agent-cloud-fips-" + agentVersion + "-SNAPSHOT -linux-" + runtime .GOARCH + ".docker.tar.gz"
1017+ source = "build/distributions/elastic-agent-cloud-fips-" + version + "-linux-" + runtime .GOARCH + ".docker.tar.gz"
10191018 }
10201019 if envSource , ok := os .LookupEnv ("DOCKER_IMPORT_SOURCE" ); ok && envSource != "" {
10211020 source = envSource
@@ -1027,9 +1026,20 @@ func (Cloud) Load() error {
10271026// Push builds a cloud image tags it correctly and pushes to remote image repo.
10281027// Previous login to elastic registry is required!
10291028func (Cloud ) Push () error {
1030- agentVersion , err := mage .AgentPackageVersion ()
1031- if err != nil {
1032- return fmt .Errorf ("failed to get agent package version: %w" , err )
1029+ snapshot := os .Getenv (snapshotEnv )
1030+ defer os .Setenv (snapshotEnv , snapshot )
1031+
1032+ os .Setenv (snapshotEnv , "true" )
1033+
1034+ version := getVersion ()
1035+ var tag string
1036+ if envTag , isPresent := os .LookupEnv ("CUSTOM_IMAGE_TAG" ); isPresent && len (envTag ) > 0 {
1037+ tag = envTag
1038+ } else {
1039+ commit := dockerCommitHash ()
1040+ time := time .Now ().Unix ()
1041+
1042+ tag = fmt .Sprintf ("%s-%s-%d" , version , commit , time )
10331043 }
10341044
10351045 // Need to get the FIPS env var flag to see if we are using the normal source cloud image name, or the FIPS variant
@@ -1039,46 +1049,38 @@ func (Cloud) Push() error {
10391049 if err != nil {
10401050 fipsVal = false
10411051 }
1042- if err := os .Setenv (fipsEnv , strconv .FormatBool (fipsVal )); err != nil {
1043- return fmt .Errorf ("failed to set fips env var: %w" , err )
1044- }
1052+ os .Setenv (fipsEnv , strconv .FormatBool (fipsVal ))
10451053 devtools .FIPSBuild = fipsVal
10461054
1047- sourceCloudImageName := fmt .Sprintf ("docker.elastic.co/beats-ci/elastic-agent-cloud:%s-SNAPSHOT " , agentVersion )
1055+ sourceCloudImageName := fmt .Sprintf ("docker.elastic.co/beats-ci/elastic-agent-cloud:%s" , version )
10481056 if fipsVal {
1049- sourceCloudImageName = fmt .Sprintf ("docker.elastic.co/beats-ci/elastic-agent-cloud-fips:%s-SNAPSHOT" , agentVersion )
1050- }
1051- var targetTag string
1052- if envTag , isPresent := os .LookupEnv ("CUSTOM_IMAGE_TAG" ); isPresent && len (envTag ) > 0 {
1053- targetTag = envTag
1054- } else {
1055- targetTag = fmt .Sprintf ("%s-%s-%d" , agentVersion , dockerCommitHash (), time .Now ().Unix ())
1057+ sourceCloudImageName = fmt .Sprintf ("docker.elastic.co/beats-ci/elastic-agent-cloud-fips:%s" , version )
10561058 }
10571059 var targetCloudImageName string
10581060 if customImage , isPresent := os .LookupEnv ("CI_ELASTIC_AGENT_DOCKER_IMAGE" ); isPresent && len (customImage ) > 0 {
1059- targetCloudImageName = fmt .Sprintf ("%s:%s" , customImage , targetTag )
1061+ targetCloudImageName = fmt .Sprintf ("%s:%s" , customImage , tag )
10601062 } else {
1061- targetCloudImageName = fmt .Sprintf (cloudImageTmpl , targetTag )
1063+ targetCloudImageName = fmt .Sprintf (cloudImageTmpl , tag )
10621064 }
10631065
10641066 fmt .Printf (">> Setting a docker image tag to %s\n " , targetCloudImageName )
10651067 err = sh .RunV ("docker" , "tag" , sourceCloudImageName , targetCloudImageName )
10661068 if err != nil {
1067- return fmt .Errorf ("failed setting a docker image tag: %w" , err )
1069+ return fmt .Errorf ("Failed setting a docker image tag: %w" , err )
10681070 }
10691071 fmt .Println (">> Docker image tag updated successfully" )
10701072
10711073 fmt .Println (">> Pushing a docker image to remote registry" )
10721074 err = sh .RunV ("docker" , "image" , "push" , targetCloudImageName )
10731075 if err != nil {
1074- return fmt .Errorf ("failed pushing docker image: %w" , err )
1076+ return fmt .Errorf ("Failed pushing docker image: %w" , err )
10751077 }
10761078 fmt .Printf (">> Docker image pushed to remote registry successfully: %s\n " , targetCloudImageName )
10771079
10781080 return nil
10791081}
10801082
1081- // Create a new devmachine that will be auto-deleted in 6 hours.
1083+ // Creates a new devmachine that will be auto-deleted in 6 hours.
10821084// Example: MACHINE_IMAGE="family/platform-ingest-elastic-agent-ubuntu-2204" ZONE="us-central1-a" mage devmachine:create "pavel-dev-machine"
10831085// ZONE defaults to 'us-central1-a', MACHINE_IMAGE defaults to 'family/platform-ingest-elastic-agent-ubuntu-2204'
10841086func (Devmachine ) Create (instanceName string ) error {
0 commit comments