#!/bin/bash ############################################################ # Decription: Preinst linux GMo cloned server from VMWare WS # Author: Gilles Mouchet (gilles.mouchet@gmail.com) # Creation Date: 07-Apr-2024 # Version: 1.0 # # V1.0 - 07-Apr-2024 - GMo # Added # - Creation of script from scratch # ############################################################ version="1.0" usage() { cat << EOF Usage: ./deploy.sh options Deploy application on kubernetes Options: -n namespace -k kubernetes system (k3s or k8s) -h display this help text -v version EOF } options=$(getopt n:k:hv "$*") [ $? -eq 0 ] || { echo "Incorrect options provided" usage exit 1 } eval set -- "$options" no_args="true" while true; do case "$1" in -k) shift case "$1" in k3s) kube_sys=$1 ;; k8s) kube_sys=$1 ;; *) usage exit 1 ;; esac ;; -n) shift ns=$1 ;; --) shift break ;; -h) usage exit ;; -v) cat << EOF deploy.sh $version Copyright (C) 2021-`date +"%Y"` - GMo Free Software. Written by Gilles Mouchet (gilles.mouchet@gmail.com) EOF exit ;; *) usage exit 1 ;; esac shift no_args="false" done if [ -z "${kube_sys}" ] || [ -z "${ns}" ]; then usage exit 1 fi # increment minor version at each deploy # get Chart verion #chart_version=$(grep appVersion helm/Chart.yaml | cut -d '"' -f2) # get Chart major version #chart_major_version=$(echo $chart_version | cut -d'.' -f1) # get Chart minor verison #chart_minor_version=$(echo $chart_version | cut -d'.' -f2) # increment minor version #let "chart_minor_version++" # set new version #chart_new_version=$chart_major_version.$chart_minor_version # replace in .env, .env.dist and Chart the version #env_file=(.env .env.dist ./docker/php-fpm/.env ./docker/php-fpm/.env.dist ./helm/Chart.yaml) #for f in ${env_file[@]}; do # case $f in # .env|.env.dist) # #sed -e "s|DOCKER_IMAGE_VERSION=\"$chart_version\"|DOCKER_IMAGE_VERSION=\"$chart_new_version\"|" < $f # sed -i "s|DOCKER_IMAGE_VERSION=\"$chart_version\"|DOCKER_IMAGE_VERSION=\"$chart_new_version\"|" $f # ;; # ./docker/php-fpm/.env|./docker/php-fpm/.env.dist) # #sed -e "s|SITE_VERSION=\"$chart_version\"|SITE_VERSION=\"$chart_new_version\"|" < $f # sed -i "s|SITE_VERSION=\"$chart_version\"|SITE_VERSION=\"$chart_new_version\"|" $f # ;; # ./helm/Chart.yaml) # #sed -e "s|appVersion: \"$chart_version\"|appVersion: \"$chart_new_version\"|" < $f # sed -i "s|appVersion: \"$chart_version\"|appVersion: \"$chart_new_version\"|" $f # ;; # esac #done echo $chart_version echo $chart_new_version echo $ns echo $kube_sys # git commit #git add .env.dist docker/php-fpm/.env.dist helm/Chart.yaml #git commit -m "deploy version $chart_new_version" # build image and push in repo ./docker.sh install ./docker.sh build ./docker.sh push # set config to connect kubernetes rm -f $HOME/.kube/config ln -s $HOME/.kube/$kube_sys $HOME/.kube/config #helm template --set kube=$kube_sys ./helm --values=./helm/values-configs.yaml --values=./helm/values-secrets.yaml --namespace $ns --create-namespace # deploy Chart #helm upgrade $ns --set kube=$kube_sys ./helm --install --atomic --cleanup-on-fail --values=./helm/values-configs.yaml --values=./helm/values-secrets.yaml --namespace $ns --create-namespace #kubectl create job -n $NS --from=cronjob/cronjob-mariadb-backupdb dbbackup-$(date +%Y-%m-%d-%H-%M-%S)