Skip to content

Commit 09c010d

Browse files
authored
feat: Add source deploys and traffic updates (#45)
* Add source deploy, tags, and revision naming * update tests * debug 2 * Remove debugging comments * update tests * fix sinon tests * respond to comments
1 parent ef1f7e5 commit 09c010d

File tree

10 files changed

+533
-75
lines changed

10 files changed

+533
-75
lines changed
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
name: deploy-cloudrun Traffic Integration
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
pull_request:
8+
9+
jobs:
10+
source:
11+
name: with Source
12+
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
13+
runs-on: ubuntu-latest
14+
steps:
15+
- id: service
16+
run: echo ::set-output name=service::run-source-$GITHUB_SHA
17+
- uses: actions/checkout@v2
18+
- uses: actions/setup-node@master
19+
with:
20+
node-version: 12.x
21+
- name: Build Javascript
22+
run: |-
23+
npm install
24+
npm run build
25+
26+
- name: Deploys from source
27+
id: deploy_1
28+
uses: ./
29+
with:
30+
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
31+
service: ${{ steps.service.outputs.service }}
32+
source: example-app
33+
34+
- name: Setup Authentication with gcloud
35+
uses: google-github-actions/setup-gcloud@master
36+
with:
37+
service_account_key: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_B64 }}
38+
export_default_credentials: true
39+
40+
- name: Integration Tests
41+
run: npm run e2e-tests
42+
env:
43+
URL: ${{ steps.deploy_1.outputs.url }}
44+
SERVICE: ${{ steps.service.outputs.service }}
45+
46+
- name: Update Service with env vars
47+
id: deploy_2
48+
uses: ./
49+
with:
50+
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
51+
service: ${{ steps.service.outputs.service }}
52+
source: example-app
53+
env_vars: TEST_ENV=TEST_VAR
54+
flags: "--cpu=2 --memory=1Gi --concurrency=20"
55+
56+
- name: Integration Tests # Check that config isn't overwritten
57+
run: npm run e2e-tests
58+
env:
59+
URL: ${{ steps.deploy_2.outputs.url }}
60+
SERVICE: ${{ steps.service.outputs.service }}
61+
ENV: TEST_ENV=TEST_VAR
62+
PARAMS: "{\"cpu\": 2,\"memory\": \"1Gi\", \"containerConcurrency\": 20}"
63+
COUNT: 2
64+
65+
suffix:
66+
name: with Suffix
67+
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
68+
runs-on: ubuntu-latest
69+
steps:
70+
- id: service
71+
run: echo ::set-output name=service::run-suffix-$GITHUB_SHA
72+
- uses: actions/checkout@v2
73+
- uses: actions/setup-node@master
74+
with:
75+
node-version: 12.x
76+
- name: Build Javascript
77+
run: |-
78+
npm install
79+
npm run build
80+
- name: Deploys with suffix
81+
id: deploy_1
82+
uses: ./
83+
with:
84+
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
85+
service: ${{ steps.service.outputs.service }}
86+
image: gcr.io/cloudrun/hello
87+
suffix: "002"
88+
89+
- name: Setup Authentication with gcloud
90+
uses: google-github-actions/setup-gcloud@master
91+
with:
92+
service_account_key: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_B64 }}
93+
export_default_credentials: true
94+
95+
- name: Integration Tests
96+
run: npm run e2e-tests
97+
env:
98+
URL: ${{ steps.deploy_1.outputs.url }}
99+
SERVICE: ${{ steps.service.outputs.service }}
100+
REVISION: ${{ steps.service.outputs.service }}-002
101+
102+
tag:
103+
name: with Tag
104+
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
105+
runs-on: ubuntu-latest
106+
steps:
107+
- id: service
108+
run: echo ::set-output name=service::run-tag-$(echo $GITHUB_SHA | cut -c1-6)
109+
- uses: actions/checkout@v2
110+
- uses: actions/setup-node@master
111+
with:
112+
node-version: 12.x
113+
114+
- name: Build Javascript
115+
run: |-
116+
npm install
117+
npm run build
118+
119+
- name: Deploys with tag
120+
id: deploy_1
121+
uses: ./
122+
with:
123+
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
124+
service: ${{ steps.service.outputs.service }}
125+
image: gcr.io/cloudrun/hello
126+
tag: test-tag
127+
128+
- name: Setup Authentication with gcloud
129+
uses: google-github-actions/setup-gcloud@master
130+
with:
131+
service_account_key: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_B64 }}
132+
export_default_credentials: true
133+
134+
- name: Integration Tests
135+
run: npm run e2e-tests
136+
env:
137+
URL: ${{ steps.deploy_1.outputs.url }}
138+
SERVICE: ${{ steps.service.outputs.service }}
139+
TAG: test-tag
140+
141+
- name: Deploys new revision
142+
id: deploy_2
143+
uses: ./
144+
with:
145+
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
146+
service: ${{ steps.service.outputs.service }}
147+
image: gcr.io/cloudrun/hello:latest
148+
suffix: "v2"
149+
150+
- name: Updates traffic
151+
id: traffic_1
152+
uses: ./
153+
with:
154+
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
155+
service: ${{ steps.service.outputs.service }}
156+
tag_traffic: "test-tag=100"
157+
158+
- name: Integration Tests
159+
run: npm run e2e-tests
160+
env:
161+
URL: ${{ steps.traffic_1.outputs.url }}
162+
SERVICE: ${{ steps.service.outputs.service }}
163+
TAG: test-tag
164+
TRAFFIC: 100
165+
166+
- name: Updates traffic
167+
id: traffic_2
168+
uses: ./
169+
with:
170+
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
171+
service: ${{ steps.service.outputs.service }}
172+
revision_traffic: "${{ steps.service.outputs.service }}-v2=20"
173+
174+
- name: Integration Tests
175+
run: npm run e2e-tests
176+
env:
177+
URL: ${{ steps.traffic_2.outputs.url }}
178+
SERVICE: ${{ steps.service.outputs.service }}
179+
TAG: test-tag
180+
TRAFFIC: 80
181+
182+
- name: Deploys new revision
183+
id: deploy_3
184+
uses: ./
185+
with:
186+
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
187+
service: ${{ steps.service.outputs.service }}
188+
image: gcr.io/cloudrun/hello
189+
tag: no-traffic
190+
no_traffic: true
191+
192+
- name: Integration Tests
193+
run: npm run e2e-tests
194+
env:
195+
URL: ${{ steps.deploy_3.outputs.url }}
196+
SERVICE: ${{ steps.service.outputs.service }}
197+
TAG: test-tag
198+
TRAFFIC: 80
199+
200+
cleanup:
201+
name: Clean Up
202+
if: ${{ always() }}
203+
runs-on: ubuntu-latest
204+
needs: [source, suffix, tag]
205+
steps:
206+
- uses: google-github-actions/setup-gcloud@master
207+
with:
208+
service_account_key: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_B64 }}
209+
project_id: ${{ secrets.DEPLOY_CLOUDRUN_PROJECT_ID }}
210+
211+
- name: Delete services
212+
run: |-
213+
gcloud config set run/platform managed
214+
gcloud config set run/region us-central1
215+
gcloud run services delete run-source-$GITHUB_SHA --quiet
216+
gcloud run services delete run-suffix-$GITHUB_SHA --quiet
217+
gcloud run services delete run-tag-$(echo $GITHUB_SHA | cut -c1-6) --quiet

.github/workflows/deploy-cloudrun.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ jobs:
2222
- name: npm lint
2323
run: npm run lint
2424

25-
- uses: google-github-actions/setup-gcloud@master
26-
with:
27-
service_account_key: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_B64 }}
28-
2925
- name: npm test
3026
run: npm run test
31-
env:
32-
TEST_DEPLOY_CLOUDRUN_CREDENTIALS: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_B64 }}
33-
TEST_DEPLOY_CLOUDRUN_PROJECT: ${{ secrets.DEPLOY_CLOUDRUN_PROJECT_ID }}
27+

0 commit comments

Comments
 (0)