prod.Dockerfile 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_builder
  12. WORKDIR /usr/src/app/packages/hoppscotch-backend
  13. RUN pnpm exec prisma generate
  14. RUN pnpm run build
  15. RUN pnpm --filter=hoppscotch-backend deploy /dist/backend --prod
  16. WORKDIR /dist/backend
  17. RUN pnpm exec prisma generate
  18. FROM node:20-alpine3.19 AS backend
  19. RUN apk add caddy
  20. RUN npm install -g pnpm
  21. COPY --from=base_builder /usr/src/app/packages/hoppscotch-backend/backend.Caddyfile /etc/caddy/backend.Caddyfile
  22. COPY --from=backend_builder /dist/backend /dist/backend
  23. COPY --from=base_builder /usr/src/app/packages/hoppscotch-backend/prod_run.mjs /dist/backend
  24. # Remove the env file to avoid backend copying it in and using it
  25. ENV PRODUCTION="true"
  26. ENV PORT=8080
  27. ENV APP_PORT=${PORT}
  28. ENV DB_URL=${DATABASE_URL}
  29. WORKDIR /dist/backend
  30. CMD ["node", "prod_run.mjs"]
  31. EXPOSE 80
  32. EXPOSE 3170
  33. FROM base_builder AS fe_builder
  34. WORKDIR /usr/src/app/packages/hoppscotch-selfhost-web
  35. RUN pnpm run generate
  36. FROM caddy:2-alpine AS app
  37. COPY --from=fe_builder /usr/src/app/packages/hoppscotch-selfhost-web/prod_run.mjs /site/prod_run.mjs
  38. COPY --from=fe_builder /usr/src/app/packages/hoppscotch-selfhost-web/selfhost-web.Caddyfile /etc/caddy/selfhost-web.Caddyfile
  39. COPY --from=fe_builder /usr/src/app/packages/hoppscotch-selfhost-web/dist/ /site/selfhost-web
  40. RUN apk add nodejs npm
  41. RUN npm install -g @import-meta-env/cli
  42. EXPOSE 80
  43. EXPOSE 3000
  44. WORKDIR /site
  45. CMD ["/bin/sh", "-c", "node /site/prod_run.mjs && caddy run --config /etc/caddy/selfhost-web.Caddyfile --adapter caddyfile"]
  46. FROM base_builder AS sh_admin_builder
  47. WORKDIR /usr/src/app/packages/hoppscotch-sh-admin
  48. # Generate two builds for `sh-admin`, one based on subpath-access and the regular build
  49. RUN pnpm run build --outDir dist-multiport-setup
  50. RUN pnpm run build --outDir dist-subpath-access --base /admin/
  51. FROM caddy:2-alpine AS sh_admin
  52. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/prod_run.mjs /site/prod_run.mjs
  53. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/sh-admin-multiport-setup.Caddyfile /etc/caddy/sh-admin-multiport-setup.Caddyfile
  54. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/sh-admin-subpath-access.Caddyfile /etc/caddy/sh-admin-subpath-access.Caddyfile
  55. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/dist-multiport-setup /site/sh-admin-multiport-setup
  56. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/dist-subpath-access /site/sh-admin-subpath-access
  57. RUN apk add nodejs npm
  58. RUN npm install -g @import-meta-env/cli
  59. EXPOSE 80
  60. EXPOSE 3100
  61. WORKDIR /site
  62. CMD ["node","/site/prod_run.mjs"]
  63. FROM node:20-alpine3.19 AS aio
  64. ENV PRODUCTION="true"
  65. ENV PORT=8080
  66. ENV APP_PORT=${PORT}
  67. ENV DB_URL=${DATABASE_URL}
  68. # Open Containers Initiative (OCI) labels - useful for bots like Renovate
  69. LABEL org.opencontainers.image.source="https://github.com/hoppscotch/hoppscotch" \
  70. org.opencontainers.image.url="https://docs.hoppscotch.io" \
  71. org.opencontainers.image.licenses="MIT"
  72. # Run this separately to use the cache from backend
  73. RUN apk add caddy
  74. RUN apk add tini curl
  75. RUN npm install -g pnpm
  76. # Copy necessary files
  77. # Backend files
  78. COPY --from=base_builder /usr/src/app/packages/hoppscotch-backend/backend.Caddyfile /etc/caddy/backend.Caddyfile
  79. COPY --from=backend_builder /dist/backend /dist/backend
  80. COPY --from=base_builder /usr/src/app/packages/hoppscotch-backend/prod_run.mjs /dist/backend
  81. # FE Files
  82. COPY --from=base_builder /usr/src/app/aio_run.mjs /usr/src/app/aio_run.mjs
  83. COPY --from=fe_builder /usr/src/app/packages/hoppscotch-selfhost-web/dist /site/selfhost-web
  84. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/dist-multiport-setup /site/sh-admin-multiport-setup
  85. COPY --from=sh_admin_builder /usr/src/app/packages/hoppscotch-sh-admin/dist-subpath-access /site/sh-admin-subpath-access
  86. COPY aio-multiport-setup.Caddyfile /etc/caddy/aio-multiport-setup.Caddyfile
  87. COPY aio-subpath-access.Caddyfile /etc/caddy/aio-subpath-access.Caddyfile
  88. RUN npm install -g @import-meta-env/cli
  89. ENTRYPOINT [ "tini", "--" ]
  90. COPY --chmod=755 healthcheck.sh /
  91. HEALTHCHECK --interval=2s CMD /bin/sh /healthcheck.sh
  92. WORKDIR /dist/backend
  93. CMD ["node", "/usr/src/app/aio_run.mjs"]
  94. # NOTE: Although these ports are exposed, the HOPP_ALTERNATE_AIO_PORT variable can be used to assign a user-specified port
  95. EXPOSE 3170
  96. EXPOSE 3000
  97. EXPOSE 3100
  98. EXPOSE 80