runenv
runenv
create gcloud run deploy --set-env-vars=
option and export shell environment from yaml file.
Motivation
I want to manage Cloud Run environment variables in a yaml file. But there is no way to pass the file to gcloud run deploy. Also, in gcloud services replace, it can manage environment variables in a yaml file, but it has to manage other values as well. In particular, we need to specify the revision, which is difficult to use.
Install
go install github.com/sonatard/runenv@latest
Usage
# env.yaml
- name: SERVER_KEY1
value: value1
- name: SERVER_KEY2
value: value2
$ runenv env.yaml
SERVER_KEY1=value1,SERVER_KEY2=value2
$ runenv -e env.yaml
export SERVER_KEY1="value1"
export SERVER_KEY2="value2"
Example
gcloud run deploy --set-env-vars
- Prepare revision config
gcloud run services describe [SERVICE] --format=export > service.yaml
- Create env.yaml from service.yaml
brew install yq
yq ".spec.template.spec.containers[].env" service.yaml > env.yaml
# or you can create env.yaml manualy.
# env.yaml
- name: SERVER_KEY1
value: value1
- name: SERVER_KEY2
value: value2
- Cloud run deploy with environment variables
gcloud run deploy [SERVICE] --image=[IMAGE] --set-env-vars="$(runenv env.yaml)"
Export shell environment
- Create env.yaml
# env.yaml
- name: SERVER_KEY1
value: value1
- name: SERVER_KEY2
value: value2
- Export shell environment
$ eval "$(runenv -e env.yaml)"
$ echo $SERVER_KEY1
value1