# gitzone dockerfile_service
## STAGE 1 // BUILD
FROM code.foss.global/host.today/ht-docker-node:lts AS build

WORKDIR /app

COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile

COPY . ./
RUN pnpm run build
RUN pnpm prune --prod

## STAGE 2 // PRODUCTION
FROM code.foss.global/host.today/ht-docker-node:lts AS production

WORKDIR /app

ENV NODE_ENV=production
ENV SERVEZONE_PORT=80

COPY --from=build /app/package.json ./package.json
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/cli.js ./cli.js
COPY --from=build /app/dist_ts ./dist_ts
COPY --from=build /app/dist_serve ./dist_serve

LABEL org.opencontainers.image.title="cloudly" \
      org.opencontainers.image.description="serve.zone control plane" \
      org.opencontainers.image.source="https://code.foss.global/serve.zone/cloudly"

HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 CMD node -e "const http=require('node:http');const port=process.env.SERVEZONE_PORT||80;const req=http.get({host:'127.0.0.1',port,path:'/'},res=>process.exit(res.statusCode<500?0:1));req.on('error',()=>process.exit(1));req.setTimeout(5000,()=>{req.destroy();process.exit(1);});"

EXPOSE 80
CMD ["node", "cli.js"]
