Deploy Gokit Todo to GAE With Cloud Build From Github Repo
gokit-todo
https://github.com/cage1016/gokit-todo
todomvc full stack demo project. react + backend API by gokit microservice toolkit. include unit test, integration test, e2e test, github action ci
https://github.com/cage1016/gokit-todo-frontend
gokit todo frotnend: React todomvc
gokit-doto
(Microservices backend API with Postgres database) and gokit-todo-frontend
(React todomvc) are demo applications developed for Kubernetes with Ingress (Istio/Nginx-ingress). You can also quickly start an entire application with a database via docker-compose. Feel free to try it out by following the guide in the repo.
migrate gokit-todo gokit-todo-frontent to Google App Engine with Cloud SQL
Before we migrated our Kubernetes application to Google App Engine. We first need to have some understanding of Google App Engine. Make sure our ideas work.
- Google App Engine is a Pass (Platform as a Service) service, which means we only need to focus on application development. So we can reuse gokit-todo, gokit-todo-frontend source code and deploy to Google App Engine through
app.yaml
configuration ✅ - Google App Engine support standard-runtime (
Python
,Java
, Node.js
,PHP
,Ruby
,Go
) and flexible-runtime (Go
,Java 8
,PHP 5/7
,Python 2.7/3.6
,.NET
,Node.js
,Ruby
,Custom runtime
)- Choose standard runtime Go 1.16 for gokit-todo as it is a pure backend API microservice ✅
- Chosee standard-runtime Node.js 16 for gokit-todo-frontentd as it is React frontend application ✅
- We can choose Cloud SQL (Postgres) as our database to gokit-todo application in Google App Engine environment. You must use Cloud SQL proxy postgres driver
cloudsqlpostgres
to connect to Cloud SQL cause Cloud SQL will handle the connection authentication and authorization automatically. ✅ - We can choose Google Cloud Build to handle CI/CD pipeline workflow and fully integrate with Github repo. There is most important things is you need to grant project default Google Cloud service account
[email protected]
with enough permissions to build and deploy your application. ✅
Architecture
Above is the whole architecture of our application gokit-todo-gae
leverage with gokit-todo
and gokit-todo-frontend
as git submodule. Using a project with git submodules avoids the overhead of interfering with the application source code.
Google App Engine
It’s very basic setup for our demo scenario. Just enable Google App Engine service in Google Cloud project and we will leverage Google Cloud Build to handle all depoyment jobs
|
|
Cloud SQL
You can create a Cloud SQL instance in Google Cloud Console or gcloud sql instances create
command. The following gcloud command will create a Cloud SQL.
|
|
When Cloud SQL instance is created then we need to crate a demo database.
|
|
It’s quick simple step to create a Cloud SQL instance and a demo database via gcloud command. Cloud SQL instance setup with Public IP address as default and you can also setup with Private IP address as your want. Make sure you enable VPC network for your private IP address Cloud SQL instance.
Google Cloud Build
As previous mentioned that all CI/CD jobs are handled by Google Cloud Build. We need to create a bunch of Cloud Build configurations to build and deploy our application.
We added
gokit-todo
andgokit-todo-frontend
application as project git submodule. We create a Cloud Build configuration forgokit-todo
andgokit-todo-frontend
and each of them could trigger another cloud build trigger to deploy application.It’s useful tips to trigger Cloud Build trigger by RESTful API in one Cloud Build steps.
1 2 3
curl -d '{"branchName":"master"}' -X POST -H "Content-type: application/json" \ -H "Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" \ https://cloudbuild.googleapis.com/v1/projects/<gcp-project>/triggers/<cloudbuild-trigger-id>:run
Trigger trigger
gokit-todo
andgokit-todo-frontend
bycloudbuild.api.yaml
及cloudbuild.default.yaml
It’s also to deploy Google App Engine dispatch router
dispatch.yaml
settings throughcloudbuild.dispatch.yaml
gokit-todo-gae
|
|
You can see above project file structure (gokit-todo-gae) is same as previous architecture diagram. The operation process is as follows
Frontend developer push code to Github repo
gokit-todo-frontend
👉 triggergokit-todo-frontend
will be triggered and do their steps job and triggergokit-todo-gae-deploy-default
trigger by RESTFul API at last step 👉 triggergokit-todo-gae-deploy-default
will build and deploygokit-todo-frontend
application to Google App Engine.Backend developer push code to Github repo
gokit-todo
👉 triggergokit-todo
will be triggered and do their steps job (application testing) and triggergokit-todo-gae-deploy-api
trigger by RESTFul API at last step 👉 triggergokit-todo-gae-deploy-api
will build and deploygokit-todo
application to Google App Engine.It’s also easy to update Google App Engine dispatch routing setting by push
dispatch.yaml
changed to Github repogokit-todo-gae
👉 triggergokit-todo-gae-deploy-dispatch
will update dispatch routing to Google App Engine
summary
Google App Engine is easy to get started with. In particular, for simple applications like this demo, the Google App Engine standard-runtime offers a free tier of 28 instance-hours per day. We can migrate pre Kubernetes application gokit-todo
and gokit-todo-frontend
to Google App Engine without any code modified, just leverage with requirement app.yaml
and Google App Engine could collaborate with GitHub Repo and Google Cloud Build well.
Q Why don’t we use Github build-in CI/CD Github action instead of Google Cloud Build ?A Yes, You could do HTTP request to trigger Google Cloud Build trigger in Github Action but have to handle request authentication by yourself. Google Cloud Build will auto handle those request authentication automatically
source code
gokit-todo
https://github.com/cage1016/gokit-todogokit-todo-frontend
https://github.com/cage1016/gokit-todo-frontendgokit-todo-gae
https://github.com/cage1016/gokit-todo-gae