Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mchmarny/knative-gitops-using-cloud-build
GitOps demo using Cloud Build and Knative
https://github.com/mchmarny/knative-gitops-using-cloud-build
build cloud github knative
Last synced: 3 months ago
JSON representation
GitOps demo using Cloud Build and Knative
- Host: GitHub
- URL: https://github.com/mchmarny/knative-gitops-using-cloud-build
- Owner: mchmarny
- License: apache-2.0
- Created: 2019-01-22T20:44:39.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-20T09:04:29.000Z (about 3 years ago)
- Last Synced: 2023-08-10T11:04:00.164Z (over 1 year ago)
- Topics: build, cloud, github, knative
- Language: Go
- Homepage: https://knative.dev
- Size: 246 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# knative-gitops-using-cloud-build
> GitOps demo using Cloud Build and Knative
Live demo: https://gocr.demo.knative.tech/
Simple setup to automate Knative deployments using Git and Cloud Build
As a developer, you write code and commit it to a repo. You also hopefully run tests on that code for each commit. Assuming your application passes all the tests, you may want to deploy it to Knative cluster. You can do it form your workstation by using any one of the Knative CLIs (e.g. gcloud, knctl, tm etc.).
In this demo however we are going to demonstrate deploying directly from git repository. This means that you as a developer do not need install anything on your machine other than the standard git tooling. Here is the outline:
* Create a release tag on the commit you want to deploy in git
* Cloud Build then:
* Tests (again)
* Builds and tags image
* Pushes that image to repository
* Creates Knative service manifest
* Applies that manifest to designated Knative cluster> As an add-on, we are also going to send mobile notification with build status using [knative-build-status-notifs](https://github.com/mchmarny/knative-build-status-notifs)
## Setup
You will have to [configure git trigger](https://pantheon.corp.google.com/cloud-build/triggers/add) in Cloud Build first. There doesn't seem to be a way to do this using `gcloud`.

Then setup IAM policy binding to allow Cloud Builder deploy build image to your cluster
```shell
PROJECT_NUMBER="$(gcloud projects describe ${PROJECT_ID} --format='get(projectNumber)')"
gcloud projects add-iam-policy-binding ${PROJECT_NUMBER} \
--member=serviceAccount:${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com \
--role=roles/container.developer
```Finally submit the Cloud Build configuration
```shell
gcloud builds submit --config deployments/cloudbuild.yaml
```
## Deployment
To build and deploy specific commit from git, tag it and publish the tags. We also are going to print the last few tags so we can see the exact commit hash.
```shell
git tag "release-v${RELEASE_VERSION}"
git push origin "release-v${RELEASE_VERSION}"
git log --oneline
```## Logs
You can monitor progress of your build but first finding its id
```shell
gcloud builds list
```And then describing it
```shell
gcloud builds describe BUILD_ID
```You can always also navigate to the [Build History](https://pantheon.corp.google.com/cloud-build/builds?folder=&organizationId=433637338589&project=s9-demo) screen in UI and see it there.