ReaperCI Documentation

ReaperCI documentation

Deploy a Next.js application

This example tests a lockfile-based Next.js application, builds an immutable container image, requests a staging deployment, and verifies an HTTP health route. Use the Node version your application supports; the example uses Node 22.

Prepare the application

Enable standalone output in next.config.js or next.config.mjs:

const nextConfig = { output: "standalone" };
export default nextConfig;

Add a health route such as app/api/healthz/route.js:

export function GET() {
  return Response.json({ status: "ok" });
}

Use a production Dockerfile that copies the standalone server and static assets:

FROM node:22-bookworm-slim AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:22-bookworm-slim
ENV NODE_ENV=production PORT=3000 HOSTNAME=0.0.0.0
WORKDIR /app
USER node
COPY --from=build --chown=node:node /app/.next/standalone ./
COPY --from=build --chown=node:node /app/.next/static ./.next/static
COPY --from=build --chown=node:node /app/public ./public
EXPOSE 3000
CMD ["node", "server.js"]

Add the pipeline

Create .reaperci.yml:

on:
  push:
    branches: [main]
  manual: true

steps:
  - name: test
    image: node:22-bookworm-slim
    run: npm ci && npm test
    timeout: 15m
    caches:
      - key: nextjs-npm
        path: /root/.npm
    resources:
      cpu: "2"
      memory: 2GiB

  - name: image
    dockerfile: Dockerfile
    tags:
      - web:{{short_sha}}
    dependsOn: [test]

deploy:
  environment: staging
  image: web:{{short_sha}}
  container: web
  runArgs:
    - -p
    - 3000:3000
  approve: manual
  healthCheck:
    url: https://staging.example.com/api/healthz
    interval: 5s
    timeout: 10s
    failureThreshold: 3
  autoRollback: true

Create the staging environment in ReaperCI, point it at the staging server, and store runtime values as environment secrets rather than YAML values.

Verify

Push the branch and confirm the provider/native build records both steps. Review the immutable deployment inputs, approve staging, and verify the public health URL and a real page. Then use Deploys > Inspect to confirm the running image matches the requested digest. Do not add production until the rollback tutorial has passed for this service.