prod.Dockerfile 5.4 KB

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