Skip to content

Commit

Permalink
Merge pull request #169 from ostelco/feature/cloud-build
Browse files Browse the repository at this point in the history
cloud-build for prime
  • Loading branch information
vihangpatil authored Jun 14, 2018
2 parents 03dd9b7 + 869abe6 commit 9218863
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
63 changes: 63 additions & 0 deletions prime/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
steps:
# Download gradle cache zip from Google Storage (GS) Bucket
- name: gcr.io/cloud-builders/gsutil
args: ['cp', 'gs://prime-gradle-caches/caches.tar.gz', '/root/in_zip/']
volumes:
- name: gradle_caches_in_zip
path: /root/in_zip
# Unzip gradle cache zip
- name: ubuntu
args: ['tar', '-xzvf', '/root/in_zip/caches.tar.gz', '-C', '/root/.gradle/caches/', '.']
volumes:
- name: gradle_caches_in_zip
path: /root/in_zip
- name: gradle_caches
path: /root/.gradle/caches
# Gradle clean and build prime & its dependencies only
- name: gcr.io/cloud-builders/gradle
args: ['clean', 'prime:build']
volumes:
- name: gradle_caches
path: /root/.gradle/caches
timeout: 600s
# Remove unwanted files from gradle cache
- name: ubuntu
args: ['rm', '-f', '/root/.gradle/caches/modules-2/modules-2.lock']
volumes:
- name: gradle_caches
path: /root/.gradle/caches
- name: ubuntu
args: ['rm', '-fr', '/root/.gradle/caches/*/plugin-resolution/']
volumes:
- name: gradle_caches
path: /root/.gradle/caches
# Zip gradle cache
- name: ubuntu
args: ['tar', '-czvf', '/root/out_zip/caches.tar.gz', '-C', '/root/.gradle/caches', '.']
volumes:
- name: gradle_caches_out_zip
path: /root/out_zip
- name: gradle_caches
path: /root/.gradle/caches
# Upload gradle cache to Google Storage (GS) Bucket
- name: gcr.io/cloud-builders/gsutil
args: ['cp', '/root/out_zip/caches.tar.gz', 'gs://prime-gradle-caches']
volumes:
- name: gradle_caches_out_zip
path: /root/out_zip
# Build docker images
- name: gcr.io/cloud-builders/docker
args: ['build', '--tag=gcr.io/$PROJECT_ID/prime:$TAG_NAME', '--cache-from', 'openjdk:8u171', 'prime']
timeout: 120s
# Deploy new docker image to Google Kubernetes Engine (GKE)
- name: ubuntu
args: ['sed', '-i', 's/PRIME_VERSION/$TAG_NAME/g', 'prime/infra/prime.yaml']
- name: gcr.io/cloud-builders/kubectl
args: ['apply', '-f', 'prime/infra/prime.yaml']
env:
- 'CLOUDSDK_COMPUTE_ZONE=europe-west1-b'
- 'CLOUDSDK_CONTAINER_CLUSTER=private-cluster'
timeout: 300s

# Upload docker image into Google Container Registry (GCR)
images: ['gcr.io/$PROJECT_ID/prime:$TAG_NAME']
27 changes: 26 additions & 1 deletion prime/infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@
Reference:
* https://cloud.google.com/endpoints/docs/grpc/get-started-grpc-kubernetes-engine

## Deploying a Deployment to GKE using GCP Container/Cloud Builder

* A build trigger is configured in GCP Container/Cloud Builder to build and deploy prime to GKE cluster
just by adding a git tag.
* The tag name should be `prime-*`
* Tag can be on any branch. (Should we limit this to `master` branch only?).

#### Limitations
* The version tag on docker images is `prime-X.Y.Z` instead of `X.Y.Z`.

#### Future Improvements
* Create a custom build docker image. (suggestion by Vihang).
* Run AT as quality gate. (suggestion by Remseth).
* Use it for CI. Currently it is only CD. (suggestion by Remseth).
* Use `git-sha` along/instead with version (suggestion by Håvard).

#### References
* Config: https://cloud.google.com/container-builder/docs/build-config
* Running locally: https://cloud.google.com/container-builder/docs/build-debug-locally
* Cloud builders: https://cloud.google.com/container-builder/docs/cloud-builders
* Customization: https://cloud.google.com/container-builder/docs/create-custom-build-steps
* Optimization: https://cloud.google.com/container-builder/docs/speeding-up-builds
* Custom Github web-hooks: https://cloud.google.com/container-builder/docs/configure-third-party-notifications
* Storing secrets for AT: https://cloud.google.com/container-builder/docs/securing-builds/use-encrypted-secrets-credentials

## Secrets

kubectl create secret generic pantel-prod.json --from-file config/pantel-prod.json
Expand Down Expand Up @@ -48,7 +73,7 @@ Update the tag (version) of prime's docker image in `infra/prime.yaml`.

Apply the deployment & service

sed -e "s/PRIME_VERSION/$PRIME_VERSION/" infra/prime.yaml | kubectl apply -f -
sed -e s/PRIME_VERSION/$PRIME_VERSION/g infra/prime.yaml | kubectl apply -f -


Details of the deployment
Expand Down

0 comments on commit 9218863

Please sign in to comment.