Skip to content

Instantly share code, notes, and snippets.

@nadyshalaby
Last active June 26, 2023 08:27
Show Gist options
  • Save nadyshalaby/be50ce03f8d856850e99a4f1f7a21f99 to your computer and use it in GitHub Desktop.
Save nadyshalaby/be50ce03f8d856850e99a4f1f7a21f99 to your computer and use it in GitHub Desktop.
How to deploy a NestJs Application on Cloud Run Service using CloudBuild and Docker
steps:
# This step builds the container image.
- name: 'gcr.io/cloud-builders/docker'
timeout: 1500s
id: Build
args:
- 'build'
- '-t'
- 'gcr.io/$PROJECT_ID/<project-name>:$SHORT_SHA' # Don't forget to update <project-name>
- '.'
# This step pushes the image to Container Registry
# The PROJECT_ID and SHORT_SHA variables are automatically
# replaced by Cloud Build.
- name: 'gcr.io/cloud-builders/docker'
timeout: 1500s
id: Push
args:
- 'push'
- 'gcr.io/$PROJECT_ID/<project-name>:$SHORT_SHA' # Don't forget to update <project-name>
# Deploy container image to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
args:
- 'run'
- 'deploy'
- '<project-name>' # Don't forget to update <project-name>
- '--image'
- 'gcr.io/$PROJECT_ID/<project-name>:$SHORT_SHA' # Don't forget to update <project-name>
- '--region'
- 'europe-west1'
- '--platform'
- 'managed'
- '--allow-unauthenticated'
- '--port'
- '3000'
images:
- 'gcr.io/$PROJECT_ID/<project-name>:$SHORT_SHA' # Don't forget to update <project-name>
timeout: 1500s
FROM node:lts-alpine3.18
WORKDIR /app
COPY package.json .
RUN yarn
COPY . .
RUN yarn build
EXPOSE 3000
CMD [ "yarn", "start:prod" ]
@nadyshalaby
Copy link
Author

nadyshalaby commented Jun 26, 2023

Don't forgot to read this article if you want to connect to Cloud SQL (e.g. PostGres or MySQL) database from Cloud Run Service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment