prod.Dockerfile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. FROM node:18-alpine3.19 as base_builder
  2. WORKDIR /usr/src/app
  3. ENV HOPP_ALLOW_RUNTIME_ENV=true
  4. RUN npm install -g pnpm
  5. COPY pnpm-lock.yaml .
  6. RUN pnpm fetch
  7. COPY . .
  8. RUN pnpm install -f --offline
  9. FROM base_builder as backend
  10. RUN apk add caddy
  11. WORKDIR /usr/src/app/packages/hoppscotch-backend
  12. RUN pnpm exec prisma generate
  13. RUN pnpm run build
  14. COPY --from=base_builder /usr/src/app/packages/hoppscotch-backend/backend.Caddyfile /etc/caddy/backend.Caddyfile
  15. # Remove the env file to avoid backend copying it in and using it
  16. RUN rm "../../.env"
  17. ENV PRODUCTION="true"
  18. ENV PORT=8080
  19. ENV APP_PORT=${PORT}
  20. ENV DB_URL=${DATABASE_URL}
  21. CMD ["node", "/usr/src/app/packages/hoppscotch-backend/prod_run.mjs"]
  22. EXPOSE 80
  23. EXPOSE 3170
  24. FROM base_builder as fe_builder
  25. WORKDIR /usr/src/app/packages/hoppscotch-selfhost-web
  26. RUN pnpm run generate
  27. FROM caddy:2-alpine as app
  28. WORKDIR /site
  29. COPY --from=fe_builder /usr/src/app/packages/hoppscotch-selfhost-web/prod_run.mjs /usr
  30. COPY --from=fe_builder /usr/src/app/packages/hoppscotch-selfhost-web/selfhost-web.Caddyfile /etc/caddy/selfhost-web.Caddyfile
  31. COPY --from=fe_builder /usr/src/app/packages/hoppscotch-selfhost-web/dist/ .
  32. RUN apk add nodejs npm
  33. RUN npm install -g @import-meta-env/cli
  34. EXPOSE 80
  35. EXPOSE 3000
  36. CMD ["/bin/sh", "-c", "node /usr/prod_run.mjs && caddy run --config /etc/caddy/selfhost-web.Caddyfile --adapter caddyfile"]
  37. FROM base_builder as sh_admin_builder
  38. WORKDIR /usr/src/app/packages/hoppscotch-sh-admin
  39. # Generate two builds for `sh-admin`, one based on subpath-access and the regular build
  40. RUN pnpm run build --outDir dist-multiport-setup
  41. RUN pnpm run build --outDir dist-subpath-access --base /admin/
  42. FROM caddy:2-alpine as sh_admin
  43. WORKDIR /site
  44. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/prod_run.mjs /usr
  45. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/sh-admin-multiport-setup.Caddyfile /etc/caddy/sh-admin-multiport-setup.Caddyfile
  46. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/sh-admin-subpath-access.Caddyfile /etc/caddy/sh-admin-subpath-access.Caddyfile
  47. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/dist-multiport-setup /site/sh-admin-multiport-setup
  48. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/dist-subpath-access /site/sh-admin-subpath-access
  49. RUN apk add nodejs npm
  50. RUN npm install -g @import-meta-env/cli
  51. EXPOSE 80
  52. EXPOSE 3100
  53. CMD ["node","/usr/prod_run.mjs"]
  54. FROM backend as aio
  55. RUN apk add caddy tini
  56. RUN npm install -g @import-meta-env/cli
  57. COPY --from=fe_builder /usr/src/app/packages/hoppscotch-selfhost-web/dist /site/selfhost-web
  58. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/dist-multiport-setup /site/sh-admin-multiport-setup
  59. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/dist-subpath-access /site/sh-admin-subpath-access
  60. COPY aio-multiport-setup.Caddyfile /etc/caddy/aio-multiport-setup.Caddyfile
  61. COPY aio-subpath-access.Caddyfile /etc/caddy/aio-subpath-access.Caddyfile
  62. ENTRYPOINT [ "tini", "--" ]
  63. RUN apk --no-cache add curl
  64. COPY --chmod=755 healthcheck.sh .
  65. HEALTHCHECK --interval=2s CMD /bin/sh ./healthcheck.sh
  66. CMD ["node", "/usr/src/app/aio_run.mjs"]
  67. EXPOSE 3170
  68. EXPOSE 3000
  69. EXPOSE 3100
  70. EXPOSE 80