Coder Social home page Coder Social logo

gcp-ci-cd-demo-node's Introduction

gcp-ci-cd-demo

Test Node Application to automatically build & deploy to GCP

Build & Test locally

cd node-hello-world
npm install
npm start

Enable APIs

gcloud services enable appengine.googleapis.com cloudfunctions.googleapis.com artifactregistry.googleapis.com run.googleapis.com translate.googleapis.com

App Engine Deploy

gcloud app deploy

Cloud Run Deploy

gcloud run deploy

Demo instructions(DRAFT)

gcloud config set project ??
export PROJECT_ID=$(gcloud config get-value project)
export PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format='value(projectNumber)')
export REGION=us-central1
gcloud config set compute/region $REGION
  • Create repo in Cloud Source Repositories
  • Clone it
  • Add gitignore npm init
  • replace package.js
  • create app.js
  • NPM install & check
    npm install
    node app.js
  • Git commit & push
    git add .
    git commit -m "Initial commit"
    git push
  • Add Dockerfile & .dockerignore
  • Add artifact Registry >> "registry-docker-hello"
  • Authenticate Docker
    gcloud auth configure-docker us-central1-docker.pkg.dev 
  • Docker Build & Push
    docker build -t us-central1-docker.pkg.dev/$PROJECT_ID/registry-docker-hello/gcp-ci-cd-demo:test .
    docker push us-central1-docker.pkg.dev/$PROJECT_ID/registry-docker-hello/gcp-ci-cd-demo:test
  • Add cloudbuild-cd-cloudrun.yaml
    steps:
    # Build the container image
    - name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-t', 'us-central1-docker.pkg.dev/$PROJECT_ID/registry-docker-hello/gcp-ci-cd-demo:$REVISION_ID', '.']
    #  dir: 'node-hello-world'
    # Push the container image to Container Registry
    - name: 'gcr.io/cloud-builders/docker'
    args: ['push', 'us-central1-docker.pkg.dev/$PROJECT_ID/registry-docker-hello/gcp-ci-cd-demo:$REVISION_ID']
    # Deploy container image to Cloud Run
    - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
    entrypoint: gcloud
    args: ['run', 'deploy', 'node-hello-world', 
            '--image', 'us-central1-docker.pkg.dev/$PROJECT_ID/registry-docker-hello/gcp-ci-cd-demo:$REVISION_ID', 
            '--region', 'us-central1',
            "--allow-unauthenticated"
            ]
    images: ['us-central1-docker.pkg.dev/$PROJECT_ID/registry-docker-hello/gcp-ci-cd-demo:$REVISION_ID']
  • Add Cloud Build Trigger
  • Add app.yaml with "runtime: nodejs18"
  • Add cloudbuild-cd-appengine.yaml
    steps:
    - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
    entrypoint: 'bash'
    #  dir: 'node-hello-world'
    args: ['-c', 'gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy']
    timeout: '1600s'

gcp-ci-cd-demo-node's People

Contributors

niranvv avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.