@@ -996,11 +996,10 @@ 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- snapshot := os .Getenv (snapshotEnv )
1000- defer os .Setenv (snapshotEnv , snapshot )
1001- os .Setenv (snapshotEnv , "true" )
1002-
1003- version := getVersion ()
999+ agentVersion , err := mage .AgentPackageVersion ()
1000+ if err != nil {
1001+ return fmt .Errorf ("failed to get agent package version: %w" , err )
1002+ }
10041003
10051004 // Need to get the FIPS env var flag to see if we are using the normal source cloud image name, or the FIPS variant
10061005 fips := os .Getenv (fipsEnv )
@@ -1009,12 +1008,14 @@ func (Cloud) Load() error {
10091008 if err != nil {
10101009 fipsVal = false
10111010 }
1012- os .Setenv (fipsEnv , strconv .FormatBool (fipsVal ))
1011+ if err := os .Setenv (fipsEnv , strconv .FormatBool (fipsVal )); err != nil {
1012+ return fmt .Errorf ("failed to set fips env var: %w" , err )
1013+ }
10131014 devtools .FIPSBuild = fipsVal
10141015
1015- source := "build/distributions/elastic-agent-cloud-" + version + "-linux-" + runtime .GOARCH + ".docker.tar.gz"
1016+ source := "build/distributions/elastic-agent-cloud-" + agentVersion + "-SNAPSHOT -linux-" + runtime .GOARCH + ".docker.tar.gz"
10161017 if fipsVal {
1017- source = "build/distributions/elastic-agent-cloud-fips-" + version + "-linux-" + runtime .GOARCH + ".docker.tar.gz"
1018+ source = "build/distributions/elastic-agent-cloud-fips-" + agentVersion + "-SNAPSHOT -linux-" + runtime .GOARCH + ".docker.tar.gz"
10181019 }
10191020 if envSource , ok := os .LookupEnv ("DOCKER_IMPORT_SOURCE" ); ok && envSource != "" {
10201021 source = envSource
@@ -1026,20 +1027,9 @@ func (Cloud) Load() error {
10261027// Push builds a cloud image tags it correctly and pushes to remote image repo.
10271028// Previous login to elastic registry is required!
10281029func (Cloud ) Push () error {
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 )
1030+ agentVersion , err := mage .AgentPackageVersion ()
1031+ if err != nil {
1032+ return fmt .Errorf ("failed to get agent package version: %w" , err )
10431033 }
10441034
10451035 // Need to get the FIPS env var flag to see if we are using the normal source cloud image name, or the FIPS variant
@@ -1049,38 +1039,46 @@ func (Cloud) Push() error {
10491039 if err != nil {
10501040 fipsVal = false
10511041 }
1052- os .Setenv (fipsEnv , strconv .FormatBool (fipsVal ))
1042+ if err := os .Setenv (fipsEnv , strconv .FormatBool (fipsVal )); err != nil {
1043+ return fmt .Errorf ("failed to set fips env var: %w" , err )
1044+ }
10531045 devtools .FIPSBuild = fipsVal
10541046
1055- sourceCloudImageName := fmt .Sprintf ("docker.elastic.co/beats-ci/elastic-agent-cloud:%s" , version )
1047+ sourceCloudImageName := fmt .Sprintf ("docker.elastic.co/beats-ci/elastic-agent-cloud:%s-SNAPSHOT " , agentVersion )
10561048 if fipsVal {
1057- sourceCloudImageName = fmt .Sprintf ("docker.elastic.co/beats-ci/elastic-agent-cloud-fips:%s" , version )
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 ())
10581056 }
10591057 var targetCloudImageName string
10601058 if customImage , isPresent := os .LookupEnv ("CI_ELASTIC_AGENT_DOCKER_IMAGE" ); isPresent && len (customImage ) > 0 {
1061- targetCloudImageName = fmt .Sprintf ("%s:%s" , customImage , tag )
1059+ targetCloudImageName = fmt .Sprintf ("%s:%s" , customImage , targetTag )
10621060 } else {
1063- targetCloudImageName = fmt .Sprintf (cloudImageTmpl , tag )
1061+ targetCloudImageName = fmt .Sprintf (cloudImageTmpl , targetTag )
10641062 }
10651063
10661064 fmt .Printf (">> Setting a docker image tag to %s\n " , targetCloudImageName )
10671065 err = sh .RunV ("docker" , "tag" , sourceCloudImageName , targetCloudImageName )
10681066 if err != nil {
1069- return fmt .Errorf ("Failed setting a docker image tag: %w" , err )
1067+ return fmt .Errorf ("failed setting a docker image tag: %w" , err )
10701068 }
10711069 fmt .Println (">> Docker image tag updated successfully" )
10721070
10731071 fmt .Println (">> Pushing a docker image to remote registry" )
10741072 err = sh .RunV ("docker" , "image" , "push" , targetCloudImageName )
10751073 if err != nil {
1076- return fmt .Errorf ("Failed pushing docker image: %w" , err )
1074+ return fmt .Errorf ("failed pushing docker image: %w" , err )
10771075 }
10781076 fmt .Printf (">> Docker image pushed to remote registry successfully: %s\n " , targetCloudImageName )
10791077
10801078 return nil
10811079}
10821080
1083- // Creates a new devmachine that will be auto-deleted in 6 hours.
1081+ // Create a new devmachine that will be auto-deleted in 6 hours.
10841082// Example: MACHINE_IMAGE="family/platform-ingest-elastic-agent-ubuntu-2204" ZONE="us-central1-a" mage devmachine:create "pavel-dev-machine"
10851083// ZONE defaults to 'us-central1-a', MACHINE_IMAGE defaults to 'family/platform-ingest-elastic-agent-ubuntu-2204'
10861084func (Devmachine ) Create (instanceName string ) error {
0 commit comments