Skip to content

Commit

Permalink
refactor: unified and simplified chart with zx setup (#505)
Browse files Browse the repository at this point in the history
also fixed the streaming bug that stopped output to the screen
  • Loading branch information
Maurice Faber committed Aug 9, 2021
1 parent 71b700a commit 4ea7f94
Show file tree
Hide file tree
Showing 50 changed files with 763 additions and 662 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Expand Up @@ -31,6 +31,8 @@ RUN if [ "$SKIP_TESTS" = 'false' ]; then npm ci; src/ci-tests.ts; fi
FROM otomi/tools:v1.4.19 as prod

ENV APP_HOME=/home/app/stack
ENV IN_DOCKER=1

RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME

Expand Down
54 changes: 27 additions & 27 deletions binzx/installer
Expand Up @@ -12,43 +12,43 @@ read -p "$msg" answer <&2
answer=${answer:-$path}

if [ ! -d $answer ]; then
echo "$answer does not exist, please provide an existing path"
exit 1
echo "$answer does not exist, please provide an existing path"
exit 1
fi

if [[ $PATH != *$answer* ]]; then
echo "$answer is not in your PATH please add it to run $script from anywhere"
echo "export PATH=$answer:\$PATH"
echo "$answer is not in your PATH please add it to run $script from anywhere"
echo "export PATH=$answer:\$PATH"
fi

file="$answer/$script"
if command -v wget &> /dev/null; then
wget $remote -O $file
elif command -v curl &> /dev/null; then
curl $remote -o $file
if command -v wget &>/dev/null; then
wget $remote -O $file
elif command -v curl &>/dev/null; then
curl $remote -o $file
fi
chmod +x $file

if [[ $SHELL == *zsh* ]] || [[ $SHELL == *bash* ]]; then
readonly msgAC="Do you want to install autocompletion for otomi? [Yes/no]: "
read -p "$msgAC" autocompleteAnswer <&2
autocompleteAnswer=${autocompleteAnswer:-yes}
case $autocompleteAnswer in
[Yy]* )
acPath='/usr/local/share/zsh/site-functions/_otomi'
if [[ $SHELL == *bash* ]]; then
acPath='/usr/local/etc/bash_completion.d/otomi.bash'
fi
otomi completion | tr -d '\r' > $acPath
chmod +x $acPath
echo "Autocompletion has been installed in ${acPath}"
echo "Please restart your terminal to use autocompletion"
;;
[Nn]* )
echo "If you need autocompletion you can run:"
echo "\`otomi completion\`"
;;
esac
readonly msgAC="Do you want to install autocompletion for otomi? [Yes/no]: "
read -p "$msgAC" autocompleteAnswer <&2
autocompleteAnswer=${autocompleteAnswer:-yes}
case $autocompleteAnswer in
[Yy]*)
acPath='/usr/local/share/zsh/site-functions/_otomi'
if [[ $SHELL == *bash* ]]; then
acPath='/usr/local/etc/bash_completion.d/otomi.bash'
fi
otomi completion | tr -d '\r' >$acPath
chmod +x $acPath
echo "Autocompletion has been installed in ${acPath}"
echo "Please restart your terminal to use autocompletion"
;;
[Nn]*)
echo "If you need autocompletion you can run:"
echo "\`otomi completion\`"
;;
esac
fi

echo "Otomi has been installed in $file"
Expand Down
32 changes: 23 additions & 9 deletions binzx/otomi
Expand Up @@ -36,19 +36,34 @@ silent() {
"$@" &>/dev/null
fi
}
# shellcheck disable=SC2155
readonly base_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

in_core=false
if [[ $base_dir == *"otomi-core"* ]] || [[ $(pwd) == *"otomi-core"* ]]; then
in_core=true
fi

function docker_tag_exists() {
curl --silent -f -lSL https://index.docker.io/v1/repositories/otomi/core/tags/$1 >/dev/null
}

# Parse yaml block without yq: https://stackoverflow.com/a/49190338/14982291
otomi_version="latest"
if [ -f "package.json" ]; then
otomi_version="master"
elif [ -f $ENV_DIR/env/settings.yaml ]; then
if [ "$in_core" = true ]; then
current_branch="$(git branch --show-current 2>/dev/null)"
current_branch="${current_branch##*/}"
current_branch="${current_branch:-'master'}"
otomi_version='master'
if docker_tag_exists $current_branch; then
otomi_version=$current_branch
fi
elif [ -f "${ENV_DIR}/env/settings.yaml" ]; then
otomi_version=$(awk '/otomi/{flag=1} flag && /version:/{print $NF;flag=""}' $ENV_DIR/env/settings.yaml)
fi
OTOMI_TAG=${OTOMI_TAG:-$otomi_version}

readonly otomi_tools_image="otomi/core:${OTOMI_TAG}"
# shellcheck disable=SC2155
readonly base_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
script_full_path="$base_dir/${BASH_SOURCE[0]##*/}"
if [[ ${BASH_SOURCE[0]} == '/'* ]]; then
script_full_path="${BASH_SOURCE[0]}"
Expand Down Expand Up @@ -117,8 +132,7 @@ EOF
}

check_update() {
if [[ $base_dir == *"otomi-core"* ]] ||
[[ $(pwd) == *"otomi-core"* ]] ||
if [ "$in_core" = true ] ||
[[ $calling_args == *'-non-interactive'* ]] ||
[[ $calling_args == *'-ni'* ]]; then
return 0
Expand Down Expand Up @@ -210,7 +224,7 @@ executable="node --experimental-specifier-resolution=node ${stack_dir}/dist/otom
stack_volume=""
tmp_volume_dir=$(mktemp -d)
tmp_volume=" -v $tmp_volume_dir:/tmp"
if [[ $base_dir == *"otomi-core"* ]] || [[ $(pwd) == *"otomi-core"* ]]; then
if [ "$in_core" = true ]; then
silent echo "Checking if in dev environment"
if [[ $base_dir == *"otomi-core"* ]]; then
stack_dir=$(cd "$base_dir/.." && pwd)
Expand Down Expand Up @@ -244,7 +258,7 @@ if [ "$1" = "bash" ] && [ "$#" = "1" ]; then
cmd="bash"
fi

if { [ "$OTOMI_TAG" = 'latest' ] || [ "$OTOMI_TAG" = 'master' ]; } && [ -z $NOPULL ] && [ -z $IN_DOCKER ]; then
if { { [ "$OTOMI_TAG" = 'latest' ] || [ "$OTOMI_TAG" = 'master' ]; } || [ -n "$FORCE_PULL" ]; } && [ -z $NOPULL ] && [ -z $IN_DOCKER ]; then
silent echo "Pulling latest version of the docker image, please wait"
silent docker pull $otomi_tools_image
status=$?
Expand Down
33 changes: 11 additions & 22 deletions chart/otomi/localtest.sh
Expand Up @@ -3,25 +3,14 @@
# With VALUES_DIR holding a file named values.yaml holding the initial chart values
set -e

function run_core() {
image=$1
shift
docker run --rm -it --env-file=$HOME/opt/.sops-secrets -e VERBOSE=1 -e IN_DOCKER=1 -e CI=1 -e OTOMI_VERSION=$OTOMI_VERSION -e OTOMI_VALUES_INPUT=/secret/values.yaml -w ${WORKDIR:-$PWD} -e ENV_DIR=/home/app/stack/env -v $ENV_OUT:/home/app/stack/env -v $PWD:$PWD -v $VALUES_DIR:/secret -v /tmp:/tmp $image "$@"
}

function run_task() {
docker run --rm -it -e OTOMI_ENV_DIR=/env -e IN_DOCKER=1 -e CI=1 -e OTOMI_VALUES_INPUT=/secret/values.yaml -e OTOMI_SCHEMA_PATH=/env/values-schema.yaml -v $ENV_OUT:/env -v $VALUES_DIR:/secret -v /tmp:/tmp otomi/tasks:master "$@"
}

coreTag=master

run_core otomi/core:$coreTag bash -c "$(cat chart/otomi/scripts/bootstrap-values.sh)"

echo ------ mapping values ------
run_task sh -c "npm run tasks:otomi-chart"

echo ------ push values ------
run_core otomi/core:$coreTag bash -c "$(cat chart/otomi/scripts/push-values.sh)"

echo ------ deploying ------
WORKDIR=/home/app/stack run_core otomi/core:$coreTag bash -c 'bin/deploy.sh'
docker run --rm -it \
--env-file=../.env \
-e VERBOSITY=1 \
-e OTOMI_VALUES_INPUT=/secret/values.yaml \
-e OTOMI_NON_INTERACTIVE='true' \
-w ${WORKDIR:-$PWD} \
-e ENV_DIR=/home/app/stack/env \
-v $ENV_OUT:/home/app/stack/env \
-v $PWD:$PWD -v $VALUES_DIR:/secret \
-v /tmp:/tmp $image \
"binzx/otomi chart bootstrap && binzx/otomi chart merge && binzx/otomi chart push && binzx/otomi apply"
65 changes: 0 additions & 65 deletions chart/otomi/scripts/bootstrap-values.sh

This file was deleted.

26 changes: 0 additions & 26 deletions chart/otomi/scripts/push-values.sh

This file was deleted.

0 comments on commit 4ea7f94

Please sign in to comment.