Skip to content

Commit 99f25f1

Browse files
authored
fix: point users to specific example workflow (#254)
* fix: point users to Cloud Run example workflow * fix: remove app engine example app and update instructions
1 parent 95e2d15 commit 99f25f1

File tree

16 files changed

+104
-1122
lines changed

16 files changed

+104
-1122
lines changed

example-workflows/cloud-run/.dockerignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

example-workflows/cloud-run/.github/workflows/cloud-run.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

example-workflows/cloud-run/Dockerfile

Lines changed: 0 additions & 34 deletions
This file was deleted.

example-workflows/cloud-run/README.md

Lines changed: 19 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
# Cloud Run - GitHub Actions
1+
# Cloud Run Workflow
22

3-
An example workflow that uses [GitHub Actions][actions] to deploy a
4-
[Hello World Node.js app](index.js) to [Cloud Run][cloud-run].
3+
An example workflow that uses the `setup-gcloud` action to deploy to [Cloud Run][cloud-run].
4+
5+
_**Checkout the [`deploy-cloudrun` action](https://github.com/google-github-actions/deploy-cloudrun) and [example workflows](https://github.com/google-github-actions/deploy-cloudrun/README.md#example-workflows)
6+
for a specialized implementation.**_
57

68
This code is intended to be an _example_. You will likely need to change or
79
update values to match your setup.
810

911
## Workflow description
1012

11-
For pushes to the `master` branch, this workflow will:
13+
For pushes to the `example` branch, this workflow will:
1214

1315
1. Download and configure the Google [Cloud SDK][sdk] with the provided
1416
credentials.
1517

18+
1. Authenticates Docker to push to Google Container Registry
19+
1620
1. Build, tag, and push a container image to Google Container Registry.
1721

18-
- The image is built using Cloud Build and pushed to Google Container Registry.
22+
- The image is built using Docker and pushed to Google Container Registry.
1923

2024
- The image is available through the following tags: `latest` and first 8 of
2125
the commit SHA.
@@ -24,72 +28,27 @@ For pushes to the `master` branch, this workflow will:
2428

2529
## Setup
2630

27-
1. Create a new Google Cloud Project (or select an existing project) and
28-
[enable the Cloud Run and Cloud Build APIs](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com,run.googleapis.com).
29-
30-
1. Create or reuse a GitHub repository for the example workflow:
31-
32-
1. [Create a repository](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-new-repository).
33-
34-
1. Move into the repository directory:
31+
1. Create a new Google Cloud Project (or select an existing project).
3532

36-
```
37-
$ cd <repo>
38-
```
33+
1. [Enable the Cloud Run API](https://console.cloud.google.com/flows/enableapi?apiid=run.googleapis.com).
3934

40-
1. Copy the example into the repository:
41-
42-
```
43-
$ cp -r <path_to>/github-actions/example-workflows/cloud-run/ .
44-
```
45-
46-
1. [Create a Google Cloud service account][create-sa] if one does not already
47-
exist.
35+
1. [Create a Google Cloud service account][sa] or select an existing one.
4836

4937
1. Add the the following [Cloud IAM roles][roles] to your service account:
5038

51-
- `Cloud Run Admin` - allows for the creation of new services
52-
53-
- `Cloud Build Editor` - allows for deploying cloud builds
54-
55-
- `Cloud Build Service Account` - allows for deploying cloud builds
56-
57-
- `Viewer` - allows for viewing the project
58-
59-
- `Service Account User` - required to deploy services to Cloud Run
60-
61-
Note: These permissions are overly broad to favor a quick start. They do not
62-
represent best practices around the Principle of Least Privilege. To
63-
properly restrict access, you should create a custom IAM role with the most
64-
restrictive permissions.
65-
66-
67-
1. [Create a JSON service account key][create-key] for the service account.
68-
69-
1. Add the following secrets to your repository's secrets:
70-
71-
- `RUN_PROJECT`: Google Cloud project ID
72-
73-
- `RUN_SA_KEY`: the content of the service account JSON file
39+
- `Cloud Run Admin` - allows for the creation of new Cloud Run services
7440

75-
## Run the workflow
41+
- `Service Account User` - required to deploy to Cloud Run as service account
7642

77-
1. Add and commit your changes:
43+
- `Storage Admin` - allow push to Google Container Registry
7844

79-
```text
80-
$ git add .
81-
$ git commit -m "Set up GitHub workflow"
82-
```
45+
1. [Download a JSON service account key][create-key] for the service account.
8346

84-
1. Push to the `master` branch:
47+
1. Add the following [secrets to your repository's secrets][gh-secret]:
8548

86-
```text
87-
$ git push -u origin master
88-
```
49+
- `GCP_PROJECT`: Google Cloud project ID
8950

90-
1. View the GitHub Actions Workflow by selecting the `Actions` tab at the top
91-
of your repository on GitHub. Then click on the `Build and Deploy to Cloud
92-
Run` element to see the details.
51+
- `GCP_SA_KEY`: the downloaded service account key
9352

9453
[actions]: https://help.github.com/en/categories/automating-your-workflow-with-github-actions
9554
[cloud-run]: https://cloud.google.com/run/
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2019 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: Build and Deploy to Cloud Run
21+
env:
22+
PROJECT_ID: ${{ secrets.GCP_PROJECT }}
23+
SERVICE: YOUR_SERVICE_NAME
24+
REGION: YOUR_SERVICE_REGION
25+
26+
jobs:
27+
deploy:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v2
32+
33+
- name: Setup Cloud SDK
34+
uses: google-github-actions/[email protected]
35+
with:
36+
project_id: ${{ env.PROJECT_ID }}
37+
service_account_key: ${{ secrets.GCP_SA_KEY }}
38+
39+
- name: Authorize Docker push
40+
run: gcloud auth configure-docker
41+
42+
- name: Build and Push Container
43+
run: |-
44+
docker build -t gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }} .
45+
docker push gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}
46+
47+
- name: Deploy to Cloud Run
48+
run: |-
49+
gcloud run deploy ${{ env.SERVICE }} \
50+
--region ${{ env.REGION }} \
51+
--image gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }} \
52+
--platform "managed" \
53+
--quiet

example-workflows/cloud-run/index.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)