Vendor yq program

This commit is contained in:
decentral1se 2021-03-16 05:47:13 +01:00
parent 00c8a988e1
commit 3b59adfe34
Signed by: decentral1se
GPG Key ID: 92DAD76BD9567B8A
1 changed files with 37 additions and 4 deletions

41
abra
View File

@ -4,6 +4,8 @@ GIT_URL="https://git.autonomic.zone/coop-cloud/"
ABRA_DIR="${ABRA_DIR:-$HOME/.abra}"
ABRA_VERSION="0.5.0"
ABRA_BACKUP_DIR="${ABRA_BACKUP_DIR:-$ABRA_DIR/backups}"
ABRA_VENDOR_DIR="$ABRA_DIR/vendor"
YQ="$ABRA_VENDOR_DIR/yq"
#######################################
# Global help
@ -403,9 +405,9 @@ require_pwqgen() {
fi
}
require_pwgen() {
if ! type pwgen > /dev/null 2>&1; then
error "pwgen program is not installed"
require_wget() {
if ! type wget > /dev/null 2>&1; then
error "wget program is not installed"
fi
}
@ -413,6 +415,10 @@ require_abra_dir() {
mkdir -p "$ABRA_DIR"
}
require_vendor_dir() {
mkdir -p "$ABRA_VENDOR_DIR"
}
require_app_latest() {
APP="$1"
APP_DIR="$ABRA_DIR/apps/$APP"
@ -436,6 +442,32 @@ require_app_latest() {
fi
}
require_yq() {
require_vendor_dir
require_wget
YQ_VERSION="4.6.1"
YQ_BINARY="yq_linux_amd64"
YQ_RELEASE_URL="https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/${YQ_BINARY}"
if [ -f "$YQ" ]; then
debug "yq is already vendored"
return
fi
case $(uname -m) in
x86_64)
warning "Attempting to download the yq binary into $ABRA_VENDOR_DIR"
wget -q "$YQ_RELEASE_URL" && chmod +x "$YQ_BINARY" && mv "$YQ_BINARY" "$YQ"
success "yq is now vendored ☮"
;;
*)
error "Unable to automatically vendor yq, you'll have to manually manage this\n
Please see https://mikefarah.gitbook.io/yq/#install and place the yq binary in the $YQ path"
;;
esac
}
# FIXME 3wc: update or remove
if [ -z "$ABRA_ENV" ] && [ -f .env ] && type direnv > /dev/null 2>&1 && ! direnv status | grep -q 'Found RC allowed true'; then
error "direnv is blocked, run direnv allow"
@ -465,7 +497,7 @@ output_version_summary() {
echo " Versions:"
IFS=':' read -ra COMPOSE_FILES <<< "$COMPOSE_FILE"
for COMPOSE in "${COMPOSE_FILES[@]}"; do
SERVICES=$(yq e '.services | keys | .[]' "${APP_DIR}/${COMPOSE_FILE}")
SERVICES=$($YQ e '.services | keys | .[]' "${APP_DIR}/${COMPOSE_FILE}")
for SERVICE in $SERVICES; do
filter="{{index .Spec.Labels \"coop-cloud.$STACK_NAME.$SERVICE.version\" }}"
label=$(docker service inspect -f "$filter" "${STACK_NAME}_${SERVICE}" 2>/dev/null)
@ -934,6 +966,7 @@ POWERED BY
}
sub_app_deploy (){
require_yq
require_app_latest "$TYPE"
echo "About to deploy:"