Skip to content

Commit

Permalink
Add a mage target to rename the artefacts for DRA
Browse files Browse the repository at this point in the history
The existing Beats release job was performing a renaming for the docker
image artefacts in order to keep comp with the release manager. This
commit adds this functionality into a mage target rather than a bash
script

Signed-off-by: Alexandros Sapranidis <[email protected]>
  • Loading branch information
alexsapran committed Jul 24, 2023
1 parent 341fb7c commit 2cd3580
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .buildkite/scripts/steps/dra-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
48 changes: 48 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 2cd3580

Please sign in to comment.