diff --git a/.buildkite/scripts/steps/dra-publish.sh b/.buildkite/scripts/steps/dra-publish.sh index 11ac4fed741..238f657ac05 100755 --- a/.buildkite/scripts/steps/dra-publish.sh +++ b/.buildkite/scripts/steps/dra-publish.sh @@ -73,9 +73,6 @@ function run_release_manager_collect() { "${_dry_run}" } -echo "+++ Distribution artefacts" -ls -la ${PWD} - echo "+++ Release Manager ${WORKFLOW} / ${BRANCH} / ${COMMIT}"; run_release_manager_list "${DRA_PROJECT_ID}" "${DRA_PROJECT_ARTIFACT_ID}" "${WORKFLOW}" "${COMMIT}" "${BRANCH}" "${PACKAGE_VERSION}" run_release_manager_collect "${DRA_PROJECT_ID}" "${DRA_PROJECT_ARTIFACT_ID}" "${WORKFLOW}" "${COMMIT}" "${BRANCH}" "${PACKAGE_VERSION}" "${DRY_RUN}" diff --git a/.buildkite/scripts/steps/package.sh b/.buildkite/scripts/steps/package.sh index d08a419c0b5..57a885a451d 100755 --- a/.buildkite/scripts/steps/package.sh +++ b/.buildkite/scripts/steps/package.sh @@ -14,7 +14,7 @@ export AGENT_DROP_PATH=build/elastic-agent-drop mkdir -p $AGENT_DROP_PATH # Download the components from the ManifestURL and then package those downloaded into the $AGENT_DROP_PATH -mage clean downloadManifest package ironbank +mage clean downloadManifest package ironbank fixDRADockerArtifacts echo "+++ Generate dependencies report" BEAT_VERSION_FULL=$(curl -s -XGET "${ManifestURL}" |jq '.version' -r ) diff --git a/magefile.go b/magefile.go index 87b7db065c2..43eab063c30 100644 --- a/magefile.go +++ b/magefile.go @@ -16,6 +16,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "runtime" "strconv" "strings" @@ -443,6 +444,53 @@ func DownloadManifest() error { return nil } +// FixDRADockerArtifacts is a workaround for the DRA artifacts produced by the package target. We had to do +// because the initial unified release manager DSL code required specific names that the package does not produce, +// we wanted to keep backwards compatibility with the artifacts of the unified release and the DRA. +// this follows the same logic as https://github.com/elastic/beats/blob/2fdefcfbc783eb4710acef07d0ff63863fa00974/.ci/scripts/prepare-release-manager.sh +func FixDRADockerArtifacts() error { + fmt.Println("--- Fixing Docker DRA artifacts") + distributionsPath := filepath.Join("build", "distributions") + // Find all the files with the given name + matches, err := filepath.Glob(filepath.Join(distributionsPath, "*docker.tar.gz*")) + if err != nil { + return err + } + if mg.Verbose() { + log.Printf("--- Found artifacts to rename %s %d", distributionsPath, len(matches)) + } + // Match the artifact name and break down into groups so that we can reconstruct the names as its expected by the DRA DSL + artifactRegexp, err := regexp.Compile(`([\w+-]+)-(([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?)-([\w]+)-([\w]+)-([\w]+)\.([\w]+)\.([\w.]+)`) + if err != nil { + return err + } + for _, m := range matches { + artifactFile, err := os.Stat(m) + if err != nil { + return fmt.Errorf("failed stating file: %w", err) + } + if artifactFile.IsDir() { + continue + } + match := artifactRegexp.FindAllStringSubmatch(artifactFile.Name(), -1) + // The groups here is tightly coupled with the regexp above. + targetName := fmt.Sprintf("%s-%s-%s-%s-image-%s-%s.%s", match[0][1], match[0][2], match[0][7], match[0][10], match[0][8], match[0][9], match[0][11]) + if mg.Verbose() { + fmt.Printf("%#v\n", match) + fmt.Printf("Artifact: %s \n", artifactFile.Name()) + fmt.Printf("Renamed: %s \n", targetName) + } + renameErr := os.Rename(filepath.Join(distributionsPath, artifactFile.Name()), filepath.Join(distributionsPath, targetName)) + if renameErr != nil { + return renameErr + } + if mg.Verbose() { + fmt.Println("Renamed artifact") + } + } + return nil +} + func getPackageName(beat, version, pkg string) (string, string) { if _, ok := os.LookupEnv(snapshotEnv); ok { version += "-SNAPSHOT"