Skip to content

Commit

Permalink
Use new helper to compile KV string (#496)
Browse files Browse the repository at this point in the history
This requires changing the test inputs to expect JSON instead of K=V
pairs in our e2e runner.

- Fixes #495 
- Fixes #492
  • Loading branch information
sethvargo committed Mar 28, 2024
1 parent 4d52883 commit 68504f3
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 268 deletions.
104 changes: 85 additions & 19 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
service: '${{ env.SERVICE_NAME }}'
env_vars: |-
FOO=bar
ZIP=zap
ZIP=zap\,with|separators\,and&stuff
env_vars_file: './tests/fixtures/env_vars.txt'
secrets: |-
MY_SECRET=${{ vars.SECRET_NAME }}:latest
Expand All @@ -73,14 +73,33 @@ jobs:
skip_default_labels: true
flags: '--cpu=2 --concurrency=20'

- run: 'npm run e2e-tests'
- name: 'Run initial deploy tests'
run: 'npm run e2e-tests'
env:
PROJECT_ID: ${{ vars.PROJECT_ID }}
SERVICE: '${{ env.SERVICE_NAME }}'
ENV: 'FOO=bar,ZIP=zap,TEXT_FOO=bar,TEXT_ZIP=zap'
SECRET_ENV: MY_SECRET=${{ vars.SECRET_NAME }}:latest,MY_SECOND_SECRET=${{ vars.SECRET_NAME }}:1
PARAMS: '{"cpu":2, "containerConcurrency":20}'
LABELS: '{"label1":"value1", "label2":"value2"}'
ENV: |-
{
"FOO": "bar",
"ZIP": "zap,with|separators,and&stuff",
"TEXT_FOO": "bar",
"TEXT_ZIP": "zap,with|separators,and&stuff"
}
SECRET_ENV: |-
{
"MY_SECRET": "${{ vars.SECRET_NAME }}:latest",
"MY_SECOND_SECRET": "${{ vars.SECRET_NAME }}:1"
}
PARAMS: |-
{
"cpu": "2",
"containerConcurrency": "20"
}
LABELS: |-
{
"label1": "value1",
"label2": "value2"
}
- id: 'deploy-cloudrun-again'
name: 'Deploy again'
Expand All @@ -94,15 +113,41 @@ jobs:
DEF=456
secrets: /api/secrets/my-secret=${{ vars.SECRET_NAME }}:latest

- run: 'npm run e2e-tests'
- name: 'Run re-deploy tests'
run: 'npm run e2e-tests'
env:
PROJECT_ID: ${{ vars.PROJECT_ID }}
SERVICE: '${{ env.SERVICE_NAME }}'
ENV: 'FOO=bar,ZIP=zap,TEXT_FOO=bar,TEXT_ZIP=zap,ABC=123,DEF=456'
SECRET_ENV: MY_SECRET=${{ vars.SECRET_NAME }}:latest,MY_SECOND_SECRET=${{ vars.SECRET_NAME }}:1
SECRET_VOLUMES: /api/secrets/my-secret=${{ vars.SECRET_NAME }}:latest
PARAMS: '{"cpu":2, "containerConcurrency":20}'
LABELS: '{"label1":"value1", "label2":"value2", "commit-sha":"${{ github.sha }}", "managed-by":"github-actions"}'
ENV: |-
{
"FOO": "bar",
"ZIP": "zap,with|separators,and&stuff",
"TEXT_FOO": "bar",
"TEXT_ZIP": "zap,with|separators,and&stuff",
"ABC": "123",
"DEF": "456"
}
SECRET_ENV: |-
{
"MY_SECRET": "${{ vars.SECRET_NAME }}:latest",
"MY_SECOND_SECRET": "${{ vars.SECRET_NAME }}:1"
}
SECRET_VOLUMES: |-
{
"/api/secrets/my-secret": "${{ vars.SECRET_NAME }}:latest"
}
PARAMS: |-
{
"cpu": "2",
"containerConcurrency": "20"
}
LABELS: |-
{
"label1": "value1",
"label2": "value2",
"commit-sha": "${{ github.sha }}",
"managed-by": "github-actions"
}
REVISION_COUNT: 2

metadata:
Expand Down Expand Up @@ -137,13 +182,25 @@ jobs:
with:
metadata: './tests/unit/service.yaml'

- run: 'npm run e2e-tests'
- name: 'Run initial deploy tests'
run: 'npm run e2e-tests'
env:
PROJECT_ID: '${{ vars.PROJECT_ID }}'
SERVICE: '${{ env.SERVICE_NAME }}'
PARAMS: '{"cpu":2, "memory":"1Gi", "containerConcurrency":20}'
ANNOTATIONS: '{"run.googleapis.com/cloudsql-instances":"test-project:us-central1:my-test-instance"}'
LABELS: '{"test_label":"test_value"}'
PARAMS: |-
{
"cpu": "2",
"memory": "1Gi",
"containerConcurrency": "20"
}
ANNOTATIONS: |-
{
"run.googleapis.com/cloudsql-instances": "test-project:us-central1:my-test-instance"
}
LABELS: |-
{
"test_label": "test_value"
}
- id: 'deploy-cloudrun-again'
name: 'Deploy again'
Expand All @@ -152,10 +209,19 @@ jobs:
image: 'gcr.io/cloudrun/hello'
service: '${{ env.SERVICE_NAME }}'

- run: 'npm run e2e-tests' # Check that config isn't overwritten
- name: 'Run re-deploy tests'
run: 'npm run e2e-tests' # Check that config isn't overwritten
env:
PROJECT_ID: '${{ vars.PROJECT_ID }}'
SERVICE: '${{ env.SERVICE_NAME }}'
PARAMS: '{"cpu":2, "memory":"1Gi", "containerConcurrency":20}'
ANNOTATIONS: '{"run.googleapis.com/cloudsql-instances":"test-project:us-central1:my-test-instance"}'
PARAMS: |-
{
"cpu": "2",
"memory": "1Gi",
"containerConcurrency": "20"
}
ANNOTATIONS: |-
{
"run.googleapis.com/cloudsql-instances": "test-project:us-central1:my-test-instance"
}
REVISION_COUNT: 2
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ jobs:
ZIP=zap
```

Entries are separated by commas (`,`) and newline characters. Keys and
values are separated by `=`. To use `,`, `=`, or newline characters, escape
them with a backslash:

```yaml
with:
env_vars: |
EMAILS=foo@bar.com\,zip@zap.com
```

- `env_vars_file`: (Optional) Path to a file on disk, relative to the
workspace, that defines environment variables. The file can be
newline-separated KEY=VALUE pairs, JSON, or YAML format. If both `env_vars`
Expand Down Expand Up @@ -124,6 +134,9 @@ jobs:
ZIP: 'zap'
```

When specified as KEY=VALUE pairs, the same escaping rules apply as
described in `env_vars`. You do not have to escape YAML or JSON.

- `secrets`: (Optional) List of key=value pairs to use as secrets. These can
either be injected as environment variables or mounted as volumes. All
existing environment secrets and volume mounts will be retained.
Expand All @@ -138,6 +151,9 @@ jobs:
/secrets/api/key=secret-key-2:latest
```

The same rules apply for escaping entries as from `env_vars`, but Cloud Run
is more restrictive with allowed keys and names for secrets.

- `labels`: (Optional) List of key=value pairs to set as labels on the Cloud
Run service. Existing labels will be overwritten.

Expand All @@ -147,7 +163,8 @@ jobs:
my-label=my-value
```

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

Expand Down
6 changes: 3 additions & 3 deletions dist/main/index.js

Large diffs are not rendered by default.

Loading

0 comments on commit 68504f3

Please sign in to comment.