Newer
Older
#!/bin/bash
export NS=`pwd | rev | cut -d'/' -f 2 | rev | sed 's/\./-/'`
export DOMAIN=`pwd | rev | cut -d'/' -f 2 | rev`
export SUBDOMAIN=`pwd | rev | cut -d'/' -f 1 | rev`
export FQDN=${SUBDOMAIN}-${NS}
export FQDN_DOTS=${SUBDOMAIN}.`echo $DOMAIN | sed 's/\(.*\)-/\1./'`
export PG_DOMAIN=$NS
export EPOCH=`date "+%s"`
export NUAGE_URL=`kubectl -n $NS get ing -o custom-columns=HOST:spec.rules[*].host --selector=app.kubernetes.io/name=nextcloud --no-headers=true`
export BUCKET=${FQDN}
export S3_ENDPOINT_COLD=https://cold-objects.liiib.re
export S3_SECRET=${NS}-dumps
for key in `kubectl -n ${NS} get secrets ${S3_SECRET} -o json | jq -r '.data | keys | .[]'`; do
#echo "loading $key into env..."
export $key=`kubectl -n ${NS} get secrets ${S3_SECRET} -o json | jq -r ".data.$key" | base64 -d`
#echo "done."
done
function show_usage {
echo "Usage:"
echo " - apply"
echo " - diff"
echo " - update"
echo " - changens"
exit 1
}
if [ $# -eq 0 ]; then
show_usage
fi
export VERSION=stable
source ./.env
#cat ./version.php | grep 'array(' | cut -d\( -f2 | cut -d\) -f1 | sed 's/,/\./g'
export NC_VERSION=23.0.6.1
export NC_IMAGE_TAG=23.0.6-2022-06-21
export NC_WEB_IMAGE_TAG=23.0.6-web-2022-06-21
export NC_VERSION=22.2.8.1
export NC_IMAGE_TAG=22.2.8-2022-06-21
export NC_WEB_IMAGE_TAG=22.2.8-web-2022-06-21
export NC_IMAGE_TAG=21.0.9-2022-06-21
export NC_WEB_IMAGE_TAG=21.0.9-web-2022-06-21
elif [ "${APP}" = "rocketchat" ]; then
fi
create_update_job_nc () {
if [ "${APP}" = "nextcloud" ]; then
kubectl -n $NS delete job update-nc
libre apply ../../common/nextcloud/other-manifests/update-job.yml
fi
}
case "$1" in
apply|diff)
if [ -z "$2" ]; then
manifest="../../common/$APP/manifests/app.yml"
if [ -f "$manifest" ]; then
cat "${manifest}" | envsubst '$BUCKET $NC_VERSION $NC_IMAGE_TAG $NC_WEB_IMAGE_TAG $ALLOWED_HOSTS $NS $EPOCH $NUAGE_URL $PG_DOMAIN $DOMAIN $SUBDOMAIN $FQDN $FQDN_DOTS $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY $S3_ENDPOINT_COLD $S3_ENDPOINT $REPLICAS'| /home/deploy/libre-cli -t - | kubectl -n ${NS} $1 -f -
else
echo "Manifest $manifest not found"
exit
fi
else
cat "${@:2}" | envsubst '$BUCKET $NC_VERSION $NC_IMAGE_TAG $NC_WEB_IMAGE_TAG $ALLOWED_HOSTS $NS $EPOCH $NUAGE_URL $PG_DOMAIN $DOMAIN $SUBDOMAIN $FQDN $FQDN_DOTS $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY $S3_ENDPOINT_COLD $S3_ENDPOINT $REPLICAS'| /home/deploy/libre-cli -t - | kubectl -n ${NS} $1 -f -
fi;;
update)
echo $FQDN_DOTS
libre diff > /tmp/diff
retVal=$? # returns 1 if diff
if [ $retVal -ne 0 ]; then # if diff
if [ "$2" = "--batch" ]; then
if [ "$3" = "--scaledown" ]; then
kubectl -n ${NS} scale --replicas=0 deployment/${FQDN}-app
fi
cat /tmp/diff | grep -v "value:\|image\|generation\|+++\|---\|@@\|diff" | grep "^+\|^-"
retVal=$? # returns 1 if grep
if [ $retVal -ne 1 ]; then
read -p "Ctrl-c to not apply the diff"
fi
else
cat /tmp/diff
read -p "Ctrl-c to not apply the diff"
fi
create_update_job_nc