1#!/bin/bash 2# Note: this is managed by Ansible, as deploy-sh.j2 3# Don't modify this file unless its name is deploy-sh.j2 4GITHUB_SHA=$1 5UNLOCK=$2 6WORKDIR=${TMPDIR-/tmp} # keep all random files here 7SERVICE="{{ cldr_openliberty_service }}" 8 9# TODO: "dogit" could be split out as a separate script 10dogit() { 11 rm -f ${WORKDIR}/git-list.txt 12 if [[ ${GITHUB_SHA} = "master" ]]; 13 then 14 echo "changing 'master' to 'origin/master' to get the latest" 15 GITHUB_SHA=origin/master 16 fi 17 git fetch -p || exit 1 18 git clean -f -d || echo 'warning: err on cleanup' 19 # what are we deploying? 20 21 echo "cldr-trunk was at :" $(git rev-parse --short HEAD) 22 echo -n "you want to move to:" 23 git rev-parse --short "${GITHUB_SHA}" || exit 1 # fail on err 24 if [[ $(git rev-parse --short HEAD) = $(git rev-parse --short "${GITHUB_SHA}") ]]; 25 then 26 echo "No checkout needed. Continuing with redeploy." 27 else 28 echo "Deploy will include these new items:" 29 echo "---" 30 (git log --oneline HEAD..${GITHUB_SHA} | tee ${WORKDIR}/git-list.txt) || exit 1 31 echo "---" 32 if [[ ! -s ${WORKDIR}/git-list.txt ]]; # if empty.. 33 then 34 echo "Note, ${GITHUB_SHA} is not ahead of HEAD" $(git rev-parse --short HEAD) 35 echo "Checking for items that would be REVERTED if we proceed:" 36 echo "---" 37 git log --oneline ${GITHUB_SHA}..HEAD 38 echo "---" 39 if [[ "${UNLOCK}" = "--override" ]]; 40 then 41 echo ".. continuing anyway! due to " "${UNLOCK}" 42 else 43 echo "STOP. Check the override box if you really want to do this" 44 exit 1 45 fi 46 fi 47 git checkout -f ${GITHUB_SHA} 48 echo "HEAD is now at" $(git rev-parse --short HEAD) "!" 49 fi 50} 51 52# Check git first, before undeploying. Want to exit early 53(cd {{ cldr_trunk_path }} && dogit ) || exit 1 54# 55# stop server 56sudo -u root /usr/sbin/service ${SERVICE} stop 57# clear cache 58if [[ -d /srv/st/config/.cache ]]; 59then 60 echo "Deleting cache /srv/config/.cache" 61 rm -rf /srv/st/config/.cache 62fi 63rm -fv ${WORKDIR}/cldr-apps.zip ${WORKDIR}/deploystatus 64# copy cldr-apps.zip from action runner to server 65dd bs=1024000 status=progress of=${WORKDIR}/cldr-apps.zip 66# this counts the # of files to make sure it's not too short, but also verifies that unzip is OK 67echo ; echo -n 'Unzip check, # of files in cldr-apps.zip: ' 68(unzip -l ${WORKDIR}/cldr-apps.zip | wc -l ) || exit 1 69cd ${WORKDIR} || exit 1 70rm -rf ./deploy || exit 1 71mkdir ./deploy 72cd ./deploy 73unzip ${WORKDIR}/cldr-apps.zip 74if [[ ! -d ./wlp ]]; 75then 76 echo "Error, did not get a ./wlp dir from this zip.. stop" 77 exit 1 78fi 79# Now, do the deployment! 80# exclude these two files 81rsync -r --exclude server.env --exclude workarea --exclude bootstrap.properties -v \ 82 --delete ./wlp/usr/servers/cldr/* /var/lib/openliberty/usr/servers/cldr/ || exit 1 83sudo -u root /usr/sbin/service ${SERVICE} start || exit 1