Using Makefile to export vars from yaml file

154 views Asked by At

Like the title says, I have a yaml file with k:v format, and I'm using yq to parse the yaml and produce env variables in k1=v1, k2=v2 format. This works great in my shell:

$ export $(yq 'to_entries | map(.key + "=" + .value) | join(" ")' app/kube/values.yaml)
$ export
appImageTag=app
appNodePort=30003
appPort=3000
dbImageTag=db
dbName=sage
dbPort=3001
dockerRegistry=trumanpurnell
dockerRepo=sage

BUT! I want to do it at the top of my Makefile. I'm so close, I have:

Makefile
export $(shell yq 'to_entries | map(.key + "=" + .value) | join(" ")' app/kube/values.yaml)

backenv:
    export

Which gets me:

appImageTag="app="
appNodePort="30003="
appPort="3000="
dbImageTag="db="
dbName="sage="
dbPort="3001="
dockerRegistry="trumanpurnell="
dockerRepo="sage="

Ugh, trailing =. How to get rid of it? Bonus points for explaining what the difference is?

1

There are 1 answers

0
Truman Purnell On
$(foreach var,$(shell yq -o=shell app/kube/values.yaml),$(eval export $(var)))

Yields

appImageTag=app
appNodePort=30003
appPort=3000
dbImageTag=db
dbName=sage
dbPort=3001
dockerRegistry=trumanpurnell
dockerRepo=sage