Deploying Nuxtjs on Google Cloud Run (Serverless)

Deploying Nuxtjs on Google Cloud Run (Serverless)

Deploying Nuxtjs on Google Cloud Run. Quickest and easiest way to deploy Nuxtjs.

Better cloud-build.yaml file pull older image before build. Save build time.


Cloud run now available in almost every region (including Singapore Hooooray!!!)

What and why?

I like NuxtJS and I use it a lot in many of my customer projects. I like it a lot and it's super easy to go serverless on Google Cloud Run. It's cheap and it support SSR as well. You should check pricing before you proceed though...


I'm using MacOS. Please let me know if I'm missing anything.

There will be times in this tutorial when gcloud cli will ask you to enable things like cloud build / cloud run / etc. If you don't enable them, this tutorial won't work. If you do, make sure you know the upcoming cost.

Let's start

First, we will create an empty project. You might want to read this.

# or just run
npx create-nuxt-app cloud-run-demo

Create nuxt app

I like git, so let's commit first.

Commit initial code

I want to know if it's working or not. Let's just try it out. Go into project directory and run npm run dev

Test our code

Cloud run require process.env.PORT to be your application port. So let's change our server config. Also, please note that using express + cloud run require host to be not localhost or

Add port config

  server: {
    port: process.env.PORT || 3000,
    host: "",
    timing: false

Add Dockerfile to build our project. You can change node version to match your project.

Add docker file

FROM node:13.6-alpine


RUN mkdir -p /usr/src/app
COPY package*.json /usr/src/app/
RUN cd /usr/src/app/; npm install
WORKDIR /usr/src/app
COPY . /usr/src/app

RUN npm run build

CMD [ "npm", "run", "start" ]

I like to config my cloud build in yaml. Let's do that by adding a file call cloud-build.yml (or anything else you like). You will need to change project-name to match your google gcloud-project-id. And container-name to whatever you want.

Add google cloud build config

  - name: ''
    entrypoint: 'bash'
      - '-c'
      - |
        docker pull || exit 0
  - name:
    timeout: 1200s
timeout: 1200s

Let's build our project on Google Cloud Build. don't forget to change project-name with your gcloud-project-id.

# build from yml config
gcloud builds submit --project "project-name" --config=./cloud-build.yaml

Cloud build

Finally let's deploy. Don't forget to change

  • cloud-run-name service name (any name you like). It will show up on
  • --region asia-northeast1 you can choose region to closest to your location.
  • project-name to your gcloud-project-id
  • --image change it to match what you set in cloud-build.yaml
# deploying (rerun to redeploy)
gcloud beta run deploy cloud-run-name --region asia-northeast1 --project "project-name" --image --platform managed

Run container on cloud run

Now, you can visit that endpoint given in the console. Usually https://cloud-run-name-{some_hash}

Or you can change the domain to something else. You should be able to find it here.

This is way too easy to deploy Serverless Nuxtjs app.

I believe you can do the same in both Nextjs or Gatsby as well. If you've done it, please share.

Again, let me know if I missed anything.