Dockerfile 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. EXPOSE 8080
  33. # Frontend node modules
  34. FROM common_base AS frontend_node_modules
  35. COPY --chown=musare:musare --link frontend/package.json frontend/package-lock.json /opt/app/
  36. RUN npm install
  37. # Frontend build
  38. FROM common_base AS frontend_build
  39. ARG FRONTEND_PROD_DEVTOOLS=false
  40. ARG MUSARE_SITENAME=Musare
  41. ARG MUSARE_PRIMARY_COLOR="#03a9f4"
  42. ARG MUSARE_DEBUG_VERSION=true
  43. ARG MUSARE_DEBUG_GIT_REMOTE=false
  44. ARG MUSARE_DEBUG_GIT_REMOTE_URL=false
  45. ARG MUSARE_DEBUG_GIT_BRANCH=true
  46. ARG MUSARE_DEBUG_GIT_LATEST_COMMIT=true
  47. ARG MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT=true
  48. ENV APP_ENV=production \
  49. FRONTEND_PROD_DEVTOOLS=${FRONTEND_PROD_DEVTOOLS} \
  50. MUSARE_SITENAME=${MUSARE_SITENAME} \
  51. MUSARE_PRIMARY_COLOR=${MUSARE_PRIMARY_COLOR} \
  52. MUSARE_DEBUG_VERSION=${MUSARE_DEBUG_VERSION} \
  53. MUSARE_DEBUG_GIT_REMOTE=${MUSARE_DEBUG_GIT_REMOTE} \
  54. MUSARE_DEBUG_GIT_REMOTE_URL=${MUSARE_DEBUG_GIT_REMOTE_URL} \
  55. MUSARE_DEBUG_GIT_BRANCH=${MUSARE_DEBUG_GIT_BRANCH} \
  56. MUSARE_DEBUG_GIT_LATEST_COMMIT=${MUSARE_DEBUG_GIT_LATEST_COMMIT} \
  57. MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT=${MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT}
  58. COPY --chown=musare:musare --link .git /opt/.git
  59. COPY --chown=musare:musare --link common /opt/common
  60. COPY --chown=musare:musare --link types /opt/types
  61. COPY --chown=musare:musare --link frontend /opt/app
  62. COPY --chown=musare:musare --from=frontend_node_modules --link /opt/app/node_modules node_modules
  63. RUN npm run prod
  64. # Frontend production image
  65. FROM nginx AS frontend
  66. COPY --chown=root:root --link frontend/nginx.prod.conf /etc/nginx/conf.d/default.conf
  67. COPY --from=frontend_build --chown=nginx:nginx --link /opt/app/build /usr/share/nginx/html
  68. EXPOSE 80