Skip to content

Commit

Permalink
added tag and push
Browse files Browse the repository at this point in the history
  • Loading branch information
oakrizan committed May 16, 2024
1 parent 1a46e70 commit 9252aab
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 39 deletions.
30 changes: 30 additions & 0 deletions .buildkite/filebeat/scripts/packaging/package-util.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -euo pipefail

is_pr() {
if [[ $BUILDKITE_PULL_REQUEST != false ]]; then
return 0
else
return 1
fi
}

define_tags() {
aliasVersion="${VERSION%.*}${IMG_POSTFIX}"
tags=("${BUILDKITE_COMMIT}")

if is_pr; then
tags+=("pr-${GITHUB_PR_NUMBER}")
else
tags+=("${SOURCE_TAG}" "${aliasVersion}")
fi
}

check_is_arm() {
if [[ ${HW_TYPE} == "aarch64" || ${HW_TYPE} == "arm64" ]]; then
is_arm="-arm"
else
is_arm=""
fi
}
71 changes: 32 additions & 39 deletions .buildkite/filebeat/scripts/packaging/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,54 @@

set -euo pipefail

#source .buildkite/env-scripts/linux-env.sh
source .buildkite/env-scripts/util.sh
source .buildkite/env-scripts/linux-env.sh
source .buildkite/filebeat/scripts/packaging/package-util.sh

IMG_POSTFIX="-BK-SNAPSHOT"
IMG_POSTFIX="-SNAPSHOT"
VARIANTS=("" "-ubi" "-oss")
VERSION="$(make get-version)"
SOURCE_TAG+="${VERSION}${IMG_POSTFIX}"
BEAT_NAME="filebeat"
TARGET="observability-ci/${BEAT_NAME}"
# Remove following once beats fully migrated
BK_IMG_POSTFIX="-BK-SNAPSHOT"
BK_SOURCE_TAG+="${VERSION}${BK_IMG_POSTFIX}"

define_tags() {
aliasVersion="${VERSION%.*}${IMG_POSTFIX}"
tags=("${BUILDKITE_COMMIT}")
echo "--- Creating package"
mage -d filebeat package

if is_pr; then
tags+=("pr-${GITHUB_PR_NUMBER}")
else
tags+=("${SOURCE_TAG}" "${aliasVersion}")
fi
}
echo "--- Distribution list"
ls -la filebeat/build/distributions

check_is_arm() {
if [[ ${HW_TYPE} == "aarch64" || ${HW_TYPE} == "arm64" ]]; then
is_arm="-arm"
else
is_arm=""
fi
}
echo "--- Docker image list"
docker images

define_tags
check_is_arm

for variant in "${VARIANTS[@]}"; do
echo "--- PARAMS for variant: $variant"

check_is_arm
registry=${DOCKER_REGISTRY}
sourceTag=$SOURCE_TAG
source="beats/${BEAT_NAME}${variant}"
target=$TARGET

echo "Registry: $registry"
echo "Source: $source"
echo "Source tag: $sourceTag"
echo "Target: $target"

for tag in "${tags[@]}"; do
targetTag=$tag${is_arm}
echo "Target tag: $targetTag"
targetTag=$tag${is_arm}

sourceName="${DOCKER_REGISTRY}/${source}:${SOURCE_TAG}"
targetName="${DOCKER_REGISTRY}/${TARGET}:${targetTag}"

if docker image inspect "${sourceName}" &>/dev/null; then
echo "--- Tag & Push"
echo "Source name: $sourceName"
echo "Target name: $targetName"

# Remove following lines once beats fully migrated
bkSourceName="${DOCKER_REGISTRY}/${source}:${BK_SOURCE_TAG}"
docker tag "$sourceName" "$bkSourceName"
# Replace bkSourceName to sourceName once beats fully migrated
docker tag "${bkSourceName}" "${targetName}"
# docker push "${targetName}"
else
echo "Docker image ${sourceName} does not exist"
fi
done
done

#echo "--- Creating package"
#mage -d filebeat package

#echo "--- Setting git config"
#set_git_config

#buildkite-agent annotate "Tag '$TAG' has been created." --style 'success' --context 'ctx-success'

0 comments on commit 9252aab

Please sign in to comment.