Merged in bugfix/fixdb (pull request #53)
cleanup * cleanup * Merged develop into bugfix/fixdb Approved-by: Rachit Bhargava
This commit is contained in:
committed by
Rachit Bhargava
parent
9435e4d282
commit
8de8fa1db7
@@ -1,314 +0,0 @@
|
||||
#!/bin/bash
|
||||
exec > >(tee -a script.log) 2>&1
|
||||
|
||||
|
||||
# Install the required packages #
|
||||
# --------------------------------------------------------------
|
||||
apk upgrade && apk add curl wget zip unzip coreutils
|
||||
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x ./kubectl && mv ./kubectl /usr/local/bin/kubectl
|
||||
|
||||
|
||||
. ./setenv.sh
|
||||
# ----------------------------------------------------------------------
|
||||
export NEW_URL=https://$URL_DOMAIN
|
||||
export CLUSTER=caresage-eks-cluster-$ENV
|
||||
|
||||
if [[ "$ENV" = "prod" ]] ; then
|
||||
export APP=`echo $URL_DOMAIN | awk -F[.-] '{print $2}'`
|
||||
else
|
||||
export APP=`echo $URL_DOMAIN | awk -F[.-] '{print $3}'`
|
||||
fi
|
||||
|
||||
export NAMESPACE=$APP-web
|
||||
|
||||
export REPO=$BITBUCKET_REPO_SLUG
|
||||
export REPLACE=`echo $NEW_URL | awk -F[./] '{print $4"."$5}'`
|
||||
export MAIN_DOMAIN=`echo $NEW_URL | awk -F[./] '{print $4"."$5}'`
|
||||
export URL_DOMAIN=$URL_DOMAIN
|
||||
# ---------------------------
|
||||
echo "export NEW_URL=https://$URL_DOMAIN" >> setenv.sh
|
||||
|
||||
if [[ "$ENV" = "prod" ]] ; then
|
||||
echo "export APP=`echo $URL_DOMAIN | awk -F[.-] '{print $2}'`" >> setenv.sh
|
||||
else
|
||||
echo "export APP=`echo $URL_DOMAIN | awk -F[.-] '{print $3}'`" >> setenv.sh
|
||||
fi
|
||||
|
||||
echo "export NAMESPACE=$APP-web" >> setenv.sh
|
||||
|
||||
echo "export REPO=$BITBUCKET_REPO_SLUG" >> setenv.sh
|
||||
echo "export REPLACE=`echo $NEW_URL | awk -F[./] '{print $4"."$5}'`" >> setenv.sh
|
||||
echo "export MAIN_DOMAIN=`echo $NEW_URL | awk -F[./] '{print $4"."$5}'`" >> setenv.sh
|
||||
echo "export URL_DOMAIN=$URL_DOMAIN" >> setenv.sh
|
||||
echo "export TOKEN=$TOKEN" >> setenv.sh
|
||||
# ---------------------------------------------------------------
|
||||
echo "JOBNAME -- $JOBNAME"
|
||||
echo "ENV -- $ENV"
|
||||
echo "CLUSTER -- $CLUSTER"
|
||||
echo "VERSION -- $BITBUCKET_BUILD_NUMBER"
|
||||
echo "RESTORE_VERSION -- $RESTORE_VERSION"
|
||||
echo "URL_DOMAIN -- $URL_DOMAIN"
|
||||
echo "SUBDOMAIN -- $SUBDOMAIN"
|
||||
echo "VERSION -- $VERSION"
|
||||
echo "RESTORE_VERSION -- $RESTORE_VERSION"
|
||||
echo "DB_NAME -- $DB_NAME"
|
||||
echo "MYSQL_FILE_NAME -- $MYSQL_FILE_NAME"
|
||||
echo "STATIC_FILE_NAME -- $STATIC_FILE_NAME"
|
||||
|
||||
|
||||
# Initial VALIDATION check #
|
||||
# -------------------------------------
|
||||
cat ./setenv.sh && . ./setenv.sh
|
||||
if [[ "$SUBDOMAIN" != "www" ]] && [[ "$ENV" = "qa" || "$ENV" = "stage" || "$ENV" = "prod" ]] ; then echo VALIDATION-FAIL && exit 9 ; else echo VALIDATION-PASS;fi
|
||||
#validation () { chmod 755 ./validation.sh && ./validation.sh; } && validation
|
||||
# ----------------------------------------------------------------------------------
|
||||
|
||||
# Check if it is already running #
|
||||
# -------------------------------------
|
||||
echo "Deploy the wordpress source code from the branch to pvc mount of subdomain..."
|
||||
aws eks update-kubeconfig --name caresage-eks-cluster-$ENV --region us-east-1
|
||||
echo "common-job-pod will be deleted if already there and thus make sure you run single common job for a given repo"
|
||||
echo ""
|
||||
kubectl get po -A | grep common-job-pod | grep $NAMESPACE && kubectl delete po common-job-pod -n $NAMESPACE || echo ----common-job-pod-t0-be-created
|
||||
# ----------------------------------------------------------------------------------
|
||||
|
||||
opt=$1
|
||||
deploy_version=$2
|
||||
|
||||
case $opt in
|
||||
|
||||
cleanup-backup)
|
||||
|
||||
aws eks update-kubeconfig --name caresage-eks-cluster-$ENV --region us-east-1 && . ./setenv.sh && chmod 755 ./s3cleanup.sh
|
||||
|
||||
./s3cleanup.sh && echo list-of-files-older-than-thirty-days-done || exit 9
|
||||
|
||||
cat script.log | egrep -v "Errors:|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|Permission denied|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
||||
|
||||
;;
|
||||
wp-auto-patch)
|
||||
|
||||
# The auto patch to be executed for dev01 to be specific
|
||||
# ----------------------------------------------------------
|
||||
if [[ "$SUBDOMAIN" != "dev01" ]] ; then echo VALIDATION-NOPASS-AUTO-PATCH-IS-FOR-DEV01 && exit 9 ; else echo VALIDATION-PASS-AUTO-PATCH-IS-FOR-DEV01;fi
|
||||
|
||||
aws eks update-kubeconfig --name caresage-eks-cluster-$ENV --region us-east-1
|
||||
kubectl apply -f build/$ENV/pod.tpl && kubectl apply -f build/$ENV/pvc.yml && echo pod-created && sleep 15
|
||||
kubectl cp setenv.sh $NAMESPACE/common-job-pod:/tmp/setenv.sh
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'chmod 755 /tmp/setenv.sh'
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt-key adv --fetch-keys 'https://packages.sury.org/php/apt.gpg' > /dev/null 2>&1
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt update
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt install wget zip unzip curl git rclone rsync -y
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c '. /tmp/setenv.sh;
|
||||
cd /tmp;
|
||||
git clone --branch="develop" https://x-token-auth:$TOKEN@bitbucket.org/connectamerica/$REPO.git;
|
||||
cd $REPO/;
|
||||
git config user.email "{botid}@bots.bitbucket.org" ;
|
||||
git checkout -b feature/$VERSION-$ENV-$SUBDOMAIN && git push --set-upstream origin feature/$VERSION-$ENV-$SUBDOMAIN;
|
||||
rclone sync --exclude wp-content/uploads/** /usr/share/nginx/subdomain/$SUBDOMAIN/ wp -q ;
|
||||
echo "-----sync-done-----" ;
|
||||
git add --all && git commit -m "auto-patch $VERSION-$ENV-$SUBDOMAIN-$(date +%Y-%m-%dT%H_%M_%S)" ;
|
||||
git push && echo ---git-push-done--- '
|
||||
#--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
kubectl delete po common-job-pod -n $NAMESPACE
|
||||
|
||||
cat script.log | egrep -v "Errors:|inflating|adding|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
||||
|
||||
;;
|
||||
|
||||
subdomain_deploy)
|
||||
|
||||
aws eks update-kubeconfig --name caresage-eks-cluster-$ENV --region us-east-1
|
||||
kubectl apply -f build/$ENV/pod.tpl && kubectl apply -f build/$ENV/pvc.yml && echo pod-created && sleep 15
|
||||
|
||||
kubectl cp wp $NAMESPACE/common-job-pod:/tmp && echo "wp copy to /tmp done" || exit 9
|
||||
kubectl cp setenv.sh $NAMESPACE/common-job-pod:/tmp/setenv.sh && echo "setenv copy done" || exit 9
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'chmod 755 /tmp/setenv.sh'
|
||||
# --------------------------------------------------------------------------------------------
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt-key adv --fetch-keys 'https://packages.sury.org/php/apt.gpg' > /dev/null 2>&1
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt update
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt install rclone rsync -y
|
||||
|
||||
echo "BITBUCKET_BRANCH: $BITBUCKET_BRANCH" > env.txt
|
||||
echo "BITBUCKET_BUILD_NUMBER: $BITBUCKET_BUILD_NUMBER" >> env.txt
|
||||
echo "BITBUCKET_COMMIT: $BITBUCKET_COMMIT" >> env.txt
|
||||
|
||||
kubectl cp env.txt $NAMESPACE/common-job-pod:/tmp/wp/env.txt && echo "-------env.txt details done" || exit 9
|
||||
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c '. /tmp/setenv.sh; cd /tmp && rclone sync --exclude wp-content/uploads/** wp/ /usr/share/nginx/subdomain/$SUBDOMAIN -q && echo ---sync-done--- '
|
||||
|
||||
# -----------------------------------------------------------
|
||||
if [ "$ENV" = "dev" ] ; then
|
||||
pods=`kubectl get pods --no-headers -o custom-columns=":metadata.name" -n $NAMESPACE`
|
||||
for i in $pods; do
|
||||
kubectl exec $i -n $NAMESPACE -- apt-key adv --fetch-keys 'https://packages.sury.org/php/apt.gpg' > /dev/null 2>&1
|
||||
kubectl exec $i -n $NAMESPACE -- apt update
|
||||
kubectl exec $i -n $NAMESPACE -- apt install rclone rsync -y
|
||||
|
||||
kubectl cp setenv.sh $NAMESPACE/$i:/tmp/setenv.sh && echo "setenv copy done" || exit 9
|
||||
|
||||
kubectl exec $i -n $NAMESPACE -- sh -c '. /tmp/setenv.sh; cd /usr/share/nginx/subdomain && rclone sync --exclude wp-content/uploads/** $SUBDOMAIN/ /usr/share/nginx/subdomain/$SUBDOMAIN-web -q && echo ---sync-done from efs to local for $SUBDOMAIN-web --- && cd $SUBDOMAIN-web/wp-content && [ -L uploads ] && [ -e uploads ]] && echo ----symlink-exist--- || ln -s /usr/share/nginx/subdomain/$SUBDOMAIN/wp-content/uploads uploads && chown -R nginx:nginx /usr/share/nginx/subdomain/$SUBDOMAIN-web'
|
||||
done
|
||||
else
|
||||
|
||||
echo ----The env is $ENV and thus no multidev applicable----
|
||||
|
||||
fi
|
||||
|
||||
kubectl delete po common-job-pod -n $NAMESPACE
|
||||
# -------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
cat script.log | egrep -v "Errors:|inflating|adding|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
||||
|
||||
;;
|
||||
|
||||
|
||||
mysql-backup)
|
||||
|
||||
echo "Running mysql backup with s3..."
|
||||
aws eks update-kubeconfig --name caresage-eks-cluster-$ENV --region us-east-1
|
||||
kubectl apply -f build/$ENV/pod.tpl && kubectl apply -f build/$ENV/pvc.yml && echo pod-created && sleep 15
|
||||
|
||||
kubectl cp setenv.sh $NAMESPACE/common-job-pod:/tmp/setenv.sh
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'chmod 755 /tmp/setenv.sh'
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt-key adv --fetch-keys 'https://packages.sury.org/php/apt.gpg' > /dev/null 2>&1
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt update
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt install zip wget unzip curl mariadb-client -y
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c '. /tmp/setenv.sh ;mysqldump -h $DB_HOST --single-transaction --quick --lock-tables=false --user=$DB_USER --password=$DB_PASSWORD $SUBDOMAIN --skip-lock-tables | gzip > /tmp/$NAMESPACE-pantheon.sql.gz'
|
||||
|
||||
kubectl cp $NAMESPACE/common-job-pod:/tmp/$NAMESPACE-pantheon.sql.gz $NAMESPACE-pantheon-$VERSION-$ENV-$SUBDOMAIN-$(date +%Y-%m-%dT%H_%M_%S).sql.gz
|
||||
FILE=`ls $NAMESPACE-pantheon-*.sql.gz`
|
||||
|
||||
aws s3 cp $FILE s3://commonjobs/$NAMESPACE/$opt/
|
||||
|
||||
curl --request POST -F files=@"$FILE" --url "https://api.bitbucket.org/2.0/repositories/connectamerica/$REPO/downloads" \
|
||||
--header "Authorization: Bearer $TOKEN"
|
||||
|
||||
kubectl delete po common-job-pod -n $NAMESPACE
|
||||
|
||||
cat script.log | egrep -v "Errors:|inflating|adding|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
||||
|
||||
;;
|
||||
|
||||
wp-data-backup)
|
||||
|
||||
aws eks update-kubeconfig --name caresage-eks-cluster-$ENV --region us-east-1
|
||||
kubectl apply -f build/$ENV/pod.tpl && kubectl apply -f build/$ENV/pvc.yml && echo pod-created && sleep 15
|
||||
kubectl cp setenv.sh $NAMESPACE/common-job-pod:/tmp/setenv.sh
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'chmod 755 /tmp/setenv.sh'
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt-key adv --fetch-keys 'https://packages.sury.org/php/apt.gpg' > /dev/null 2>&1
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt update
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt install wget zip unzip curl -y
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c '. /tmp/setenv.sh;cd /usr/share/nginx/subdomain/$SUBDOMAIN/wp-content/uploads;zip -r /tmp/upload.zip . -x "./wc-logs/*.log"'
|
||||
kubectl cp $NAMESPACE/common-job-pod:/tmp/upload.zip $NAMESPACE-$VERSION-$ENV-$SUBDOMAIN-$(date +%Y-%m-%dT%H_%M_%S).zip
|
||||
FILE=`ls $NAMESPACE-*.zip`
|
||||
aws s3 cp $FILE s3://commonjobs/$NAMESPACE/$opt/
|
||||
kubectl delete po common-job-pod -n $NAMESPACE
|
||||
cat script.log | egrep -v "Errors:|inflating|adding|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
||||
;;
|
||||
|
||||
mysql-restore)
|
||||
|
||||
aws eks update-kubeconfig --name caresage-eks-cluster-$ENV --region us-east-1
|
||||
kubectl apply -f build/$ENV/pod.tpl && kubectl apply -f build/$ENV/pvc.yml && echo pod-created && sleep 15
|
||||
kubectl cp setenv.sh $NAMESPACE/common-job-pod:/tmp/setenv.sh
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'chmod 755 /tmp/setenv.sh'
|
||||
|
||||
[ -n "$RESTORE_VERSION" ] && FILE=$RESTORE_VERSION || FILE=$deploy_version
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt-key adv --fetch-keys 'https://packages.sury.org/php/apt.gpg' > /dev/null 2>&1
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt update
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt install zip wget unzip curl mariadb-client -y
|
||||
|
||||
#Check if file is present in bitbucket download else check on s3
|
||||
# -------------------------------------------------------------------
|
||||
curl -s -L -O -H "Authorization: Bearer $TOKEN" https://api.bitbucket.org/2.0/repositories/connectamerica/$REPO/downloads/$FILE && echo file_downloaded || aws s3 cp s3://commonjobs/$NAMESPACE/mysql-backup/$FILE $FILE
|
||||
|
||||
# --------------------------------------------------------
|
||||
kubectl cp $FILE $NAMESPACE/common-job-pod:/tmp/$FILE
|
||||
kubectl cp wp $NAMESPACE/common-job-pod:/tmp && echo "wp copy to /tmp done" || exit 9
|
||||
kubectl cp setenv.sh $NAMESPACE/common-job-pod:/tmp/setenv.sh && echo "setenv copy done" || exit 9
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'chmod 755 /tmp/setenv.sh'
|
||||
# ----------------------------------------------------------------------------------------
|
||||
|
||||
#Create schema if not present #
|
||||
# -------------------------------
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c '. /tmp/setenv.sh; mysql -h $DB_HOST --user=$DB_USER --password=$DB_PASSWORD -e "create schema IF NOT EXISTS $SUBDOMAIN"'
|
||||
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c '. /tmp/setenv.sh; export FILE=`ls /tmp/*.sql.gz` ; gunzip -c $FILE | mysql -h $DB_HOST --user=$DB_USER --password=$DB_PASSWORD $SUBDOMAIN'
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c '. /tmp/setenv.sh; mysql -h $DB_HOST --user=$DB_USER --password=$DB_PASSWORD -e "DROP TABLE IF EXISTS $SUBDOMAIN._pantheon_heartbeat"'
|
||||
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar ; chmod u+x wp-cli.phar;mv wp-cli.phar /usr/local/bin/wp; php /usr/local/bin/wp --info'
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c '. /tmp/setenv.sh; OLD_URL=`wp option get siteurl --allow-root --path=/tmp/wp`; echo "export OLD_URL=$OLD_URL" >> /tmp/setenv.sh; echo "export FIND=$(echo $OLD_URL|cut -d. -f2,3)" >> /tmp/setenv.sh; echo "export OLD_MAIN_DOMAIN=$(echo $OLD_URL|cut -d. -f2,3)" >> /tmp/setenv.sh; echo "export OLD_URL_DOMAIN=$(echo $OLD_URL| cut -d/ -f3)" >> /tmp/setenv.sh; echo "export OLD_SUBDOMAIN=$(echo $OLD_URL| cut -d/ -f3|cut -d. -f1)" >> /tmp/setenv.sh'
|
||||
# -----------------------------------------------------------------------------------------
|
||||
kubectl cp $NAMESPACE/common-job-pod:/tmp/setenv.sh setenv.sh && . ./setenv.sh
|
||||
# -----------------------------------------------------------------------------------------
|
||||
if [[ "$OLD_SUBDOMAIN" = "www" ]] && [[ "$SUBDOMAIN" = "www" ]]; then
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'cat /tmp/setenv.sh ; . /tmp/setenv.sh; wp search-replace --allow-root --path=/tmp/wp "$OLD_URL_DOMAIN" "$URL_DOMAIN" --all-tables'
|
||||
|
||||
[[ "$APP" = "connectamerica" ]] && kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'cat /tmp/setenv.sh ; . /tmp/setenv.sh; wp search-replace --allow-root --path=/tmp/wp ".$OLD_MAIN_DOMAIN" ".$MAIN_DOMAIN" --all-tables'
|
||||
|
||||
|
||||
elif [[ "$OLD_SUBDOMAIN" = "www" ]] && [[ "$SUBDOMAIN" != "www" ]]; then
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'cat /tmp/setenv.sh ; . /tmp/setenv.sh; wp search-replace --allow-root --path=/tmp/wp "$OLD_URL_DOMAIN" "$URL_DOMAIN" --all-tables'
|
||||
[[ "$APP" = "connectamerica" ]] && kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'cat /tmp/setenv.sh ; . /tmp/setenv.sh; wp search-replace --allow-root --path=/tmp/wp ".$OLD_MAIN_DOMAIN" ".$URL_DOMAIN" --all-tables'
|
||||
|
||||
|
||||
elif [[ "$OLD_SUBDOMAIN" != "www" ]] && [[ "$SUBDOMAIN" = "www" ]]; then
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'cat /tmp/setenv.sh ; . /tmp/setenv.sh; wp search-replace --allow-root --path=/tmp/wp ".$OLD_URL_DOMAIN" ".$MAIN_DOMAIN" --all-tables'
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'cat /tmp/setenv.sh ; . /tmp/setenv.sh; wp search-replace --allow-root --path=/tmp/wp "$OLD_URL_DOMAIN" "$URL_DOMAIN" --all-tables'
|
||||
|
||||
|
||||
elif [[ "$OLD_SUBDOMAIN" != "www" ]] && [[ "$SUBDOMAIN" != "www" ]]; then
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'cat /tmp/setenv.sh ; . /tmp/setenv.sh; wp search-replace --allow-root --path=/tmp/wp "$OLD_URL_DOMAIN" "$URL_DOMAIN" --all-tables'
|
||||
|
||||
else
|
||||
echo "======== fix the issues ============="
|
||||
fi
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------------------
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c '. /tmp/setenv.sh; wp search-replace --allow-root --path=/tmp/wp "http://$NEW_URL" "https://$NEW_URL" --all-tables'
|
||||
|
||||
kubectl delete po common-job-pod -n $NAMESPACE
|
||||
cat script.log | egrep -v "Errors:|inflating|adding|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
||||
;;
|
||||
|
||||
|
||||
wp-data-restore)
|
||||
aws eks update-kubeconfig --name caresage-eks-cluster-$ENV --region us-east-1
|
||||
kubectl apply -f build/$ENV/pod.tpl && kubectl apply -f build/$ENV/pvc.yml && echo pod-created && sleep 15
|
||||
kubectl get po common-job-pod -n $NAMESPACE | grep -i pending && exit 9 || echo ----common-pod-NOT-in-pending-state --
|
||||
|
||||
kubectl cp setenv.sh $NAMESPACE/common-job-pod:/tmp/setenv.sh
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c 'chmod 755 /tmp/setenv.sh'
|
||||
|
||||
[ -n "$RESTORE_VERSION" ] && FILE=$RESTORE_VERSION || FILE=$deploy_version
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt-key adv --fetch-keys 'https://packages.sury.org/php/apt.gpg' > /dev/null 2>&1
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt update
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- apt install wget zip unzip curl rsync rclone -y
|
||||
aws s3 cp s3://commonjobs/$NAMESPACE/wp-data-backup/$FILE $FILE
|
||||
kubectl cp $FILE $NAMESPACE/common-job-pod:/tmp/$FILE
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c '. /tmp/setenv.sh; mkdir -p /usr/share/nginx/subdomain/$SUBDOMAIN/wp-content/uploads'
|
||||
# ----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c '. /tmp/setenv.sh; mkdir /tmp/uploads ;export FILE=`ls /tmp/*.zip`;unzip -o $FILE -d /tmp/uploads'
|
||||
kubectl exec common-job-pod -n $NAMESPACE -- sh -c '. /tmp/setenv.sh; rclone sync /tmp/uploads/ /usr/share/nginx/subdomain/$SUBDOMAIN/wp-content/uploads -q && echo ---sync-done--- '
|
||||
|
||||
#------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
kubectl delete po common-job-pod -n $NAMESPACE
|
||||
cat script.log | egrep -v "Errors:|inflating|adding|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
||||
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "common job shell script utility taking variables from env"
|
||||
echo "Usage: $0 {mysql-backup|wp-data-backup|mysql-restore|wp-data-restore}"
|
||||
echo "mysql-backup : Run MySQL backup utility and upload"
|
||||
echo "mysql-restore : Run MySQL backup utility and upload it to bitbucket."
|
||||
echo "wp-data-backup : Run web server backup utility and uplaod."
|
||||
echo "wp-data-restore : Run web server backup utility and uplaod to bitbucket." ;;
|
||||
esac
|
||||
@@ -1,68 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
# Install the required packages #
|
||||
# --------------------------------------------------------------
|
||||
apt update && apt install curl unzip zip mariadb-client -y
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install
|
||||
# -------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
opt=$1
|
||||
case $opt in
|
||||
mysql-backup)
|
||||
echo "Running mysql backup with s3..."
|
||||
export DATABASES=perchon
|
||||
export MYSQL_USER=perchona
|
||||
|
||||
# execute the command now #
|
||||
# --------------------------------------------------------------------------------------------------------------
|
||||
mysqldump -h $DB_HOST --single-transaction --quick --lock-tables=false --user=pantheon --password=$DB_PASSWORD \
|
||||
pantheon --skip-lock-tables | gzip > "/tmp/lifeline-web-pantheon-$(date +%Y-%m-%dT%H_%M_%S).sql.gz"
|
||||
# ----------------------------------------------------------------------------------------------------------
|
||||
|
||||
# upload the same to s3 #
|
||||
# -----------------------------------------
|
||||
# aws s3 cp /tmp/lifeline-web-pantheon-*.sql.gz s3://caresage-dev-ws/mysqlbackups/
|
||||
# aws s3 ls s3://caresage-dev-ws/mysqlbackups/
|
||||
|
||||
# upload to bitbucket #
|
||||
# ---------------------------------------
|
||||
FILE=`ls /tmp/lifeline-web-pantheon-*.sql.gz`
|
||||
curl --request POST -F files=@"$FILE" --url 'https://api.bitbucket.org/2.0/repositories/connectamerica/lifeline-ecommerce/downloads' \
|
||||
--header "Authorization: Bearer $TOKEN"
|
||||
;;
|
||||
|
||||
|
||||
mysql-backup-bitbucket)
|
||||
echo "Running bmysql-backup-s3 with bitbucket ..."
|
||||
export DATABASES=perchona
|
||||
export MYSQL_USER=perchona
|
||||
;;
|
||||
|
||||
|
||||
wp-data-backup)
|
||||
echo "Running wp-data-s3..."
|
||||
cd /usr/share/nginx/html/wp-content/
|
||||
zip -r lifeline-web-static-data-$(date +%Y-%m-%dT%H_%M_%S).zip ./uploads && FILE=`ls lifeline-web-static-data-*.zip`
|
||||
curl --request POST -F files=@"$FILE" --url 'https://api.bitbucket.org/2.0/repositories/connectamerica/lifeline-ecommerce/downloads' \
|
||||
--header "Authorization: Bearer $TOKEN"
|
||||
#aws s3 mv lifeline-web-static-data-*.zip s3://caresage-dev-ws/staticbackups/
|
||||
#aws s3 ls s3://caresage-dev-ws/staticbackups/
|
||||
|
||||
|
||||
;;
|
||||
|
||||
|
||||
wp-data-bitbucket)
|
||||
echo "Running wp-data-bitbucket ..."
|
||||
;;
|
||||
|
||||
|
||||
*)
|
||||
echo "common job shell script utility taking variables from env"
|
||||
echo "Usage: $0 {mysql-backup|mysql-backup-bitbucket|wp-data-backup}"
|
||||
echo " mysql-backup : Run MySQL backup utility and upload"
|
||||
echo " mysql-backup-bitbucket : Run MySQL backup utility and upload it to bitbucket."
|
||||
echo " wp-data-backup : Run web server backup utility and uplaod."
|
||||
echo " wp-data-bitbucket : Run web server backup utility and uplaod to bitbucket." ;;
|
||||
esac
|
||||
@@ -1,5 +0,0 @@
|
||||
env["CACHE_PASSWORD"] = $CACHE_PASSWORD
|
||||
env["CACHE_HOST"] = $CACHE_HOST
|
||||
env["CACHE_PORT"] = $CACHE_PORT
|
||||
env["DB_PASSWORD"] = $DB_PASSWORD
|
||||
env["DB_HOST"] = $DB_HOST
|
||||
@@ -1,50 +0,0 @@
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: common-jobs
|
||||
namespace: lifeline-web
|
||||
labels:
|
||||
app: lifeline-web
|
||||
rds: enable
|
||||
spec:
|
||||
ttlSecondsAfterFinished: 10
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: lifeline-web
|
||||
rds: enable
|
||||
spec:
|
||||
affinity:
|
||||
nodeAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
nodeSelectorTerms:
|
||||
- matchExpressions:
|
||||
- key: kubernetes.io/arch
|
||||
operator: In
|
||||
values:
|
||||
- amd64
|
||||
- arm64
|
||||
containers:
|
||||
- name: common-jobs
|
||||
image: ubuntu:latest
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: lifeline-web-secrets
|
||||
- configMapRef:
|
||||
name: lifeline-web-cm
|
||||
command: ["bash"]
|
||||
args:
|
||||
- -c
|
||||
- cp -rf /usr/share/nginx/subdomain/www/wp-content/uploads/common-jobs.sh /root/ && chmod 755 /root/common-jobs.sh && /root/common-jobs.sh $JOBNAME
|
||||
volumeMounts:
|
||||
- mountPath: /usr/share/nginx/subdomain/www/wp-content/uploads
|
||||
name: persistent-storage
|
||||
imagePullSecrets:
|
||||
- name: regcred
|
||||
nodeSelector:
|
||||
kubernetes.io/os: linux
|
||||
restartPolicy: Never
|
||||
volumes:
|
||||
- name: persistent-storage
|
||||
persistentVolumeClaim:
|
||||
claimName: efs-claim-lifeline
|
||||
@@ -1,49 +0,0 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
deployment.kubernetes.io/revision: "1"
|
||||
generation: 1
|
||||
labels:
|
||||
role: db-ca
|
||||
type: rds-mysql-ca
|
||||
name: mysql-medicalalert
|
||||
namespace: caresage-exec
|
||||
spec:
|
||||
progressDeadlineSeconds: 600
|
||||
replicas: 1
|
||||
revisionHistoryLimit: 10
|
||||
selector:
|
||||
matchLabels:
|
||||
role: db-ca
|
||||
type: rds-mysql-ca
|
||||
strategy:
|
||||
rollingUpdate:
|
||||
maxSurge: 25%
|
||||
maxUnavailable: 25%
|
||||
type: RollingUpdate
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
role: db-ca
|
||||
type: rds-mysql-ca
|
||||
spec:
|
||||
containers:
|
||||
- args:
|
||||
- tcp-listen:3306,fork,reuseaddr
|
||||
- tcp-connect:dev-medicalalert-ecommerce.c5om7w6xopq1.us-east-1.rds.amazonaws.com:3306
|
||||
image: alpine/socat
|
||||
imagePullPolicy: Always
|
||||
name: mysql-100plus
|
||||
ports:
|
||||
- containerPort: 3306
|
||||
protocol: TCP
|
||||
resources: {}
|
||||
terminationMessagePath: /dev/termination-log
|
||||
terminationMessagePolicy: File
|
||||
dnsPolicy: ClusterFirst
|
||||
restartPolicy: Always
|
||||
schedulerName: default-scheduler
|
||||
securityContext: {}
|
||||
terminationGracePeriodSeconds: 30
|
||||
Binary file not shown.
1947
backups/php.ini
1947
backups/php.ini
File diff suppressed because it is too large
Load Diff
@@ -1,14 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------
|
||||
export WP_FILE="/usr/share/nginx/subdomain/www/wp-config.php"
|
||||
|
||||
sed -i '/^define.*NONCE_SALT.*/a define(\'\'WP_SITEURL\'', '\'http://localhost/\'');' $WP_FILE || exit 9
|
||||
sed -i '/^define.*NONCE_SALT.*/a define(\'\'WP_HOME\'', '\'http://localhost/\'');' $WP_FILE || exit 9
|
||||
|
||||
wget -q --spider localhost && echo pass-localhost || exit 9
|
||||
sleep 1
|
||||
wget -q --spider localhost/wp-login.php && echo pass-wp-login.php|| exit 9
|
||||
|
||||
sed -i '/http\:\/\/localhost/d' $WP_FILE || exit 9
|
||||
# ---------------------------------------------------
|
||||
@@ -1,83 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
export DIR=`pwd`
|
||||
exec > >(tee -a $DIR/script.log) 2>&1
|
||||
|
||||
function install {
|
||||
|
||||
# kubectl
|
||||
# ----------------
|
||||
curl -fsSLO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
|
||||
chmod +x ./kubectl
|
||||
mv ./kubectl /usr/local/bin/kubectl
|
||||
# setenv
|
||||
# -----------
|
||||
. ./setenv.sh
|
||||
|
||||
# krew
|
||||
# ---------
|
||||
set -x; cd "$(mktemp -d)" &&
|
||||
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
|
||||
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
|
||||
KREW="krew-${OS}_${ARCH}" &&
|
||||
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
|
||||
tar zxvf "${KREW}.tar.gz" &&
|
||||
./"${KREW}" install krew &&
|
||||
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" >> ~/.bashrc && . ~/.bashrc
|
||||
|
||||
# kubeval
|
||||
# -------------------
|
||||
curl -fsSLO https://github.com/instrumenta/kubeval/releases/latest/download/kubeval-linux-amd64.tar.gz
|
||||
tar xf kubeval-linux-amd64.tar.gz &&
|
||||
cp kubeval /usr/local/bin
|
||||
|
||||
# kube-score
|
||||
# ---------------
|
||||
kubectl krew install score
|
||||
|
||||
}
|
||||
|
||||
install
|
||||
|
||||
default () {
|
||||
|
||||
cd $DIR/build
|
||||
find . -type f -exec kubeval --ignore-missing-schemas '{}' \; | tee -a $DIR/script.log
|
||||
|
||||
find . -type f -exec kubectl score --output-format ci '{}' \; | tee -a $DIR/script.log
|
||||
|
||||
cat $DIR/script.log | egrep -v -i "script.log|warning|SQL|create mode|rewrite" | egrep -i "fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file|ERR" && exit 9 || echo VALIDATION_PASS_$opt
|
||||
|
||||
}
|
||||
|
||||
|
||||
opt=$1
|
||||
|
||||
case $opt in
|
||||
|
||||
default)
|
||||
|
||||
default
|
||||
;;
|
||||
|
||||
env)
|
||||
|
||||
env
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "validation job shell script utility taking variables from env"
|
||||
echo "Usage: $0 {default|env}"
|
||||
|
||||
esac
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#cat $DIR/script.log | egrep -v -i "script.log|warning|SQL|create mode|rewrite" | egrep -i "fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file|ERR" && exit 9 || echo VALIDATION_PASS_$opt
|
||||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
NAMESPACE=medicalalert-web
|
||||
|
||||
if [ "$ENV" = "dev" ]; then
|
||||
pods=`kubectl get pods --no-headers -o custom-columns=":metadata.name" -n $NAMESPACE`
|
||||
for i in $pods; do
|
||||
kubectl exec $i -n $NAMESPACE -- apt-key adv --fetch-keys 'https://packages.sury.org/php/apt.gpg' > /dev/null 2>&1
|
||||
kubectl exec $i -n $NAMESPACE -- apt-get update
|
||||
kubectl exec $i -n $NAMESPACE -- apt-get install rclone rsync -y
|
||||
kubectl exec $i -n $NAMESPACE -- sh -c 'for j in dev02 dev03 dev04 dev05; do cd /usr/share/nginx/subdomain && rclone sync --exclude wp-content/uploads/** $j/ /usr/share/nginx/subdomain/$j-web -q && echo ---sync-done from efs to local for $j-web --- && cd $j-web/wp-content && [ -L uploads ] && [ -e uploads ]] && echo ----symlink-exist--- || ln -s /usr/share/nginx/subdomain/$j/wp-content/uploads uploads && chown -R nginx:nginx /usr/share/nginx/subdomain/$j-web;done'
|
||||
|
||||
done
|
||||
else
|
||||
|
||||
echo ----The env is $ENV and thus no multidev applicable----
|
||||
|
||||
fi
|
||||
@@ -1,83 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
exec > >(tee -a script.log) 2>&1
|
||||
|
||||
# Install the required packages #
|
||||
# --------------------------------------------------------------
|
||||
apk upgrade && apk add --update curl wget zip unzip coreutils
|
||||
|
||||
cat schedule-setenv.sh && . ./schedule-setenv.sh
|
||||
|
||||
opt=$1
|
||||
|
||||
case $opt in
|
||||
|
||||
create-schedule-pipelines)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#curl --request POST --url "https://api.bitbucket.org/2.0/repositories/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pipelines_config/schedules" --header "Authorization: Bearer $TOKEN" --header 'Accept: application/json' --header "Content-Type: application/json" --data { \"type\": \"pipeline_schedule\", \"enabled\": true, \"target\": { \"ref_type\": \"branch\", \"type\": \"pipeline_ref_target\", \"ref_name\": \"$BRANCH_NAME\", \"selector\": { \"type\": \"custom\", \"pattern\": \"$PIPELINE_NAME\" } }, \"cron_pattern\": \"$CRONTIME\" }
|
||||
# -----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
curl -X POST https://api.bitbucket.org/2.0/repositories/connectamerica/100plus-web/pipelines_config/schedules -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: Bearer $TOKEN" -d "{
|
||||
\"type\": \"pipeline_schedule\",
|
||||
\"enabled\": true,
|
||||
\"target\": {
|
||||
\"ref_type\": \"branch\",
|
||||
\"type\": \"pipeline_ref_target\",
|
||||
\"ref_name\": \"$BRANCH_NAME\",
|
||||
\"selector\": {
|
||||
\"type\": \"custom\",
|
||||
\"pattern\": \"$PIPELINE_NAME\"
|
||||
}
|
||||
},
|
||||
\"cron_pattern\": \"$CRONTIME\"
|
||||
}"
|
||||
|
||||
|
||||
|
||||
echo "" && echo -----------------------------------
|
||||
|
||||
cat script.log | egrep -v "Errors:|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|Permission denied|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
||||
|
||||
;;
|
||||
|
||||
delete-schedule-pipelines)
|
||||
|
||||
for i in `curl -s --request GET --url "https://api.bitbucket.org/2.0/repositories/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pipelines_config/schedules" --header "Authorization: Bearer $TOKEN" --header 'Accept: application/json'| jq ".values[].target.selector.pattern+.values[].uuid" |awk -F'["{}]' '{print $3}'| uniq`
|
||||
|
||||
do
|
||||
|
||||
echo curl --location -g --request DELETE --url \'https://api.bitbucket.org/2.0/repositories/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pipelines_config/schedules/{$i}\' --header \'Authorization: Bearer $TOKEN\' > delete.sh
|
||||
|
||||
chmod 755 delete.sh && ./delete.sh
|
||||
|
||||
done
|
||||
|
||||
cat script.log | egrep -v "Errors:|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|Permission denied|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
||||
|
||||
;;
|
||||
|
||||
|
||||
list-schedule-pipelines)
|
||||
|
||||
echo "" && echo ----------------------------------------------
|
||||
|
||||
curl -s --request GET --url "https://api.bitbucket.org/2.0/repositories/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pipelines_config/schedules" --header "Authorization: Bearer $TOKEN" --header 'Accept: application/json' | jq .
|
||||
|
||||
echo ""
|
||||
|
||||
cat script.log | egrep -v "Errors:|SQL|rewrite|Rewrite|warning|Warning|create mode" | egrep -i "not in gzip format|Permission denied|fail|fatal|exception|terminated|command not found|error|unexpected|cannot access|No such file" && exit 9 || echo VALIDATION_PASS_$opt
|
||||
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "script for schedule-pipelines"
|
||||
echo "Usage: schedule-pipeline.sh {create-schedule-pipelines|delete-schedule-pipelines}"
|
||||
echo "create-schedule-pipelines : create-schedule-pipelines"
|
||||
echo "delete-schedule-pipelines : delete-schedule-pipelines"
|
||||
echo "list-schedule-pipelines : list-schedule-pipelines"
|
||||
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user