Dockerfile 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Common base image
  2. FROM node:20-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/app \
  10. && chown -R musare:musare /opt/app
  11. WORKDIR /opt/app
  12. USER musare
  13. # Backend node modules
  14. FROM common_base AS backend_node_modules
  15. COPY --chown=musare:musare --link backend/package.json backend/package-lock.json /opt/app/
  16. RUN npm install
  17. # Backend build
  18. FROM common_base AS backend_build
  19. ENV APP_ENV=production
  20. COPY --chown=musare:musare --link .git /opt/.git
  21. COPY --chown=musare:musare --link common /opt/common
  22. COPY --chown=musare:musare --link types /opt/types
  23. COPY --chown=musare:musare --link backend /opt/app
  24. COPY --chown=musare:musare --link --from=backend_node_modules /opt/app/node_modules node_modules
  25. RUN npm run build
  26. # Backend production image
  27. FROM common_base AS backend
  28. COPY --from=backend_build --link /opt/app/build build
  29. COPY --from=backend_node_modules --link /opt/app/node_modules node_modules
  30. COPY --from=backend_node_modules --link /opt/app/package.json /opt/app/package-lock.json /opt/app/
  31. ENTRYPOINT npm run prod
  32. # Frontend node modules
  33. FROM common_base AS frontend_node_modules
  34. COPY --chown=musare:musare --link frontend/package.json frontend/package-lock.json /opt/app/
  35. RUN npm install
  36. # Frontend build
  37. FROM common_base AS frontend_build
  38. ARG FRONTEND_PROD_DEVTOOLS=false
  39. ARG MUSARE_SITENAME=Musare
  40. ARG MUSARE_PRIMARY_COLOR="#03a9f4"
  41. ARG MUSARE_DEBUG_VERSION=true
  42. ARG MUSARE_DEBUG_GIT_REMOTE=false
  43. ARG MUSARE_DEBUG_GIT_REMOTE_URL=false
  44. ARG MUSARE_DEBUG_GIT_BRANCH=true
  45. ARG MUSARE_DEBUG_GIT_LATEST_COMMIT=true
  46. ARG MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT=true
  47. ENV APP_ENV=production \
  48. FRONTEND_PROD_DEVTOOLS=${FRONTEND_PROD_DEVTOOLS} \
  49. MUSARE_SITENAME=${MUSARE_SITENAME} \
  50. MUSARE_PRIMARY_COLOR=${MUSARE_PRIMARY_COLOR} \
  51. MUSARE_DEBUG_VERSION=${MUSARE_DEBUG_VERSION} \
  52. MUSARE_DEBUG_GIT_REMOTE=${MUSARE_DEBUG_GIT_REMOTE} \
  53. MUSARE_DEBUG_GIT_REMOTE_URL=${MUSARE_DEBUG_GIT_REMOTE_URL} \
  54. MUSARE_DEBUG_GIT_BRANCH=${MUSARE_DEBUG_GIT_BRANCH} \
  55. MUSARE_DEBUG_GIT_LATEST_COMMIT=${MUSARE_DEBUG_GIT_LATEST_COMMIT} \
  56. MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT=${MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT}
  57. COPY --chown=musare:musare --link .git /opt/.git
  58. COPY --chown=musare:musare --link common /opt/common
  59. COPY --chown=musare:musare --link types /opt/types
  60. COPY --chown=musare:musare --link frontend /opt/app
  61. COPY --chown=musare:musare --from=frontend_node_modules --link /opt/app/node_modules node_modules
  62. RUN npm run prod
  63. # Frontend production image
  64. FROM nginx AS frontend
  65. COPY --chown=root:root --link frontend/nginx.prod.conf /etc/nginx/conf.d/default.conf
  66. COPY --from=frontend_build --chown=nginx:nginx --link /opt/app/build /usr/share/nginx/html