prod.Dockerfile 3.3 KB

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