prod.Dockerfile 6.4 KB

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