Dockerfile 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. # 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 production image
  18. FROM common_base AS backend
  19. ENV APP_ENV=production
  20. COPY --chown=musare:musare --link .git /opt/.git
  21. COPY --chown=musare:musare --link backend /opt/app
  22. COPY --chown=musare:musare --link --from=backend_node_modules /opt/app/node_modules node_modules
  23. ENTRYPOINT npm run prod
  24. EXPOSE 8080
  25. # Frontend node modules
  26. FROM common_base AS frontend_node_modules
  27. COPY --chown=musare:musare --link frontend/package.json frontend/package-lock.json /opt/app/
  28. RUN npm install
  29. # Frontend build
  30. FROM common_base AS frontend_build
  31. ARG FRONTEND_PROD_DEVTOOLS=false
  32. ARG MUSARE_SITENAME=Musare
  33. ARG MUSARE_PRIMARY_COLOR="#03a9f4"
  34. ARG MUSARE_DEBUG_VERSION=true
  35. ARG MUSARE_DEBUG_GIT_REMOTE=false
  36. ARG MUSARE_DEBUG_GIT_REMOTE_URL=false
  37. ARG MUSARE_DEBUG_GIT_BRANCH=true
  38. ARG MUSARE_DEBUG_GIT_LATEST_COMMIT=true
  39. ARG MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT=true
  40. ENV APP_ENV=production \
  41. FRONTEND_PROD_DEVTOOLS=${FRONTEND_PROD_DEVTOOLS} \
  42. MUSARE_SITENAME=${MUSARE_SITENAME} \
  43. MUSARE_PRIMARY_COLOR=${MUSARE_PRIMARY_COLOR} \
  44. MUSARE_DEBUG_VERSION=${MUSARE_DEBUG_VERSION} \
  45. MUSARE_DEBUG_GIT_REMOTE=${MUSARE_DEBUG_GIT_REMOTE} \
  46. MUSARE_DEBUG_GIT_REMOTE_URL=${MUSARE_DEBUG_GIT_REMOTE_URL} \
  47. MUSARE_DEBUG_GIT_BRANCH=${MUSARE_DEBUG_GIT_BRANCH} \
  48. MUSARE_DEBUG_GIT_LATEST_COMMIT=${MUSARE_DEBUG_GIT_LATEST_COMMIT} \
  49. MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT=${MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT}
  50. COPY --chown=musare:musare --link .git /opt/.git
  51. COPY --chown=musare:musare --link types /opt/types
  52. COPY --chown=musare:musare --link frontend /opt/app
  53. COPY --chown=musare:musare --from=frontend_node_modules --link /opt/app/node_modules node_modules
  54. RUN npm run prod
  55. # Frontend production image
  56. FROM nginx AS frontend
  57. COPY --chown=root:root --link frontend/nginx.prod.conf /etc/nginx/conf.d/default.conf
  58. COPY --from=frontend_build --chown=nginx:nginx --link /opt/app/build /usr/share/nginx/html
  59. EXPOSE 80