Skip to content

Instantly share code, notes, and snippets.

@ncknt
Last active June 19, 2020 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncknt/37b1743111eb727bcd81e21dffda90d6 to your computer and use it in GitHub Desktop.
Save ncknt/37b1743111eb727bcd81e21dffda90d6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script download a version of Armory's BOM to a local directory
# Usage: download.sh <version name> <destination path>
# Prerequisites:
# - aws cli: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
# - access to public s3 installed (no need for credentials)
# - write access to the destination path
# Change that
NEW_DOCKER_REGISTRY="docker.io/armory"
PGM=$0
VERSION=$1
DESTINATION_DIR=$2
ARMORY_BUCKET="halconfig"
ARMORY_BUCKET_REGION="us-west-2"
SERVICES="clouddriver echo gate orca igor deck fiat front50 kayenta rosco monitoring-daemon dinghy terraformer"
if [[ $# -lt 2 ]]; then
echo "Usage: ${PGM} <version name> <destination path>"
exit 1
fi
if [[ -f $DESTINATION_DIR ]]; then
echo "${DESTINATION_DIR} is a file."
exit 1
fi
mkdir -p ${DESTINATION_DIR}/bom
bom="${DESTINATION_DIR}/bom/${VERSION}.yml"
aws s3 cp --no-sign-request --region ${ARMORY_BUCKET_REGION} s3://${ARMORY_BUCKET}/bom/${VERSION}.yml ${bom}
for svc in $SERVICES; do
sv=$(grep -A 1 ${svc} ${bom} | awk '/version/ {print $2}' | cut -f1 -d"-")
sdir="$DESTINATION_DIR/profiles/${svc}/${sv}"
mkdir -p $sdir
aws s3 cp --no-sign-request --region ${ARMORY_BUCKET_REGION} --recursive --include "*" s3://${ARMORY_BUCKET}/profiles/${svc}/${sv}/ $sdir
done
sed -i '' "s/docker.io\\/armory/$(echo $NEW_DOCKER_REGISTRY | sed 's/\//\\\//g')/g" $bom
echo "\nVersion ${version} is ready to be uploaded to your private bucket."
echo "For example, with \"aws cp --recursive\" or \"gsutil cp -m -r ...\""
@away168
Copy link

away168 commented Jun 18, 2020

@ncknt the new bom format added 'commit' causing the grep & awk to fail on line 34

e.g.

> cat 2.19.9.yml
version: 2.19.9-rc.4
timestamp: "2020-06-04 17:31:17"
services:
  clouddriver:
    commit: 7d487dd7
    version: 2.19.20
...

@away168
Copy link

away168 commented Jun 18, 2020

alternative approach for Line 34 using yq
sv=$(yq r ${bom} 'services.'${svc}'.version')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment