From e8bb889789cbde375952ca97f8c3374fd6a27676 Mon Sep 17 00:00:00 2001 From: yage Date: Tue, 2 Aug 2022 19:08:33 -0600 Subject: [PATCH] v2.2.0 ===================================================================== --- New Scripts -------------------------- zsh ) amazon EKS - aws/eks/login --- Changes ------------------------------ - moved global .config to global/config.zsh - moved various global configurations to global/ --- Bug Fixes ---------------------------- - REDIS_AUTH no longer required to attempt connection - global configurations now propagate to non-zsh scripts --- global/common.zsh | 32 +++++++++++++++++++++++++++++ .config => global/config.zsh | 7 ++++--- py/redis/client.py | 2 +- zsh/aws/eks/common.zsh | 6 ++++++ zsh/aws/eks/login | 19 ++++++++++++++++++ zsh/common.zsh | 39 ++++++------------------------------ zsh/scwrypts/configure | 2 +- 7 files changed, 69 insertions(+), 38 deletions(-) create mode 100644 global/common.zsh rename .config => global/config.zsh (95%) create mode 100644 zsh/aws/eks/common.zsh create mode 100755 zsh/aws/eks/login diff --git a/global/common.zsh b/global/common.zsh new file mode 100644 index 0000000..656ace2 --- /dev/null +++ b/global/common.zsh @@ -0,0 +1,32 @@ +##################################################################### + +[ ! $SCWRYPTS_ROOT ] && SCWRYPTS_ROOT="$(dirname ${0:a:h})" + +source "${0:a:h}/config.zsh" + +##################################################################### + +__SCWRYPT=1 # arbitrary; indicates scwrypts exists + +__PREFERRED_PYTHON_VERSIONS=(3.10 3.9) +__NODE_VERSION=18.0.0 + +__ENV_TEMPLATE=$SCWRYPTS_ROOT/.env.template + +##################################################################### + +__RUN_SCWRYPT() { + ((SUBSCWRYPT+=1)) + printf ' '; printf '--%.0s' {1..$SUBSCWRYPT}; printf " ($SUBSCWRYPT) " + echo " BEGIN SUBSCWRYPT : $(basename $1)" + + SUBSCWRYPT=$SUBSCWRYPT SCWRYPTS_ENV=$ENV_NAME \ + "$SCWRYPTS_ROOT/scwrypts" $@ + EXIT_CODE=$? + + printf ' '; printf '--%.0s' {1..$SUBSCWRYPT}; printf " ($SUBSCWRYPT) " + echo " END SUBSCWRYPT : $(basename $1)" + ((SUBSCWRYPT-=1)) + + return $EXIT_CODE +} diff --git a/.config b/global/config.zsh similarity index 95% rename from .config rename to global/config.zsh index 377642a..00d85d9 100644 --- a/.config +++ b/global/config.zsh @@ -14,6 +14,8 @@ SCWRYPTS_LOG_PATH="$SCWRYPTS_DATA_PATH/logs" SCWRYPTS_OUTPUT_PATH="$SCWRYPTS_DATA_PATH/output" SCWRYPTS_VIRTUALENV_PATH="$SCWRYPTS_DATA_PATH/virtualenv" +##################################################################### + [ -f $SCWRYPTS_CONFIG_PATH/config ] && source $SCWRYPTS_CONFIG_PATH/config ##################################################################### @@ -21,15 +23,12 @@ SCWRYPTS_VIRTUALENV_PATH="$SCWRYPTS_DATA_PATH/virtualenv" [ ! -d $SCWRYPTS_CONFIG_PATH ] && mkdir -p $SCWRYPTS_CONFIG_PATH [ ! -d $SCWRYPTS_DATA_PATH ] && mkdir -p $SCWRYPTS_DATA_PATH - [ ! -d $SCWRYPTS_ENV_PATH ] && mkdir -p $SCWRYPTS_ENV_PATH [ ! -d $SCWRYPTS_LOG_PATH ] && mkdir -p $SCWRYPTS_LOG_PATH [ ! -d $SCWRYPTS_OUTPUT_PATH ] && mkdir -p $SCWRYPTS_OUTPUT_PATH [ ! -d $SCWRYPTS_VIRTUALENV_PATH ] && mkdir -p $SCWRYPTS_VIRTUALENV_PATH -##################################################################### - export \ SCWRYPTS_CONFIG_PATH \ SCWRYPTS_DATA_PATH \ @@ -40,4 +39,6 @@ export \ SCWRYPTS_OUTPUT_PATH \ SCWRYPTS_VIRTUALENV_PATH \ ; + +##################################################################### true diff --git a/py/redis/client.py b/py/redis/client.py index 8060a79..8184be2 100644 --- a/py/redis/client.py +++ b/py/redis/client.py @@ -8,7 +8,7 @@ class RedisClient(StrictRedis): super().__init__( host = getenv('REDIS_HOST'), port = getenv('REDIS_PORT'), - password = getenv('REDIS_AUTH'), + password = getenv('REDIS_AUTH', required=False), decode_responses = True, ) diff --git a/zsh/aws/eks/common.zsh b/zsh/aws/eks/common.zsh new file mode 100644 index 0000000..1110be3 --- /dev/null +++ b/zsh/aws/eks/common.zsh @@ -0,0 +1,6 @@ +_DEPENDENCIES+=( + kubectl +) +_REQUIRED_ENV+=() +source ${0:a:h}/../common.zsh +##################################################################### diff --git a/zsh/aws/eks/login b/zsh/aws/eks/login new file mode 100755 index 0000000..08b4835 --- /dev/null +++ b/zsh/aws/eks/login @@ -0,0 +1,19 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### + +__STATUS "performing AWS ECR docker login" + +CLUSTER_NAME=$(\ + _AWS eks list-clusters \ + | jq -r '.[] | .[]' \ + | __FZF 'select a cluster' +) +[ ! $CLUSTER_NAME ] && __ABORT + +__STATUS "updating kubeconfig for '$CLUSTER_NAME'" +_AWS eks update-kubeconfig --name $CLUSTER_NAME \ + && __SUCCESS "kubeconfig updated with '$CLUSTER_NAME'" \ + || __ERROR "failed to update kubeconfig; do you have permissions to access '$CLUSTER_NAME'?" diff --git a/zsh/common.zsh b/zsh/common.zsh index 9fabd01..a126dd6 100644 --- a/zsh/common.zsh +++ b/zsh/common.zsh @@ -1,17 +1,8 @@ ##################################################################### -[ ! $SCWRYPTS_ROOT ] && SCWRYPTS_ROOT="$(dirname ${0:a:h})" - -__PREFERRED_PYTHON_VERSIONS=(3.10 3.9) -__NODE_VERSION=18.0.0 -__ENV_TEMPLATE=$SCWRYPTS_ROOT/.env.template - -__SCWRYPT=1 - -source $SCWRYPTS_ROOT/.config -source ${0:a:h}/utils/utils.module.zsh || { - [ $DONT_EXIT ] && return 1 || exit 1 -} +source ${0:a:h}/../global/common.zsh +source ${0:a:h}/utils/utils.module.zsh \ + || { [ $DONT_EXIT ] && return 1 || exit 1; } ##################################################################### @@ -26,33 +17,15 @@ __GET_ENV_NAMES() { __GET_ENV_FILES | sed 's/.*\///'; } __GET_ENV_FILE() { echo "$SCWRYPTS_CONFIG_PATH/env/$1"; } __SELECT_OR_CREATE_ENV() { __GET_ENV_NAMES | __FZF_TAIL 'select/create an environment'; } -__SELECT_ENV() { __GET_ENV_NAMES | __FZF 'select an environment'; } +__SELECT_ENV() { __GET_ENV_NAMES | __FZF 'select an environment'; } + +##################################################################### __GET_AVAILABLE_SCRIPTS() { cd $SCWRYPTS_ROOT; find . -mindepth 2 -type f -executable \ | grep -v '\.git' \ - | grep -v '\.env' \ | grep -v 'node_modules' \ | sed 's/^\.\///; s/\.[^.]*$//' \ ; } - -##################################################################### - -__RUN_SCWRYPT() { - # run a scwrypt inside a scwrypt w/stack-depth indicators - ((SUBSCWRYPT+=1)) - printf ' '; printf '--%.0s' {1..$SUBSCWRYPT}; printf " ($SUBSCWRYPT) " - echo " BEGIN SUBSCWRYPT : $(basename $1)" - - SUBSCWRYPT=$SUBSCWRYPT SCWRYPTS_ENV=$ENV_NAME \ - "$SCWRYPTS_ROOT/scwrypts" $@ - EXIT_CODE=$? - - printf ' '; printf '--%.0s' {1..$SUBSCWRYPT}; printf " ($SUBSCWRYPT) " - echo " END SUBSCWRYPT : $(basename $1)" - ((SUBSCWRYPT-=1)) - - return $EXIT_CODE -} diff --git a/zsh/scwrypts/configure b/zsh/scwrypts/configure index af30673..392cb03 100755 --- a/zsh/scwrypts/configure +++ b/zsh/scwrypts/configure @@ -13,7 +13,7 @@ source ${0:a:h}/common.zsh echo '#' echo '# configuration for scwrypts' echo '#' - sed -n '1d; /^###/q; p' $SCWRYPTS_ROOT/.config | sed '$d' + sed -n '1d; /^###/q; p' $SCWRYPTS_ROOT/global/config.zsh | sed '$d' } > $SCWRYPTS_CONFIG_PATH/config __EDIT $SCWRYPTS_CONFIG_PATH/config