prod.Dockerfile 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. RUN addgroup -S hoppgroup && adduser -S hoppuser -G hoppgroup
  22. COPY --from=base_builder /usr/src/app/packages/hoppscotch-backend/backend.Caddyfile /etc/caddy/backend.Caddyfile
  23. COPY --from=backend_builder --chown=hoppuser:hoppgroup --chmod=755 /dist/backend /dist/backend
  24. COPY --from=base_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-backend/prod_run.mjs /dist/backend
  25. # Remove the env file to avoid backend copying it in and using it
  26. ENV PRODUCTION="true"
  27. ENV PORT=8080
  28. ENV APP_PORT=${PORT}
  29. ENV DB_URL=${DATABASE_URL}
  30. USER hoppuser
  31. WORKDIR /dist/backend
  32. CMD ["node", "prod_run.mjs"]
  33. EXPOSE 80
  34. EXPOSE 3170
  35. FROM base_builder AS fe_builder
  36. WORKDIR /usr/src/app/packages/hoppscotch-selfhost-web
  37. RUN pnpm run generate
  38. FROM caddy:2-alpine AS app
  39. RUN addgroup -S hoppgroup && adduser -S hoppuser -G hoppgroup
  40. COPY --from=fe_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-selfhost-web/prod_run.mjs /site/prod_run.mjs
  41. COPY --from=fe_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-selfhost-web/selfhost-web.Caddyfile /etc/caddy/selfhost-web.Caddyfile
  42. COPY --from=fe_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-selfhost-web/dist/ /site/selfhost-web
  43. RUN apk add nodejs npm
  44. RUN npm install -g @import-meta-env/cli
  45. USER hoppuser
  46. EXPOSE 80
  47. EXPOSE 3000
  48. WORKDIR /site
  49. CMD ["/bin/sh", "-c", "node /site/prod_run.mjs && caddy run --config /etc/caddy/selfhost-web.Caddyfile --adapter caddyfile"]
  50. FROM base_builder AS sh_admin_builder
  51. WORKDIR /usr/src/app/packages/hoppscotch-sh-admin
  52. # Generate two builds for `sh-admin`, one based on subpath-access and the regular build
  53. RUN pnpm run build --outDir dist-multiport-setup
  54. RUN pnpm run build --outDir dist-subpath-access --base /admin/
  55. FROM caddy:2-alpine AS sh_admin
  56. RUN addgroup -S hoppgroup && adduser -S hoppuser -G hoppgroup
  57. COPY --from=sh_admin_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-sh-admin/prod_run.mjs /site/prod_run.mjs
  58. COPY --from=sh_admin_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-sh-admin/sh-admin-multiport-setup.Caddyfile /etc/caddy/sh-admin-multiport-setup.Caddyfile
  59. COPY --from=sh_admin_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-sh-admin/sh-admin-subpath-access.Caddyfile /etc/caddy/sh-admin-subpath-access.Caddyfile
  60. COPY --from=sh_admin_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-sh-admin/dist-multiport-setup /site/sh-admin-multiport-setup
  61. COPY --from=sh_admin_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-sh-admin/dist-subpath-access /site/sh-admin-subpath-access
  62. RUN apk add nodejs npm
  63. RUN npm install -g @import-meta-env/cli
  64. USER hoppuser
  65. EXPOSE 80
  66. EXPOSE 3100
  67. WORKDIR /site
  68. CMD ["node","/site/prod_run.mjs"]
  69. FROM node:20-alpine3.19 AS aio
  70. ENV PRODUCTION="true"
  71. ENV PORT=8080
  72. ENV APP_PORT=${PORT}
  73. ENV DB_URL=${DATABASE_URL}
  74. # Run this separately to use the cache from backend
  75. RUN apk add caddy
  76. RUN apk add tini curl
  77. RUN npm install -g pnpm
  78. RUN addgroup -S hoppgroup && adduser -S hoppuser -G hoppgroup
  79. # Copy necessary files
  80. # Backend files
  81. COPY --from=base_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-backend/backend.Caddyfile /etc/caddy/backend.Caddyfile
  82. COPY --from=backend_builder --chown=hoppuser:hoppgroup --chmod=755 /dist/backend /dist/backend
  83. COPY --from=base_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-backend/prod_run.mjs /dist/backend
  84. # FE Files
  85. COPY --from=base_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/aio_run.mjs /usr/src/app/aio_run.mjs
  86. COPY --from=fe_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-selfhost-web/dist /site/selfhost-web
  87. COPY --from=sh_admin_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-sh-admin/dist-multiport-setup /site/sh-admin-multiport-setup
  88. COPY --from=sh_admin_builder --chown=hoppuser:hoppgroup --chmod=755 /usr/src/app/packages/hoppscotch-sh-admin/dist-subpath-access /site/sh-admin-subpath-access
  89. COPY aio-multiport-setup.Caddyfile /etc/caddy/aio-multiport-setup.Caddyfile
  90. COPY aio-subpath-access.Caddyfile /etc/caddy/aio-subpath-access.Caddyfile
  91. RUN npm install -g @import-meta-env/cli
  92. USER hoppuser
  93. ENTRYPOINT [ "tini", "--" ]
  94. COPY --chmod=755 healthcheck.sh .
  95. HEALTHCHECK --interval=2s CMD /bin/sh ./healthcheck.sh
  96. WORKDIR /dist/backend
  97. CMD ["node", "/usr/src/app/aio_run.mjs"]
  98. EXPOSE 3170
  99. EXPOSE 3000
  100. EXPOSE 3100
  101. EXPOSE 80