content: ARG CADDY_VERSION=2.8.4
  ARG NODE_VERSION=20.19.5
  FROM node:${NODE_VERSION}-slim AS base
  
  ENV PNPM_HOME="/pnpm"
  ENV PATH="$PNPM_HOME:$PATH"
  
  RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
      --mount=type=cache,target=/var/lib/apt,sharing=locked \
      apt-get update \
   && apt-get install -y --no-install-recommends \
          curl \
          git
  
  ARG COREPACK_VERSION=0.31.0
  ARG PNPM_VERSION=9.11.0
  ENV PNPM_HOME="/pnpm"
  ENV PATH="$PNPM_HOME:$PATH"
  RUN npm install -g corepack@${COREPACK_VERSION} \
   && corepack enable \
   && mkdir -p /app $PNPM_HOME \
   && chown node /app $PNPM_HOME \
   && runuser --login node --command="corepack install --global pnpm@${PNPM_VERSION}"
  
  WORKDIR /app
  COPY package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.base.json ./
  COPY ./shared/package.json ./shared/
  COPY ./ui/package.json ./ui/
  RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
      pnpm install --frozen-lockfile
  
  COPY ./ui ./ui
  COPY ./shared ./shared
  # The UI references a type from ./server as part of its usage of trpc.
  # esbuild doesn't type-check so, strictly speaking, we don't need the type here.
  # However, esbuild would complain about the broken tsconfig.json reference, so we add server's tsconfig.json here.
  COPY server/tsconfig.json ./server/
  
  WORKDIR /app/ui
  
  ARG VITE_API_URL=http://server:4001
  ARG VITE_AUTH0_AUDIENCE=
  ARG VITE_AUTH0_CLIENT_ID=
  ARG VITE_AUTH0_DOMAIN=
  ARG VITE_COMMIT_ID=n/a
  ARG VITE_GITHUB_AGENT_ORG=poking-agents
  ARG VITE_IS_READ_ONLY=false
  ARG VITE_NODE_ENV=development
  ARG VITE_SENTRY_DSN=
  ARG VITE_SENTRY_ENVIRONMENT=
  ARG VITE_TASK_REPO_HTTPS_HOST=https://github.com
  ARG VITE_USE_AUTH0=false
  
  FROM base AS build
  RUN pnpm exec vite build
  
  FROM base AS dev
  ENV VITE_API_URL=${VITE_API_URL}
  ENV VITE_AUTH0_AUDIENCE=${VITE_AUTH0_AUDIENCE}
  ENV VITE_AUTH0_CLIENT_ID=${VITE_AUTH0_CLIENT_ID}
  ENV VITE_AUTH0_DOMAIN=${VITE_AUTH0_DOMAIN}
  ENV VITE_COMMIT_ID=${VITE_COMMIT_ID}
  ENV VITE_GITHUB_AGENT_ORG=${VITE_GITHUB_AGENT_ORG}
  ENV VITE_IS_READ_ONLY=${VITE_IS_READ_ONLY}
  ENV VITE_NODE_ENV=${VITE_NODE_ENV}
  ENV VITE_SENTRY_DSN=${VITE_SENTRY_DSN}
  ENV VITE_SENTRY_ENVIRONMENT=${VITE_SENTRY_ENVIRONMENT}
  ENV VITE_TASK_REPO_HTTPS_HOST=${VITE_TASK_REPO_HTTPS_HOST}
  ENV VITE_USE_AUTH0=${VITE_USE_AUTH0}
  USER node
  ENTRYPOINT ["pnpm", "vite", "--no-open", "--host"]
  
  
  FROM caddy:${CADDY_VERSION} AS prod
  RUN apk add --no-cache curl
  
  COPY --from=build /app/builds/ui /srv
  RUN cat <<'EOF' > /etc/caddy/Caddyfile
  {$VIVARIA_UI_HOSTNAME} {
      handle /api/* {
          uri strip_prefix /api
          reverse_proxy {$VIVARIA_API_URL}
          encode gzip
      }
  
      handle {
          root * /srv
          file_server
          encode gzip
      }
  }
  EOF
  