Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/maven/fixes/8.1' into maven/rele…
Browse files Browse the repository at this point in the history
…ase/8.1
  • Loading branch information
metaventis-build committed Oct 18, 2024
2 parents 2cc7bbc + 78b53a1 commit aa253a1
Show file tree
Hide file tree
Showing 2 changed files with 204 additions and 125 deletions.
310 changes: 186 additions & 124 deletions archetypes/helm/src/main/resources/archetype-resources/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,45 @@ set -o pipefail

if [[ -z $1 ]] ; then
echo ""
echo "deploy.sh [-s skip checks and deploy directly] <release> <chart> [<version|path>]"
echo "deploy.sh [options] <release> <chart> [<version|path>]"
echo " options:"
echo " -s # skip checks and deploy directly"
echo " -d # run diff"
echo " -t # run try run"
echo " -e # run execute deployment"
echo ""
exit 0
fi

SKIP=false
while getopts s: opt; do
WIZARD=true
DIFF=false
TRY_RUN=false
DEPLOY=false
while getopts sdte opt; do
case $opt in
s) SKIP=true
s)
SKIP=true
;;
d)
WIZARD=false
DIFF=true
;;
t)
WIZARD=false
TRY_RUN=true
;;
e)
WIZARD=false
DEPLOY=true
;;
*)
;;
esac
shift
done

shift $(( "$OPTIND" - 1))

RELEASE=${1?"release required"}
CHART=${2?"chart required"}
VERSION=${3:-"":->=0.0.0-0}
Expand Down Expand Up @@ -92,127 +118,163 @@ fi

popd >/dev/null || exit

if [ "$SKIP" = false ] ; then
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
echo "cluster: ${CONTEXT}"
echo "namespace: ${NAMESPACE}"
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
read -p "---> kubectl context ok [y/N] " answer
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
case ${answer:0:1} in
y | Y)
echo "Request existing releases, please wait ..."
echo ""
helm repo update >/dev/null
helm ls -a
;;
*)
exit 0
;;
esac

echo ""
echo "--------------------------------------------------------------------------------"
echo ""
echo "release: ${RELEASE}"
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
read -p "---> helm release ok [y/N] " answer
echo ""
echo "--------------------------------------------------------------------------------"
echo ""

case ${answer:0:1} in
y | Y)
echo "Request existing revisions, please wait ..."
echo ""
helm history ${RELEASE} 2>/dev/null || echo "skipped ..."
;;
*)
exit 0
;;
esac

echo ""
echo "--------------------------------------------------------------------------------"
echo ""
echo "chart: ${CHART}"
echo "version: ${VERSION}"
echo "options: ${ARGS[@]}"
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
read -p "---> helm parameter ok [y/N] " answer
echo ""
echo "--------------------------------------------------------------------------------"
echo ""

if [[ ! -f ${CHART} ]] ; then

ARGS+=("--version")
ARGS+=("${VERSION}")
diff() {
echo "Request diff from last revision, please wait ..."
echo ""
# temporarily disable the script from exiting on a non-zero status code
set +e
helm diff upgrade --install "${RELEASE}" "${CHART}" "${ARGS[@]}"
set -e
}

fi
tryRun(){
echo "Dry-run, please wait ..."
echo ""
helm upgrade --install "${RELEASE}" "${CHART}" "${ARGS[@]}" --dry-run --debug
}

execute(){
echo "Execute, please wait ..."
echo ""
helm upgrade --install "${RELEASE}" "${CHART}" "${ARGS[@]}" --timeout=30m
}


runAsWizard() {
if [ "$SKIP" = false ] ; then
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
echo "cluster: ${CONTEXT}"
echo "namespace: ${NAMESPACE}"
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
read -p "---> kubectl context ok [y/N] " answer
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
case ${answer:0:1} in
y | Y)
echo "Request existing releases, please wait ..."
echo ""
helm repo update >/dev/null
helm ls -a
;;
*)
exit 0
;;
esac

echo ""
echo "--------------------------------------------------------------------------------"
echo ""
echo "release: ${RELEASE}"
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
read -p "---> helm release ok [y/N] " answer
echo ""
echo "--------------------------------------------------------------------------------"
echo ""

case ${answer:0:1} in
y | Y)
echo "Request existing revisions, please wait ..."
echo ""
helm history ${RELEASE} 2>/dev/null || echo "skipped ..."
;;
*)
exit 0
;;
esac

echo ""
echo "--------------------------------------------------------------------------------"
echo ""
echo "chart: ${CHART}"
echo "version: ${VERSION}"
echo "options: ${ARGS[*]}"
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
read -p "---> helm parameter ok [y/N] " answer
echo ""
echo "--------------------------------------------------------------------------------"
echo ""

if [[ ! -f ${CHART} ]] ; then

ARGS+=("--version")
ARGS+=("${VERSION}")

fi

case ${answer:0:1} in
y | Y)
diff
;;
*)
exit 0
;;
esac

echo ""
echo "--------------------------------------------------------------------------------"
echo ""
read -p "---> perform test [y/N] " answer
echo ""
echo "--------------------------------------------------------------------------------"
echo ""

case ${answer:0:1} in
y | Y)
tryRun
;;
*)
echo "skipped ..."
;;
esac

fi
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
read -p "---> perform deployment [y/N] " answer
echo ""
echo "--------------------------------------------------------------------------------"
echo ""

case ${answer:0:1} in
y | Y)
echo "Request diff from last revision, please wait ..."
echo ""
helm diff upgrade --install "${RELEASE}" "${CHART}" "${ARGS[@]}"
;;
*)
exit 0
;;
esac

echo ""
echo "--------------------------------------------------------------------------------"
echo ""
read -p "---> perform test [y/N] " answer
echo ""
echo "--------------------------------------------------------------------------------"
echo ""

case ${answer:0:1} in
y | Y)
echo "Dry-run, please wait ..."
echo ""
helm upgrade --install "${RELEASE}" "${CHART}" "${ARGS[@]}" --dry-run --debug
;;
*)
echo "skipped ..."
;;
esac
case ${answer:0:1} in
y | Y)
execute
;;
*)
echo "skipped ..."
;;
esac

echo ""
echo "--------------------------------------------------------------------------------"
echo ""
echo "done"
echo ""
}


if [[ $WIZARD == "true" ]] ; then
runAsWizard
else
if [[ $DIFF == "true" ]] ; then
diff
fi

if [[ $TRY_RUN == "true" ]] ; then
tryRun
fi

if [[ $DEPLOY == "true" ]] ; then
execute
fi

fi
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
read -p "---> perform deployment [y/N] " answer
echo ""
echo "--------------------------------------------------------------------------------"
echo ""

case ${answer:0:1} in
y | Y)
echo "Run, please wait ..."
echo ""
helm upgrade --install "${RELEASE}" "${CHART}" "${ARGS[@]}" --timeout=30m
;;
*)
echo "skipped ..."
;;
esac

echo ""
echo "--------------------------------------------------------------------------------"
echo ""
echo "done"
echo ""
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,25 @@ backup() {


if [[ -n $repodb ]] ; then
echo "backup postgres"
if [[ "$($COMPOSE_EXEC ps repository-mongo -a)" != "no such service: repository-mongo" ]]; then
echo "backup mongo"

if [[ -n $compressed ]] ; then
$COMPOSE_EXEC exec -t repository-mongo sh -c "mongodump --archive --gzip -u ${REPOSITORY_MONGO_ROOT_USER:-root} -p ${REPOSITORY_MONGO_ROOT_PASS:-root}" >"$backupDir/repository-mongo.gz" || {
rm -rf "$backupDir"
echo "ERROR on creating mongodb dump"
exit 1
}
else
$COMPOSE_EXEC exec -t repository-mongo sh -c "mongodump --archive -u ${REPOSITORY_MONGO_ROOT_USER:-root} -p ${REPOSITORY_MONGO_ROOT_PASS:-root}" >"$backupDir/repository-mongo.dump" || {
rm -rf "$backupDir"
echo "ERROR on creating mongodb dump"
exit 1
}
fi
fi

echo "backup postgres"
if [[ -n $compressed ]] ; then
$COMPOSE_EXEC exec -t repository-database sh -c "export PGPASSWORD=${REPOSITORY_DATABASE_PASS:-repository}; pg_dump --username ${REPOSITORY_DATABASE_USER:-repository} --format custom --no-owner --no-privileges ${REPOSITORY_DATABASE_NAME:-repository} | gzip" >"$backupDir/repository-db.gz" || {
rm -rf "$backupDir"
Expand Down

0 comments on commit aa253a1

Please sign in to comment.