I am attempting to deploy my basic next.js app (code here) to google cloud run using a basic CI/CD pipeline. I have a dockerfile that works fine locally, and builds on GCP:
FROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Copy package.json and package-lock.json (if available)
COPY package*.json ./
# Install dependencies
RUN npm ci
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED 1
RUN npm run build
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
ENV PORT=${PORT:-8080}
EXPOSE ${PORT}
#CMD ["node", "server.js"] <- I have tried this as well
CMD ["npm", "run", "start"]
The issue is that that is all it does. Building is the only step (if i were to do this through firebase there would be multiple steps) and after completing the build nothing seems to actually deploy. And it just has the placeholder text: app url. I have set my (IAM) permissions correctly (as far as I can tell). What am I missing?
Please feel free to comment on any other relevant/useful information I could give.
Also: I know my dockerfile uses a lowercase d instead of an uppercase D, but I have it set correctly in GCP, and it clearly reads the dockerfile and does its contents
Edit:
I have added my trigger file as an image. Is my issue that I need a cloudbuild.yaml file?
6
You just need to add cloud run deployment to a build step in your cloud build job.
Here’s a sample cloudbuild yaml file you could use as a starting point:
steps:
- id: Build
name: gcr.io/cloud-builders/docker
entrypoint: "bash"
args:
- "-c"
- |
docker build -t gcr.io......<your tag here> &&
docker push -t gcr.io......<your tag here>
- id: Deploy to Cloud Run
name: gcr.io/cloud-builders/gcloud
entrypoint: "bash"
args:
- "-c"
- |
gcloud run deploy myNextJSApp
--image <your gcr.io tag from the build step>
--region australia-southeast2
--platform managed
--allow-unauthenticated