| #/bin/bash | |||||
| rm -rf /tmp/goweb | |||||
| mkdir -p /tmp/goweb | |||||
| cp -a . /tmp/goweb/ | |||||
| rm -rf /tmp/goweb/html/* | |||||
| rsync -avh /mnt/hgfs/workspace/2021-07-31-BiukopWeb/ /tmp/goweb/html/ | |||||
| cd /tmp/goweb | |||||
| gcloud app deploy |
| { | |||||
| // Use IntelliSense to learn about possible attributes. | |||||
| // Hover to view descriptions of existing attributes. | |||||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |||||
| "version": "0.2.0", | |||||
| "configurations": [ | |||||
| { | |||||
| "type": "bashdb", | |||||
| "request": "launch", | |||||
| "name": "Bash-Debug (simplest configuration)", | |||||
| "program": "${file}" | |||||
| } | |||||
| ] | |||||
| } |
| #!/bin/bash | |||||
| PROJ_DIR="/home/sp/go/src/goweb" | |||||
| UPDATE_HTML="update-go-web-html" | |||||
| HTML_WORKDIR="/tmp/$UPDATE_HTML" | |||||
| REMOTE_WORK="/home/sp/$UPDATE_HTML" | |||||
| #/bin/bash | |||||
| SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | |||||
| PROJ_DIR="$SCRIPT_DIR/../" | |||||
| rm -rf /tmp/goweb | |||||
| mkdir -p /tmp/goweb | |||||
| rsync -a $PROJ_DIR /tmp/goweb/ | |||||
| rm -rf /tmp/goweb/html/* | |||||
| rsync -avh /mnt/hgfs/workspace/2021-07-31-BiukopWeb/ /tmp/goweb/html/ | |||||
| cd /tmp/goweb | |||||
| #gcloud app deploy | |||||
| source $SCRIPT_DIR/gcp_version.sh | |||||
| del_old_instances |
| #!/bin/bash | |||||
| GCP_VERSIONS=() | |||||
| LAST_VERSION_ID="" | |||||
| INSTANCE_ID="" | |||||
| get_instance_id() { | |||||
| # SERVICE VERSION ID VM_STATUS VM_LIVENESS DEBUG_MODE | |||||
| # default 20210807t221459 aef-default-20210807t221459-1nqz RUNNING HEALTHY YES | |||||
| echo "Getting gcloud instance id ..." | |||||
| if [ "$INSTANCE_ID" == "" ] | |||||
| then | |||||
| output=` gcloud app instances list | grep RUNNING` # get the running version only | |||||
| INSTANCE_ID=(` echo $output | awk -F' ' '{print $3}' `) | |||||
| LAST_VERSION_ID=(` echo $output | awk -F' ' '{print $2}' `) | |||||
| fi | |||||
| } | |||||
| del_old_instances(){ | |||||
| get_instance_id | |||||
| echo "RUNNING VERSION: " $LAST_VERSION_ID | |||||
| GCP_VERSIONS=(` gcloud app versions list | awk -F' ' '{print $2}' `) | |||||
| LENGTH=${#GCP_VERSIONS[@]} | |||||
| for i in $(seq 1 1 $(expr $LENGTH - 1) ) | |||||
| do | |||||
| if [ "${GCP_VERSIONS[$i]}" != "$LAST_VERSION_ID" ] ; then | |||||
| echo "delete old version ${GCP_VERSIONS[$i]} " | |||||
| del_instance_by_version ${GCP_VERSIONS[$i]} | |||||
| else | |||||
| echo "KEEP RUNNING VERSION ${GCP_VERSIONS[$i]}" | |||||
| fi | |||||
| done | |||||
| } | |||||
| del_instance_by_version() { | |||||
| versionId=$1 | |||||
| if [ "$versionId" == "" ]; then | |||||
| return | |||||
| fi | |||||
| gcloud app versions delete --service=default $versionId ; | |||||
| # while true; do | |||||
| # read -p "Do you wish to delete version $versionId ?" yn | |||||
| # case $yn in | |||||
| # [Yy]* ) | |||||
| # echo gcloud app instances delete $INSTANCE_ID --service=default --version=$versionId ; | |||||
| # break;; | |||||
| # [Nn]* ) exit;; | |||||
| # * ) echo "Please answer yes or no.";; | |||||
| # esac | |||||
| # done | |||||
| } | |||||
| #!/bin/bash | |||||
| SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | |||||
| source $SCRIPT_DIR/config.sh | |||||
| NOW=$(date +"%m-%d-%Y") | |||||
| MERGED404PATH=`find /var/lib/docker/overlay2/ -name '404.html' | grep merged ` | |||||
| SRC="$SCRIPT_DIR/../html/" | |||||
| DEST="$(dirname ${MERGED404PATH})/" | |||||
| #clear | |||||
| rm -rf $SRC | |||||
| #untar recreate SRC | |||||
| cd "$SCRIPT_DIR/.." | |||||
| tar -xvf "$SCRIPT_DIR/../html.tar.gz" | |||||
| echo "======= check source directory ========= " | |||||
| ls -R $SRC | |||||
| # command looks like | |||||
| # "rsync --delete -avz /home/sp/goweb/html/ | |||||
| # /var/lib/docker/overlay2/511128e41cf1c2df2f270176d6f8de647ef5bcffe44e0d2e2317a4914123e03c/merged/app/html/ | |||||
| # >> /home/sp/goweb/rsync-html-$NOW.log" | |||||
| echo "===== rsync --delete -avz $SRC $DEST >> ${SCRIPT_DIR}/rsync-html-$NOW.log ======" | |||||
| rsync --delete -avz $SRC $DEST >> ${SCRIPT_DIR}/rsync-html-$NOW.log | |||||
| echo "--- remote log for rsync ---- " | |||||
| cat ${SCRIPT_DIR}/rsync-html-$NOW.log | |||||
| #!/bin/bash | |||||
| source config.sh | |||||
| source gcp_version.sh | |||||
| get_instance_id | |||||
| echo INSTANCE ID: $INSTANCE_ID | |||||
| echo VERSION: $LAST_VERSION_ID | |||||
| rm -rf $HTML_WORKDIR | |||||
| mkdir -p $HTML_WORKDIR | |||||
| rsync -a $PROJ_DIR/deploy $HTML_WORKDIR | |||||
| mkdir -p "$HTML_WORKDIR/html" | |||||
| rsync -a /mnt/hgfs/workspace/2021-07-31-BiukopWeb/* "$HTML_WORKDIR/html/" | |||||
| #create compressed archive | |||||
| echo tar -zcvf -C $HTML_WORKDIR $HTML_WORKDIR/html.tar.gz "$HTML_WORKDIR/html/" | |||||
| tar -C $HTML_WORKDIR -zcvf $HTML_WORKDIR/html.tar.gz "html" | |||||
| rm -rf "$HTML_WORKDIR/html/" | |||||
| rm -f "/home/sp/.ssh/google_compute_known_hosts" | |||||
| # copy deploy script and html to destination | |||||
| echo "===copy $HTML_WORKDIR to remote instance ======" | |||||
| gcloud app instances scp --recurse "$HTML_WORKDIR" $INSTANCE_ID:/home/sp/ --service=default --version=$LAST_VERSION_ID | |||||
| # copy html | |||||
| echo "===execute remote sync======" | |||||
| gcloud app instances ssh $INSTANCE_ID --service=default --version=$LAST_VERSION_ID -- sudo bash $REMOTE_WORK/deploy/r_sync_html.sh |
| custom 404 | |||||
| <html> | |||||
| <body> | |||||
| custom 404 | |||||
| <img src="favicon.ico" /> | |||||
| </body> | |||||
| </html> |
| func fileSystem404(w http.ResponseWriter, r *http.Request) (doDefaultFileServe bool) { | func fileSystem404(w http.ResponseWriter, r *http.Request) (doDefaultFileServe bool) { | ||||
| //if not found redirect to / | //if not found redirect to / | ||||
| r.URL.Path = "/404.html" | |||||
| return true | |||||
| // r.URL.Path = "/404.html" //not working as some directorys may not be feasible. | |||||
| // return true | |||||
| http.Redirect(w, r, "/404.html", http.StatusSeeOther) | |||||
| return false | |||||
| } | } |