Skip to content
This repository has been archived by the owner on Mar 12, 2023. It is now read-only.

Deploy to Google Cloud Run

Hiroki Toyokawa edited this page Dec 3, 2022 · 1 revision

You can also run easy-notion-blog on Google Cloud Run instead of Vercel.

You should execute Next.js as SSR(Server-Side Rendering) not ISR(Incremental Static Regeneration).

1. Change ISR to SSR

  1. Replace getStaticProps({ props }) to getServerSideProps({ res, props }) from all pages
  2. Place res.setHeader("Cache-Control", "public, s-maxage=300, stale-while-revalidate=86400") into getServerSideProps()
  3. Remove revalidate property from return object of the pages
  4. Remove getStaticPaths() from all pages

2. Create Dockerfile

Dockerfile

FROM node:16 AS builder

ARG NEXT_PUBLIC_URL
ARG NEXT_PUBLIC_GA_TRACKING_ID

ENV NEXT_PUBLIC_URL=${NEXT_PUBLIC_URL}
ENV NEXT_PUBLIC_GA_TRACKING_ID=${NEXT_PUBLIC_GA_TRACKING_ID}

ENV NODE_ENV=development

WORKDIR /app

COPY package.json ./
COPY yarn.lock ./

RUN yarn install

COPY . .

RUN yarn build


FROM node:16-slim AS runner

ENV NODE_ENV=production

WORKDIR /app

COPY package.json ./
COPY yarn.lock ./

RUN yarn install

COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public

CMD ["yarn", "start"]

3. Deploy to Google Cloud Run

Build Docker image and push to Container Registry or Artifact Registry.

And deploy to Cloud Run.