I have a compute engine instance and the start-up script to it includes the following lines.
# Get the application source code from the Google Cloud Repository.
# git requires $HOME and it's not set during the startup script.
export HOME=/root
git config --global credential.helper gcloud.sh
git clone https://source.developers.google.com/p/$PROJECTID /opt/app
This code tells the VM to get source code from the cloud repository, my application code. Whenever I modify my sourcecode and push the changes to the repository and re-start my vm, the vm isn't executing the new code. How would I make the vm run the new code without deleting the instance and creating a new one?
GCE VM startup scripts run on every boot, not just the first boot, so you should only clone the repo on first time, and then update every other time, e.g.,
# Note: this script is untested but should work.
export HOME=/root
git config --global credential.helper gcloud.sh
declare -r LOCAL_GIT_REPO="/opt/app"
if ! [[ -e "${LOCAL_GIT_REPO}" ]]; then
git clone https://source.developers.google.com/p/$PROJECTID "${LOCAL_GIT_REPO}"
else
cd "${LOCAL_GIT_REPO}"
git pull
fi
Then, you can re-run this script manually anytime to update your repo while your instance is running. If you want to have the instance update its own code automatically, call this script from cron
. You can learn how to set up periodic command runs via man cron
and man crontab
.