-
-
Save vivek-dhayalan/dc421c2329f09eb499fb7e53d21fe1c6 to your computer and use it in GitHub Desktop.
Building Cloud Native CI/CD Pipeline with GCP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
steps: | |
# Remove last run test results | |
- id: remove-allure-results | |
name: gcr.io/cloud-builders/gsutil | |
entrypoint: "/bin/bash" | |
args: ["-c", "gsutil -m rm -r gs://$_GCS_BUCKET_PATH"] | |
allow_failure: true | |
# Getting the sub-module ui-tests | |
- id: git-submodule | |
name: "gcr.io/cloud-builders/git" | |
entrypoint: "bash" | |
args: | |
- "-c" | |
- | | |
git init | |
git clean -d -f . #clean current working directory | |
git remote add origin https://source.developers.google.com/p/[my-gcp-project]/r/[my-host-repo-name] | |
git fetch origin $BRANCH_NAME | |
git checkout $COMMIT_SHA #checkout at current commit | |
git config -f .gitmodules submodule.[my-submodule-repo-name].url https://source.developers.google.com/p/[my-gcp-project]/r/[my-submodule-repo-name] | |
git submodule update --init | |
# Executing Docker compose file | |
- id: docker-compose | |
name: "docker/compose:1.19.0" | |
args: ["up", "-d"] | |
timeout: 900s #15 mins | |
# Installing test dependencies | |
- id: npm-test | |
dir: "ui-tests" | |
name: node:18 | |
entrypoint: npm | |
args: ["install", "--force"] | |
# Executing Ui tests | |
- id: run-ui-test | |
dir: "ui-tests" | |
name: node:18 | |
entrypoint: npm | |
args: ["run", "$_SUITE_NAME"] | |
env: | |
- "DOCKER_SERVICE=true" | |
- "SITE_URL=$_SITE_URL" | |
- "GOOGLE_CHAT_WEBHOOK=$_GCHAT_WEBHOOK" | |
allow_failure: true | |
timeout: 600s #5 mins | |
# Copy test results to cloud bucket | |
- id: copy-allure-results | |
dir: "ui-tests" | |
name: gcr.io/cloud-builders/gsutil | |
entrypoint: "/bin/bash" | |
args: | |
[ | |
"-c", | |
"gsutil -m cp -r test-results gs://$_GCS_BUCKET_PATH", | |
] | |
# Adding check gates 1&2 to verify test exit code and incase of failure/error | |
# abort pushing build image to registry | |
# Check Gate 1 - ExitCode file exists | |
- id: check-gate-1 | |
dir: "ui-tests" | |
name: ubuntu | |
entrypoint: "bash" | |
args: | |
- "-c" | |
- | | |
test -f $_EXITCODE_FILENAME && echo "$_EXITCODE_FILENAME exists." | |
# Check Gate 2 - Read ExitCode file | |
- id: check-gate-2 | |
dir: "ui-tests" | |
name: ubuntu | |
entrypoint: "bash" | |
args: | |
- "-c" | |
- | | |
ls | |
cat $_EXITCODE_FILENAME | |
if [[ $(< $_EXITCODE_FILENAME) == "1" ]]; then | |
exit 1 | |
fi | |
# Tag and Push built image to registry | |
- id: push-image | |
name: "gcr.io/cloud-builders/docker" | |
entrypoint: "bash" | |
args: | |
- "-c" | |
- | | |
docker tag next-app gcr.io/$PROJECT_ID/next-app:latest | |
docker push gcr.io/$PROJECT_ID/next-app:latest | |
# Send build notification via webhook - image pushed | |
- id: notify-image-pushed | |
name: "curlimages/curl" | |
args: | |
[ | |
"-d", | |
"{'text': 'Container Registry - image pushed.. Yet to Deploy! from build: $BUILD_ID'}", | |
"-X", | |
"POST", | |
"$_GCHAT_WEBHOOK", | |
"-H", | |
"Content-Type: application/json", | |
"--http1.1", | |
] | |
# Deploy latest built image to Cloud Run | |
- id: deploy-built-image | |
name: "gcr.io/google.com/cloudsdktool/cloud-sdk" | |
entrypoint: gcloud | |
args: | |
[ | |
"run", | |
"deploy", | |
"next-app", | |
"--image", | |
"gcr.io/$PROJECT_ID/next-app:latest", | |
"--region", | |
"us-west1", | |
] | |
# Send build notification via webhook - image deployed | |
- id: notify-image-deployed | |
name: "curlimages/curl" | |
args: | |
[ | |
"-d", | |
"{'text': 'Cloud Run - image Deployed! from build: $BUILD_ID'}", | |
"-X", | |
"POST", | |
"$_GCHAT_WEBHOOK", | |
"-H", | |
"Content-Type: application/json", | |
"--http1.1", | |
] | |
images: ["gcr.io/$PROJECT_ID/next-app:latest"] | |
options: | |
logging: CLOUD_LOGGING_ONLY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "2.3" | |
services: | |
next-application: | |
build: | |
context: . | |
dockerfile: Dockerfile | |
image: next-app | |
container_name: next-app | |
environment: | |
- NEXT_PUBLIC_ENV_1= env value1 | |
- NEXT_PUBLIC_ENV_2= env value2 | |
ports: | |
- "3000:3000" | |
healthcheck: | |
test: curl --fail http://localhost:3000 || exit 1 | |
interval: 60s | |
retries: 5 | |
timeout: 10s | |
chrome: | |
image: selenium/node-chrome:4.7.1-20221208 | |
depends_on: | |
- selenium-hub | |
environment: | |
- SE_EVENT_BUS_HOST=selenium-hub | |
- SE_EVENT_BUS_PUBLISH_PORT=4442 | |
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443 | |
ports: | |
- "6900:5900" | |
firefox: | |
image: selenium/node-firefox:4.7.1-20221208 | |
depends_on: | |
- selenium-hub | |
environment: | |
- SE_EVENT_BUS_HOST=selenium-hub | |
- SE_EVENT_BUS_PUBLISH_PORT=4442 | |
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443 | |
ports: | |
- "6901:5900" | |
selenium-hub: | |
image: selenium/hub:4.7.1-20221208 | |
depends_on: | |
next-application: | |
condition: service_healthy | |
container_name: selenium-hub | |
ports: | |
- "4442:4442" | |
- "4443:4443" | |
- "4444:4444" | |
networks: | |
default: | |
external: | |
name: cloudbuild |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment