Skip to content

Commit 68504f3

Browse files
authored
Use new helper to compile KV string (#496)
This requires changing the test inputs to expect JSON instead of K=V pairs in our e2e runner. - Fixes #495 - Fixes #492
1 parent 4d52883 commit 68504f3

File tree

9 files changed

+360
-268
lines changed

9 files changed

+360
-268
lines changed

.github/workflows/integration.yml

Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
service: '${{ env.SERVICE_NAME }}'
6363
env_vars: |-
6464
FOO=bar
65-
ZIP=zap
65+
ZIP=zap\,with|separators\,and&stuff
6666
env_vars_file: './tests/fixtures/env_vars.txt'
6767
secrets: |-
6868
MY_SECRET=${{ vars.SECRET_NAME }}:latest
@@ -73,14 +73,33 @@ jobs:
7373
skip_default_labels: true
7474
flags: '--cpu=2 --concurrency=20'
7575

76-
- run: 'npm run e2e-tests'
76+
- name: 'Run initial deploy tests'
77+
run: 'npm run e2e-tests'
7778
env:
7879
PROJECT_ID: ${{ vars.PROJECT_ID }}
7980
SERVICE: '${{ env.SERVICE_NAME }}'
80-
ENV: 'FOO=bar,ZIP=zap,TEXT_FOO=bar,TEXT_ZIP=zap'
81-
SECRET_ENV: MY_SECRET=${{ vars.SECRET_NAME }}:latest,MY_SECOND_SECRET=${{ vars.SECRET_NAME }}:1
82-
PARAMS: '{"cpu":2, "containerConcurrency":20}'
83-
LABELS: '{"label1":"value1", "label2":"value2"}'
81+
ENV: |-
82+
{
83+
"FOO": "bar",
84+
"ZIP": "zap,with|separators,and&stuff",
85+
"TEXT_FOO": "bar",
86+
"TEXT_ZIP": "zap,with|separators,and&stuff"
87+
}
88+
SECRET_ENV: |-
89+
{
90+
"MY_SECRET": "${{ vars.SECRET_NAME }}:latest",
91+
"MY_SECOND_SECRET": "${{ vars.SECRET_NAME }}:1"
92+
}
93+
PARAMS: |-
94+
{
95+
"cpu": "2",
96+
"containerConcurrency": "20"
97+
}
98+
LABELS: |-
99+
{
100+
"label1": "value1",
101+
"label2": "value2"
102+
}
84103
85104
- id: 'deploy-cloudrun-again'
86105
name: 'Deploy again'
@@ -94,15 +113,41 @@ jobs:
94113
DEF=456
95114
secrets: /api/secrets/my-secret=${{ vars.SECRET_NAME }}:latest
96115

97-
- run: 'npm run e2e-tests'
116+
- name: 'Run re-deploy tests'
117+
run: 'npm run e2e-tests'
98118
env:
99119
PROJECT_ID: ${{ vars.PROJECT_ID }}
100120
SERVICE: '${{ env.SERVICE_NAME }}'
101-
ENV: 'FOO=bar,ZIP=zap,TEXT_FOO=bar,TEXT_ZIP=zap,ABC=123,DEF=456'
102-
SECRET_ENV: MY_SECRET=${{ vars.SECRET_NAME }}:latest,MY_SECOND_SECRET=${{ vars.SECRET_NAME }}:1
103-
SECRET_VOLUMES: /api/secrets/my-secret=${{ vars.SECRET_NAME }}:latest
104-
PARAMS: '{"cpu":2, "containerConcurrency":20}'
105-
LABELS: '{"label1":"value1", "label2":"value2", "commit-sha":"${{ github.sha }}", "managed-by":"github-actions"}'
121+
ENV: |-
122+
{
123+
"FOO": "bar",
124+
"ZIP": "zap,with|separators,and&stuff",
125+
"TEXT_FOO": "bar",
126+
"TEXT_ZIP": "zap,with|separators,and&stuff",
127+
"ABC": "123",
128+
"DEF": "456"
129+
}
130+
SECRET_ENV: |-
131+
{
132+
"MY_SECRET": "${{ vars.SECRET_NAME }}:latest",
133+
"MY_SECOND_SECRET": "${{ vars.SECRET_NAME }}:1"
134+
}
135+
SECRET_VOLUMES: |-
136+
{
137+
"/api/secrets/my-secret": "${{ vars.SECRET_NAME }}:latest"
138+
}
139+
PARAMS: |-
140+
{
141+
"cpu": "2",
142+
"containerConcurrency": "20"
143+
}
144+
LABELS: |-
145+
{
146+
"label1": "value1",
147+
"label2": "value2",
148+
"commit-sha": "${{ github.sha }}",
149+
"managed-by": "github-actions"
150+
}
106151
REVISION_COUNT: 2
107152

108153
metadata:
@@ -137,13 +182,25 @@ jobs:
137182
with:
138183
metadata: './tests/unit/service.yaml'
139184

140-
- run: 'npm run e2e-tests'
185+
- name: 'Run initial deploy tests'
186+
run: 'npm run e2e-tests'
141187
env:
142188
PROJECT_ID: '${{ vars.PROJECT_ID }}'
143189
SERVICE: '${{ env.SERVICE_NAME }}'
144-
PARAMS: '{"cpu":2, "memory":"1Gi", "containerConcurrency":20}'
145-
ANNOTATIONS: '{"run.googleapis.com/cloudsql-instances":"test-project:us-central1:my-test-instance"}'
146-
LABELS: '{"test_label":"test_value"}'
190+
PARAMS: |-
191+
{
192+
"cpu": "2",
193+
"memory": "1Gi",
194+
"containerConcurrency": "20"
195+
}
196+
ANNOTATIONS: |-
197+
{
198+
"run.googleapis.com/cloudsql-instances": "test-project:us-central1:my-test-instance"
199+
}
200+
LABELS: |-
201+
{
202+
"test_label": "test_value"
203+
}
147204
148205
- id: 'deploy-cloudrun-again'
149206
name: 'Deploy again'
@@ -152,10 +209,19 @@ jobs:
152209
image: 'gcr.io/cloudrun/hello'
153210
service: '${{ env.SERVICE_NAME }}'
154211

155-
- run: 'npm run e2e-tests' # Check that config isn't overwritten
212+
- name: 'Run re-deploy tests'
213+
run: 'npm run e2e-tests' # Check that config isn't overwritten
156214
env:
157215
PROJECT_ID: '${{ vars.PROJECT_ID }}'
158216
SERVICE: '${{ env.SERVICE_NAME }}'
159-
PARAMS: '{"cpu":2, "memory":"1Gi", "containerConcurrency":20}'
160-
ANNOTATIONS: '{"run.googleapis.com/cloudsql-instances":"test-project:us-central1:my-test-instance"}'
217+
PARAMS: |-
218+
{
219+
"cpu": "2",
220+
"memory": "1Gi",
221+
"containerConcurrency": "20"
222+
}
223+
ANNOTATIONS: |-
224+
{
225+
"run.googleapis.com/cloudsql-instances": "test-project:us-central1:my-test-instance"
226+
}
161227
REVISION_COUNT: 2

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ jobs:
9797
ZIP=zap
9898
```
9999

100+
Entries are separated by commas (`,`) and newline characters. Keys and
101+
values are separated by `=`. To use `,`, `=`, or newline characters, escape
102+
them with a backslash:
103+
104+
```yaml
105+
with:
106+
env_vars: |
107+
EMAILS=foo@bar.com\,zip@zap.com
108+
```
109+
100110
- `env_vars_file`: (Optional) Path to a file on disk, relative to the
101111
workspace, that defines environment variables. The file can be
102112
newline-separated KEY=VALUE pairs, JSON, or YAML format. If both `env_vars`
@@ -124,6 +134,9 @@ jobs:
124134
ZIP: 'zap'
125135
```
126136

137+
When specified as KEY=VALUE pairs, the same escaping rules apply as
138+
described in `env_vars`. You do not have to escape YAML or JSON.
139+
127140
- `secrets`: (Optional) List of key=value pairs to use as secrets. These can
128141
either be injected as environment variables or mounted as volumes. All
129142
existing environment secrets and volume mounts will be retained.
@@ -138,6 +151,9 @@ jobs:
138151
/secrets/api/key=secret-key-2:latest
139152
```
140153

154+
The same rules apply for escaping entries as from `env_vars`, but Cloud Run
155+
is more restrictive with allowed keys and names for secrets.
156+
141157
- `labels`: (Optional) List of key=value pairs to set as labels on the Cloud
142158
Run service. Existing labels will be overwritten.
143159

@@ -147,7 +163,8 @@ jobs:
147163
my-label=my-value
148164
```
149165

150-
Labels have strict naming and casing requirements. See [Requirements for
166+
The same rules apply for escaping entries as from `env_vars`, but labels
167+
have strict naming and casing requirements. See [Requirements for
151168
labels](https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements)
152169
for more information.
153170

dist/main/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)