prod.Dockerfile 3.2 KB

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