Step before deploy app engine and cloud run
- Create Project
- Enable Cloud Build API (Click Here to Enable Cloud Build API)
- Enable App Engine API Click Here
- Clone your repo in google cloud shell
- Prepare database
- Create app.yaml file and fill the file with this code
runtime: nodejs20 - Make sure your package.json script is this
"scripts": { "start": "node server.js" } - Run this command to deploy to App Engine
gcloud app deploy - Test your app
- Clone your repo in google cloud shell
- Prepare database
- Create artifact registry repo
- Create Dockerfile file and fill the with this code
#Use the official Node.js 14 image as the base image FROM node:20 #Set the working directory in the container WORKDIR /usr/src/app #Copy package.json and package-lock.json to the working directory COPY package*.json ./ #Install app dependencies RUN npm install #Copy the rest of the application code to the working directory COPY . . #Expose the port your app runs on EXPOSE 8080 #Command to run your application CMD ["npm", "start"] - Build docker image and don't forget to tag it
docker build -t <image-name>:<tag> . - Create tag to Artifact Registry
docker tag <image_name>:<tag> <location>-docker.pkg.dev/<project_id>/<repository_name>/<image_name>:<tag> - Push docker image to artifact registry
docker push <location>-docker.pkg.dev/<project_id>/<repository_name>/<image_name>:<tag> - Deploy cloud run by pull docker image from artifact registry
gcloud run deploy <service-name> --image <image-uri> - Test your app