Dockerfile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Common base image
  2. FROM node:22-alpine AS common_base
  3. ARG UID=1000
  4. ARG GID=1000
  5. RUN deluser --remove-home node \
  6. && addgroup -S -g ${GID} musare \
  7. && adduser -SD -u ${UID} musare \
  8. && adduser musare musare
  9. RUN mkdir -p /opt/.git /opt/types /opt/app \
  10. && chown -R musare:musare /opt/app
  11. WORKDIR /opt/app
  12. USER musare
  13. # Server node modules
  14. FROM common_base AS server_node_modules
  15. COPY --chown=musare:musare --link server/package.json server/package-lock.json /opt/app/
  16. RUN npm install
  17. # Server build
  18. FROM common_base AS server_build
  19. ENV APP_ENV=production
  20. COPY --chown=musare:musare --link .git /opt/.git
  21. COPY --chown=musare:musare --link server /opt/app
  22. COPY --chown=musare:musare --link --from=server_node_modules /opt/app/node_modules node_modules
  23. RUN npm run compile
  24. # Server production image
  25. FROM common_base AS server
  26. COPY --from=server_build --link /opt/app /opt/app
  27. COPY --from=server_node_modules --link /opt/app/node_modules node_modules
  28. COPY --from=server_node_modules --link /opt/app/package.json /opt/app/package-lock.json /opt/app/
  29. ENTRYPOINT npm run migrate && npm run start
  30. EXPOSE 3030
  31. # Backend node modules
  32. FROM common_base AS backend_node_modules
  33. COPY --chown=musare:musare --link backend/package.json backend/package-lock.json /opt/app/
  34. RUN npm install
  35. # Backend production image
  36. FROM common_base AS backend
  37. ENV APP_ENV=production
  38. COPY --chown=musare:musare --link .git /opt/.git
  39. COPY --chown=musare:musare --link backend /opt/app
  40. COPY --chown=musare:musare --link --from=backend_node_modules /opt/app/node_modules node_modules
  41. ENTRYPOINT npm run prod
  42. EXPOSE 8080
  43. # Frontend node modules
  44. FROM common_base AS frontend_node_modules
  45. COPY --chown=musare:musare --link frontend/package.json frontend/package-lock.json /opt/app/
  46. RUN npm install
  47. # Frontend build
  48. FROM common_base AS frontend_build
  49. ARG FRONTEND_PROD_DEVTOOLS=false
  50. ARG MUSARE_SITENAME=Musare
  51. ARG MUSARE_PRIMARY_COLOR="#03a9f4"
  52. ARG MUSARE_DEBUG_VERSION=true
  53. ARG MUSARE_DEBUG_GIT_REMOTE=false
  54. ARG MUSARE_DEBUG_GIT_REMOTE_URL=false
  55. ARG MUSARE_DEBUG_GIT_BRANCH=true
  56. ARG MUSARE_DEBUG_GIT_LATEST_COMMIT=true
  57. ARG MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT=true
  58. ENV APP_ENV=production \
  59. FRONTEND_PROD_DEVTOOLS=${FRONTEND_PROD_DEVTOOLS} \
  60. MUSARE_SITENAME=${MUSARE_SITENAME} \
  61. MUSARE_PRIMARY_COLOR=${MUSARE_PRIMARY_COLOR} \
  62. MUSARE_DEBUG_VERSION=${MUSARE_DEBUG_VERSION} \
  63. MUSARE_DEBUG_GIT_REMOTE=${MUSARE_DEBUG_GIT_REMOTE} \
  64. MUSARE_DEBUG_GIT_REMOTE_URL=${MUSARE_DEBUG_GIT_REMOTE_URL} \
  65. MUSARE_DEBUG_GIT_BRANCH=${MUSARE_DEBUG_GIT_BRANCH} \
  66. MUSARE_DEBUG_GIT_LATEST_COMMIT=${MUSARE_DEBUG_GIT_LATEST_COMMIT} \
  67. MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT=${MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT}
  68. COPY --chown=musare:musare --link .git /opt/.git
  69. COPY --chown=musare:musare --link types /opt/types
  70. COPY --chown=musare:musare --link frontend /opt/app
  71. COPY --chown=musare:musare --from=frontend_node_modules --link /opt/app/node_modules node_modules
  72. RUN npm run prod
  73. # Frontend production image
  74. FROM nginx AS frontend
  75. COPY --chown=root:root --link frontend/nginx.prod.conf /etc/nginx/conf.d/default.conf
  76. COPY --from=frontend_build --chown=nginx:nginx --link /opt/app/build /usr/share/nginx/html
  77. EXPOSE 80