Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

CD Cloud Build + Git Hub App

 

Hello,

I am currently in the process of transitioning my application deployment from GitHub Actions to Cloud Build and have encountered some difficulties replicating the exact behavior.

My deployment process involves the following steps:
1. Pulling the latest version of the code from GitHub.
2. Deploying the code to a specific directory on one of my Ubuntu servers.
3. Executing a series of commands on the server.

I am having trouble creating the `cloudbuild.yaml` file to achieve this behavior. Could anyone provide guidance or examples on how to structure the steps to achieve this? Any help would be greatly appreciated.

1 1 196
1 REPLY 1

Hello @LeoDevBatler  ,Welcome on Google Cloud Community.

I did some code and I think, that it will be good start for you to upgrade if needed. I had some issues due to Organization restriction, but basically should work with small changes.

steps:
#Initialize tepository
- name: 'gcr.io/cloud-builders/git'
  args: ['clone', 'https://DEVELOPER_TOKEN@github.com/REPO.git']

#Copy repo content to bucket. "-m" is for multithread for performance issues
- name: 'gcr.io/cloud-builders/gsutil'
  args: ['-m', 'cp', '-r', '.', 'gs://BUCKET/deployment']

#Connect to VM, use gsutil to download bucket content to specifc folder and execute "touch" command
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    echo Connecting to VM and deploying...
    gcloud compute ssh VM_NAME \
      --tunnel-through-iap \ #I'm using IAP because of interal restrictions
      --zone=us-central1-a \
      --command='mkdir -p /monorepo && gsutil cp -r gs://BUCKET/deployment/* /monorepo && cd /monorepo && touch test1.txt'

  --
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost