Is there any documentation available on how to deploy code from BitBucket to Google Compute Engine. Can see documentation on Google App Engine, but not Compute Engine.
2 Answers
Google Compute Engine basically a VM, so you would deploy code just like any other VM. You could SSH into the instance, git pull from bitbucket (using an ssh deployment key), and then do whatever you need to do.
That's not the best, reproducible method, however. Is there a particular reason why GCE is what you want? If you are familiar with Docker, then I'd recommend going to Cloud Run or App Engine Flex, which handles the underlying infrastructure for you.
I suggest you to do the following.
First of all, make sure that you have the packages "git" and "rsync" installed on your GCE, on the VM run:
apt-get update && apt-get install -y git rsync
Also you will want to create an “aux” dir necessary for the procedure, on the VM run:
mkdir /path/to/aux/dir/
Then activate your Cloud Shell and create a new firewall rule that will allow you to do SSH connections to your GCE Instance:
gcloud compute --project=PROJECT_ID firewall-rules create gcloud-ssh --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:22 --source-ranges=0.0.0.0/0 --target-tags=gcloud-ssh
After that, go to the view "Compute Engine > VM instances" in the Cloud Console and select your GCE instance, click on "EDIT" on the topbar and in the section "Network tags" add the tag "gcloud-ssh". That will apply the network tag created before on that particular VM.
Now you should be able to make code deployments on that VM with the execution of this command via the Cloud Shell:
gcloud compute --project=PROJECT_ID ssh --zone "VM_ZONE" "VM_NAME" --command="sudo rm -rf /path/to/aux/dir/ && sudo mkdir /path/to/aux/dir/ && cd /path/to/aux/dir/ && sudo git clone https://BITBUCKET_USERNAME:BITBUCKET_PASSWORD@BITBUCKET_REPOSITORY . >> /dev/null 2>&1 && sudo rsync -a --delete /path/to/aux/dir/ /path/to/code/dir/"
Hopefully this will solve your issue.