Skip to content

Commit ee5bf41

Browse files
authored
feat: add example workflow (#14)
* feat: add example workflow * docs: Add roles link
1 parent f22fce7 commit ee5bf41

File tree

8 files changed

+546
-4
lines changed

8 files changed

+546
-4
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2020 Google, LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
on:
16+
push:
17+
branches:
18+
- example
19+
20+
name: Deploy to Google App Engine
21+
22+
jobs:
23+
deploy:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v2
28+
29+
- name: Deploy to App Engine
30+
id: deploy
31+
uses: google-github-actions/[email protected]
32+
with:
33+
deliverables: example-app/app.yaml
34+
project_id: ${{ secrets.GCP_PROJECT }}
35+
credentials: ${{ secrets.GCP_SA_KEY }}
36+
37+
- name: Show Output
38+
run: echo ${{ steps.deploy.outputs.url }}

README.md

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,12 @@ for more information.
7777
There are a few ways to authenticate this action. The caller must have
7878
permissions to access the secrets being requested.
7979

80-
Roles needed:
80+
[Roles needed](https://cloud.google.com/appengine/docs/standard/python/roles#predefined_roles):
8181

82+
- App Engine Admin (`roles/appengine.appAdmin`): can manage all App Engine resources
83+
- Service Account User (`roles/iam.serviceAccountUser`): to deploy as the service account
8284
- Storage Admin (`roles/compute.storageAdmin`): to upload files
8385
- Cloud Build Editor (`cloudbuild.builds.editor`): to build the application
84-
- App Engine roles:
85-
- Deployer (`roles/appengine.deployer`): Can deploy but can not promote
86-
- Admin (`roles/appengine.appAdmin`): Can manage all App Engine resources (not recommended)
8786

8887
*Note:* An owner will be needed to create the App Engine application
8988

@@ -133,6 +132,75 @@ only works using a custom runner hosted on GCP.**
133132
The action will automatically detect and use the Application Default
134133
Credentials.
135134

135+
## Example Workflows
136+
137+
* [Deploy from source](#deploy-from-source)
138+
139+
### Setup
140+
141+
1. Clone this repo.
142+
143+
1. Create a new Google Cloud Project (or select an existing project).
144+
145+
1. [Initialize your App Engine app with your project](https://cloud.google.com/appengine/docs/standard/nodejs/console#console).
146+
147+
1. [Create a Google Cloud service account][sa] or select an existing one.
148+
149+
1. Add the the following [Cloud IAM roles][roles] to your service account:
150+
151+
- `App Engine Admin` - allows for the creation of new App Engine apps
152+
153+
- `Service Account User` - required to deploy to App Engine as service account
154+
155+
- `Storage Admin` - allows upload of source code
156+
157+
- `Cloud Build Editor` - allows building of source code
158+
159+
1. [Download a JSON service account key][create-key] for the service account.
160+
161+
1. Add the following [secrets to your repository's secrets][gh-secret]:
162+
163+
- `GCP_PROJECT`: Google Cloud project ID
164+
165+
- `GCP_SA_KEY`: the downloaded service account key
166+
167+
### Deploy from source
168+
169+
To run this workflow, push to the branch named `example`:
170+
171+
```sh
172+
git push YOUR-FORK main:example
173+
```
174+
175+
## Migrating from `setup-gcloud`
176+
177+
Example using `setup-gcloud`:
178+
179+
```YAML
180+
- name: Setup Cloud SDK
181+
uses: google-github-actions/[email protected]
182+
with:
183+
project_id: ${{ env.PROJECT_ID }}
184+
service_account_key: ${{ secrets.GCP_SA_KEY }}
185+
186+
- name: Deploy to App Engine
187+
run: gcloud app deploy app.yaml --quiet --no-promote --version v1
188+
189+
```
190+
191+
Migrated to `deploy-appengine`:
192+
193+
```YAML
194+
- name: Deploy to App Engine
195+
uses: google-github-actions/[email protected]
196+
with:
197+
deliverables: app.yaml
198+
project_id: ${{ secrets.GCP_PROJECT }}
199+
credentials: ${{ secrets.GCP_SA_KEY }}
200+
promote: false
201+
version: v1
202+
```
203+
136204
[gae]: https://cloud.google.com/appengine
137205
[sm]: https://cloud.google.com/secret-manager
138206
[sa]: https://cloud.google.com/iam/docs/creating-managing-service-accounts

action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
1415
name: Deploy to Google App Engine
1516
author: Google LLC
1617
description: |-

example-app/.gcloudignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.github
2+
node_modules
3+
dist
4+
README.md

example-app/app.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2020 Google, LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
runtime: nodejs12

example-app/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2020 Google, LLC.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
const express = require('express');
16+
const app = express();
17+
18+
app.get('/', (req, res) => {
19+
console.log('Hello world received a request.');
20+
21+
const target = process.env.TARGET || 'World';
22+
res.send(`Hello ${target}!`);
23+
});
24+
25+
const port = process.env.PORT || 8080;
26+
app.listen(port, () => {
27+
console.log('Hello world listening on port', port);
28+
});

0 commit comments

Comments
 (0)