An example devops pipeline for prototyping. Author: Dylan Klein
The demo pipeline builds a simple "hit counter" web app using Python's Flask framework with Redis as a database. It then deploys the dockerised architecture to Google Kubernetes Engine (GKE).
The following is a visual representation of the CICD process.
Developers can develop the Flask app on their localhost in a containerised environment using Docker. If you wish to run the app on localhost (for testing purposes):
- Modify
app.py
line 7:
cache = redis.Redis(host='my-redis-svc.default.svc.cluster.local', port=6379)
to:
cache = redis.Redis(host='redis', port=6379)
- Run the command
$ docker-compose up
to build the app locally.
When the workflow is triggered (either via git push
or otherwise), the first thing that GitHub Actions does is authenticate to GCP via Workload Identity Federation.
The following docker image is then built via GitHub Actions (Continuous Integration):
dylan-website
(Flask frontend)
The latest docker image (titled dylan-website
) is then published to GCP's Artifact Registry.
Once docker build & publish are successful, GitHub Actions deploys the following 2 docker images as workloads to GKE (Continuous Deployment):
gke-test
(Flask frontend)redis-master
(Redis backend)
GitHub Actions also deploys the following 2 services, such that the workloads mentioned above can be accessed:
gke-test-service
(External Loadbalancer - i.e. internet facing)my-redis-svc
(ClusterIP)
- Create a new GCP project and authorise GitHub Actions via IAM. Follow these instructions for help: https://github.com/google-github-actions/setup-gcloud/tree/master/example-workflows/gke-kustomize
- Git clone this repository:
$ git clone https://github.com/dylman123/devops-pipeline.git
- Add your GCP project ID as a secret in your project repository, using
GKE_PROJECT
as the key. - Modify
cicd-pipeline.yml
with your specific env variables. - Modify
cicd-pipeline.yml
with your specific auth details for:
workload_identity_provider
andservice_account
To run, all you have to do is git push
your code or manually click 'Re-run all jobs' in GitHub Actions.
To ensure your deployment worked successfully:
- Find the IP address of the
gke-test-service
service which you deployed in GCP. - Navigate to the IP address in your browser on port 80.