YY_H
YY_H

Reputation: 41

Import a config file in Google Cloud Build yaml config to assign values

Before, I have a makefile which contains commands for docker build and docker run. I also have a config file which is imported by the makefile, and it has some variable values. Then, I use build-arg flag to assign values to variables which are used in the dockerfile and my code.

Now I want to switch to Google Cloud Build and use the yaml config. I know the structure of the yaml config file and I still can use the build-arg flag. However, can i still import my config file and assign variable values as I did before?

Upvotes: 1

Views: 741

Answers (1)

guillaume blaquiere
guillaume blaquiere

Reputation: 75810

You shared few information on your current process,but I will try to provide you some tips

First, you can import your file. I don't know where it is, but if it is on Google CLoud Storage, your can do this

step:
  - name: gcr.io/cloud-builders/gcloud:latest
    entrypoint: "gsutil"
    args: ["cp","gs://yourbuket/config.file", "/workspace/config.file"]

Then, and it's the boring thing of Cloud Build, you can't define global environment variable inside the code (I mean dynamically) and for all the steps. You have to do it step by step, for example like this

step:
  ....
  - name: gcr.io/cloud-builders/gcloud:latest
    entrypoint: "bash"
    args:
      - "-c"
      - |
        # Add it in the environment
        export MY_VAR=$(grep MY_VAR /workspace/config.file | cut -d'=' -f2)

Here I supposed that the config file format is key=value

If you need to add it in Docker Build, you can do the same thing with the -e param. For your code, I don't know how you passe it.

Upvotes: 2

Related Questions