# syntax=docker/dockerfile:1.19.0
# This file is generated by Dofigen v2.8.0
# See https://github.com/lenra-io/dofigen

# manifests
FROM node@sha256:0e0ff40c39bc087845bfb27465a0df4ea419520094bc35842ff83dd8cbe6f9b6 AS manifests
LABEL \
    org.opencontainers.image.base.digest="sha256:0e0ff40c39bc087845bfb27465a0df4ea419520094bc35842ff83dd8cbe6f9b6" \
    org.opencontainers.image.base.name="docker.io/node:24-slim"
WORKDIR /app
COPY \
    --link \
    "." "/app/"
RUN <<EOF
mkdir -p /out
cp pnpm-workspace.yaml pnpm-lock.yaml package.json /out/
find apps packages -name package.json -not -path '*/node_modules/*' -exec cp --parents {} /out/ \;
EOF

# install
FROM node@sha256:0e0ff40c39bc087845bfb27465a0df4ea419520094bc35842ff83dd8cbe6f9b6 AS install
LABEL \
    org.opencontainers.image.base.digest="sha256:0e0ff40c39bc087845bfb27465a0df4ea419520094bc35842ff83dd8cbe6f9b6" \
    org.opencontainers.image.base.name="docker.io/node:24-slim"
ENV \
    PATH="$PNPM_HOME:$PATH" \
    PNPM_HOME="/pnpm"
WORKDIR /app
COPY \
    --from=manifests \
    --link \
    "/out/" "/app/"
RUN <<EOF
corepack enable pnpm
pnpm install --frozen-lockfile --filter=@openstatus/dashboard...
EOF

# builder
FROM node@sha256:0e0ff40c39bc087845bfb27465a0df4ea419520094bc35842ff83dd8cbe6f9b6 AS builder
LABEL \
    org.opencontainers.image.base.digest="sha256:0e0ff40c39bc087845bfb27465a0df4ea419520094bc35842ff83dd8cbe6f9b6" \
    org.opencontainers.image.base.name="docker.io/node:24-slim"
ENV \
    NEXT_PUBLIC_URL="http://localhost:3800" \
    PROJECT_ID_VERCEL="test" \
    AUTH_SECRET="build-time-placeholder-min-32-chars-long" \
    NEXT_PUBLIC_OPENPANEL_CLIENT_ID="test" \
    DATABASE_URL="http://libsql:8080" \
    PNPM_HOME="/pnpm" \
    PATH="$PNPM_HOME:$PATH" \
    UNKEY_API_ID="test" \
    OPENPANEL_CLIENT_SECRET="test" \
    SELF_HOST="true" \
    UPSTASH_REDIS_REST_URL="https://test.upstash.io" \
    RESEND_API_KEY="test" \
    DATABASE_AUTH_TOKEN="test" \
    VERCEL_AUTH_BEARER_TOKEN="test" \
    STRIPE_SECRET_KEY="test" \
    TINY_BIRD_API_KEY="test" \
    NODE_ENV="production" \
    CRON_SECRET="test" \
    TEAM_ID_VERCEL="test" \
    NEXT_PUBLIC_SELF_HOST="true" \
    UPSTASH_REDIS_REST_TOKEN="test" \
    UNKEY_TOKEN="test"
WORKDIR /app
COPY \
    --link \
    "." "/app/"
COPY \
    --from=install \
    --link \
    "/app/node_modules" "/app/node_modules"
COPY \
    --from=install \
    --link \
    "/app/apps/dashboard/node_modules" "/app/apps/dashboard/node_modules"
COPY \
    --from=install \
    --link \
    "/app/packages" "/app/packages"
RUN <<EOF
corepack enable pnpm
pnpm turbo run build --filter=@openstatus/dashboard
EOF

# runtime
FROM node@sha256:0e0ff40c39bc087845bfb27465a0df4ea419520094bc35842ff83dd8cbe6f9b6 AS runtime
LABEL \
    io.dofigen.version="2.8.0" \
    org.opencontainers.image.base.digest="sha256:0e0ff40c39bc087845bfb27465a0df4ea419520094bc35842ff83dd8cbe6f9b6" \
    org.opencontainers.image.base.name="docker.io/node:24-slim"
WORKDIR /app/apps/dashboard
COPY \
    --from=builder \
    --chown=1000:1000 \
    --chmod=555 \
    --link \
    "/app/apps/dashboard/.next/standalone/apps/dashboard/" "./"
COPY \
    --from=builder \
    --chown=1000:1000 \
    --link \
    "/app/node_modules/" "/app/node_modules/"
COPY \
    --from=builder \
    --chown=1000:1000 \
    --link \
    "/app/apps/dashboard/.next/static/" "./.next/static/"
COPY \
    --from=builder \
    --chown=1000:1000 \
    --link \
    "/app/apps/dashboard/public/" "./public/"
USER 0:0
RUN <<EOF
apt-get update
apt-get install -y --no-install-recommends curl
rm -rf /var/lib/apt/lists/*
EOF
USER 1000:1000
EXPOSE 3000
HEALTHCHECK \
    --interval=30s \
    --timeout=10s \
    --start-period=45s \
    --retries=3 \
    CMD curl -f http://localhost:3000/ || exit 1
CMD ["node", "server.js"]
