Reputation: 6002
I have a simple cloudbuild.yaml
file which runs a Bazel command. This command returns a Kubernetes configuration in form as a log output.
My goal is to take the output of the first step and apply it to my Kubernetes cluster.
steps:
- name: gcr.io/cloud-builders/bazel
args: ["run", "//:kubernetes"]
- name: "gcr.io/cloud-builders/kubectl"
args: ["apply", "<log output of previous step>"]
env:
- "CLOUDSDK_COMPUTE_ZONE=europe-west3-a"
- "CLOUDSDK_CONTAINER_CLUSTER=cents-ideas"
I've tried the following:
- name: gcr.io/cloud-builders/bazel
entrypoint: /bin/bash
args:
[
"bazel",
"run",
"//:kubernetes",
" > kubernetes.yaml",
]
- name: "gcr.io/cloud-builders/kubectl"
args: ["apply", "-f", "kubernetes.yaml"]
env:
- "CLOUDSDK_COMPUTE_ZONE=europe-west3-a"
- "CLOUDSDK_CONTAINER_CLUSTER=cents-ideas"
But then I get this error:
Running: kubectl apply -f kubernetes.yaml
error: the path "kubernetes.yaml" does not exist
Upvotes: 1
Views: 878
Reputation: 1168
As everyone already suggested here use volumes.
Tweak your cloudbuild.yaml
file like this:
- name: gcr.io/cloud-builders/bazel
entrypoint: /bin/bash
args:
[
"bazel",
"run",
"//:kubernetes",
" > /workspace/kubernetes.yaml",
]
- name: "gcr.io/cloud-builders/kubectl"
args: ["apply", "-f", "/workspace/kubernetes.yaml"]
env:
- "CLOUDSDK_COMPUTE_ZONE=europe-west3-a"
- "CLOUDSDK_CONTAINER_CLUSTER=cents-ideas"
Upvotes: 1
Reputation: 336
Here's how to mount the volume:
https://cloud.google.com/cloud-build/docs/build-config#volumes
Basically add:
volumes:
- name: 'vol1'
path: '/persistent_volume'
Then reference full path /persistent_volume/filename/
when writing / reading to your file.
Upvotes: 2