Last active
June 26, 2023 08:27
-
-
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
This file contains hidden or 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: | |
# 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 |
This file contains hidden or 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
FROM node:lts-alpine3.18 | |
WORKDIR /app | |
COPY package.json . | |
RUN yarn | |
COPY . . | |
RUN yarn build | |
EXPOSE 3000 | |
CMD [ "yarn", "start:prod" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't forgot to read this article if you want to connect to Cloud SQL (e.g.
PostGres
orMySQL
) database from Cloud Run Service