Fix license and update readmes

This commit is contained in:
averikitsch 2020-01-14 10:56:09 -08:00
parent 8958ac65db
commit 601bebc1b0
7 changed files with 126 additions and 55 deletions

View file

@ -0,0 +1,46 @@
# Example Workflows for Github Actions with Google Cloud Platform
These example workflows use the [setup-gcloud][action] to build and deploy applications to Google Cloud Platform.
## Workflows
| Workflow | Description |
| ------------------------------- | ------------------------ |
| [Google Kubernetes Engine](gke/)| Deploy a static site to an existing GKE cluster |
| [Cloud Run](cloud-run/) | Deploy a container to Cloud Run (Fully Managed)|
## Before you begin
1. [Create or select a Google Cloud Platform project][project].
1. Make sure that billing is enabled for your Google Cloud project. [Learn how to confirm billing is enabled for your project.][billing]
1. [Create a Service Account][service-account] and download a [JSON key][key].
* Base64 encode your JSON key with the following command:
```
base64 ~/path/to/key/key.json
```
* Add the encoded key to the [repository's secrets][secrets] (⚙ Settings > Secrets), named `GOOGLE_APPLICATION_CREDENTIALS`.
* Add the service account email, `<NAME@PROJECT_ID.iam.gserviceaccount.com`, to the repository's secrets, named `SA_EMAIL`.
## Resources
#### Example Actions
* [`actions/setup-node`](https://github.com/actions/setup-node)
* [`actions/setup-gcloud`](https://github.com/GoogleCloudPlatform/github-actions/tree/master/setup-gcloud)
* [Actions in GitHub Marketplace](https://github.com/marketplace?type=actions)
#### Example Workflows
* [`actions/starter-workflows`](https://github.com/actions/starter-workflows)
<!-- links -->
[action]: https://github.com/GoogleCloudPlatform/github-actions/tree/0c32120a9a2dda7fb9b392e6c3b90fa413b4642e/setup-gcloud
[project]: https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project
[billing]: https://cloud.google.com/billing/docs/how-to/modify-project
[service-account]: https://cloud.google.com/iam/docs/creating-managing-service-accounts#creating
[key]: https://cloud.google.com/iam/docs/creating-managing-service-account-keys#creating_service_account_keys
[secrets]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets

View file

@ -1,4 +1,4 @@
# Copyright 2019 Google Inc.
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -17,7 +17,9 @@
# To configure this workflow:
#
# https://github.com/GoogleCloudPlatform/github-actions/tree/docs/service-account-key/setup-gcloud#inputs
# 1. Set up secrets in your workspace: GKE_PROJECT with the name of the project, GKE_EMAIL with the service account email, GKE_KEY with the Base64 encoded JSON service account key.
# 1. Set up secrets in your workspace: GKE_PROJECT with the name of the project,
# SA_EMAIL with the service account email, GOOGLE_APPLICATION_CREDENTIALS with
# the Base64 encoded JSON service account key.
#
# 2. Change the values for the GKE_ZONE, GKE_CLUSTER and IMAGE environment variables (below).
@ -31,10 +33,8 @@ on:
# Environment variables available to all jobs and steps in this workflow
env:
GKE_PROJECT: ${{ secrets.GKE_PROJECT }}
GKE_EMAIL: ${{ secrets.GKE_EMAIL }}
GITHUB_SHA: ${{ github.sha }}
GKE_ZONE: us-west1-a
GKE_CLUSTER: example-gke-cluster
GKE_ZONE: us-west1-a
IMAGE: gke-test
jobs:
@ -50,19 +50,19 @@ jobs:
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '270.0.0'
service_account_email: ${{ secrets.GKE_EMAIL }}
service_account_key: ${{ secrets.GKE_KEY }}
service_account_email: ${{ secrets.SA_EMAIL }}
service_account_key: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
# Configure docker to use the gcloud command-line tool as a credential helper
- run: |
# Set up docker to authenticate
# via gcloud command-line tool.
gcloud auth configure-docker
# Build the Docker image
- name: Build
run: |
docker build -t gcr.io/"$GKE_PROJECT"/"$IMAGE":"$GITHUB_SHA" \
run: |
docker build -t gcr.io/$GKE_PROJECT/$IMAGE:$GITHUB_SHA \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" .
@ -70,7 +70,7 @@ jobs:
- name: Publish
run: |
docker push gcr.io/$GKE_PROJECT/$IMAGE:$GITHUB_SHA
# Set up kustomize
- name: Set up Kustomize
run: |
@ -80,7 +80,8 @@ jobs:
# Deploy the Docker image to the GKE cluster
- name: Deploy
run: |
gcloud container clusters get-credentials $GKE_CLUSTER --zone $GKE_ZONE --project $GKE_PROJECT
gcloud container clusters get-credentials $GKE_CLUSTER \
--zone $GKE_ZONE --project $GKE_PROJECT
./kustomize edit set image gcr.io/$GKE_PROJECT/$IMAGE:${GITHUB_SHA}
./kustomize build . | kubectl apply -f -
kubectl rollout status deployment/gke-test

View file

@ -1,51 +1,75 @@
<!--
Copyright 2019 Google LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing permissions and limitations under the
License.
-->
# Google Kubernetes Engine - GitHub Actions
An example workflow that uses [GitHub Actions](https://help.github.com/en/categories/automating-your-workflow-with-github-actions) to deploy [a static website](site/) to an existing [Google Kubernetes Engine](https://cloud.google.com/kubernetes-engine/) cluster.
## Workflow
The [example workflow](.github/workflows/gke.yml) will trigger on every push to this repo.
For pushes to the _default_ branch, `master`, the workflow will:
For pushes to the _feature_ branch, the workflow will:
1. Build the Docker image
1. Verify the Google Cloud Platform credentials are correct
1. Verify the Google Cloud Platform credentials are correct.
For pushes to the _default_ branch (`master`), in addition to the above Actions, the workflow will:
1. Tag and Push the image to Google Container Registry
* The image is available through the following tags: `latest`, the branch name, and first 8 of the commit SHA
* `gcloud` serves as a [credential helper](https://cloud.google.com/container-registry/docs/pushing-and-pulling) for Docker. This workflow registers `gcloud` as a credential helper and uses the 'docker' command within the `gcloud` action to push the image.
1. Use a Kubernetes Deployment to push an image to the Cluster
* Note that a GKE deployment requires a unique Tag to update the pods. Using a constant tag `latest` or a branch name `master` may result in successful workflows that don't update the cluster.
1. Build, tag, and push the image to Google Container Registry.
## Pre-reqs
* `gcloud` serves as a [credential helper](https://cloud.google.com/container-registry/docs/pushing-and-pulling) for Docker. This workflow registers `gcloud` as a
credential helper and uses the 'docker' command within the `gcloud` action
to push the image.
1. Google Cloud Platform project
1. GCP Service Account with write access to GCR and GKE for this project
1. GCP Service Account [credentials](https://cloud.google.com/iam/docs/creating-managing-service-account-keys) stored as a JSON key. Base64 encode the JSON key and paste the entire blob as a secret (Repository Settings --> Secrets) named `GKE_KEY`.
1. Also add Secrets for `GKE_PROJECT` and `GKE_EMAIL`. Those can be found in the raw key JSON above.
1. An existing Kubernetes Engine cluster
1. [Create a Cluster](https://cloud.google.com/kubernetes-engine/docs/quickstart#create_cluster)
1. Edit `deployment.yml` to enter the correct GCR path to your image. Easy to find from GCR section of GCP console after first image push.
## Resources
* The image is available through the following tags: `latest`, the branch
name, and first 8 of the commit SHA.
#### Example Actions
* [`actions/setup-node`](https://github.com/actions/setup-node)
* [`actions/setup-gcloud`](https://github.com/GoogleCloudPlatform/github-actions/tree/master/setup-gcloud)
* [Actions in GitHub Marketplace](https://github.com/marketplace?type=actions)
1. Use a Kubernetes Deployment to push the image to the cluster.
#### Example Workflows
* [`actions/starter-workflows`](https://github.com/actions/starter-workflows)
* Note that a GKE deployment requires a unique Tag to update the pods. Using
a constant tag `latest` or a branch name `master` may result in successful
workflows that don't update the cluster.
## Setup
1. Create or reuse a Github repository for the example workflow:
1. [Create a repository](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-new-repository).
1. Move into your repository directory.
1. Copy the example into the repository:
```
cp -r <path_to>/github-actions/example-workflows/gke/ ./
```
1. Add your Project Id to the [repository's secret][secrets], named `GKE_PROJECT`.
1. [Create a GKE cluster][cluster] or select an existing GKE cluster.
1. Update `deployment.yml` with the following values:
* `GKE_CLUSTER`: the name of your cluster.
* `GKE_ZONE`: the zone your cluster resides.
You can find the names of your clusters using the command: `gcloud container clusters list`,
and the zone using the command: `gcloud container clusters describe <CLUSTER_NAME>`.
1. [Add the the following roles to your service account][roles]:
* `Kubernetes Engine Developer`
* `Storage Admin`
## Run the workflow
1. Add and commit your changes:
```
git add .
git commit -m "Set up Github workflow"
```
1. Push to the `master` branch:
```
git push origin master
```
1. View the workflow by selecting the `Actions` tab at the top of your repository.
Then click on the `Build and Deploy to GKE` workflow to see the details.
[secrets]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets
[cluster]: https://cloud.google.com/kubernetes-engine/docs/quickstart#create_cluster
[roles]: https://cloud.google.com/iam/docs/granting-roles-to-service-accounts#granting_access_to_a_service_account_for_a_resource

View file

@ -1,4 +1,4 @@
# Copyright 2019 Google Inc.
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View file

@ -1,4 +1,4 @@
# Copyright 2019 Google Inc.
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View file

@ -1,4 +1,4 @@
# Copyright 2019 Google Inc.
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View file

@ -1,4 +1,4 @@
# Copyright 2019 Google Inc.
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.