Reputation: 80
I am kinda having this weird not meant to use for case with GCP. So there is a few things I need to do with Google Cloud Platform. We use an much stronger than at the office Ubuntu VM to build a yocto build. I can somehow not figure out what the proper .yaml is to turn on a VM in google cloud. The pipeline should run from bitbucket and is supposed to the following things
(pseudo code)
start up the vm in gcp && ssh builder@server
cd ./repo/build
start build && push build image to repo server
push logs to pipeline
shutdown
I am aware of google cloud build but we have some dependencies that would likely make this more or less inefficient, now I have a general idea how my yaml is suppose to look like but I could use some better pointers in this. As in I am sure this is wrong.
steps:
- name: 'gcloud compute instances start build-server-turnoff-when-unused'
- name: buildstep
script: /bin/bash build.sh
- name: 'send logs'
script: /bin/bash sendlogs.sh
- name: gcloud compute instances stop build-server-turnoff-when-unused'
I was wondering if someone has done something like this before and could help me out?
Upvotes: 0
Views: 542
Reputation: 80
I had a bit of a wrong understanding how pipelines in bitbucket exactly work, I figured out I could just download the google-cloud sdk and give commands through the pipeline.
image: google/cloud-sdk:latest
pipelines:
default:
- step:
name: "Start build instance"
script:
- echo ${GCLOUD_JSON_KEY} > client-secret.json
- gcloud auth activate-service-account --key-file client-secret.json
- gcloud config set project $project-name
- 'gcloud compute instances start build-serve --zone=america-west4-b'
Upvotes: 0
Reputation: 4126
Assuming that your directory looks like this:
.
./cloudbuild.yaml
./repo
./repo/build
./repo/build/build.sh
./repo/build/sendLogs.sh
Your yaml file should look like this:
steps:
#0 Start Instance
- name: 'gcr.io/cloud-builders/gcloud'
args: ['compute', 'instances', 'start', 'INSTANCE', '--zone', 'ZONE']
#1 Build Step
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
dir: 'repo/build'
args: ['./build.sh']
#2 Send Logs
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
dir: 'repo/build'
args: ['./sendLogs.sh']
#3 Stop Instance
- name: 'gcr.io/cloud-builders/gcloud'
args: ['compute', 'instances', 'stop', INSTANCE, '--zone', 'ZONE']
In this case we used the dir
field in the build step to set a working directory to use when running the scripts. Also, make sure that your Cloud Build service account has a Compute Admin role on IAM so you can start and stop your Compute Engine instance on your build steps.
Service account name:
[email protected]
Upvotes: 1