|
| 1 | +# Base image for common dependencies |
| 2 | +FROM node:18.17.1-alpine as common-deps |
| 3 | + |
| 4 | +WORKDIR /app |
| 5 | + |
| 6 | +# Copy only the necessary files for dependency resolution |
| 7 | +COPY ./package.json ./yarn.lock ./.yarnrc.yml ./tsconfig.base.json ./nx.json /app/ |
| 8 | +COPY ./.yarn/releases /app/.yarn/releases |
| 9 | + |
| 10 | +COPY ./packages/twenty-emails/package.json /app/packages/twenty-emails/ |
| 11 | +COPY ./packages/twenty-server/package.json /app/packages/twenty-server/ |
| 12 | +COPY ./packages/twenty-server/patches /app/packages/twenty-server/patches |
| 13 | +COPY ./packages/twenty-ui/package.json /app/packages/twenty-ui/ |
| 14 | +COPY ./packages/twenty-front/package.json /app/packages/twenty-front/ |
| 15 | + |
| 16 | +# Install all dependencies |
| 17 | +RUN yarn && yarn cache clean && npx nx reset |
| 18 | + |
| 19 | + |
| 20 | +# Build the back |
| 21 | +FROM common-deps as twenty-server-build |
| 22 | + |
| 23 | +# Copy sourcecode after installing dependences to accelerate subsequents builds |
| 24 | +COPY ./packages/twenty-emails /app/packages/twenty-emails |
| 25 | +COPY ./packages/twenty-server /app/packages/twenty-server |
| 26 | + |
| 27 | +RUN npx nx run twenty-server:build && \ |
| 28 | + mv /app/packages/twenty-server/dist /app/packages/twenty-server/build && \ |
| 29 | + npx nx run twenty-server:build:packageJson && \ |
| 30 | + mv /app/packages/twenty-server/dist/package.json /app/packages/twenty-server/package.json && \ |
| 31 | + rm -rf /app/packages/twenty-server/dist && \ |
| 32 | + mv /app/packages/twenty-server/build /app/packages/twenty-server/dist |
| 33 | + |
| 34 | +RUN yarn workspaces focus --production twenty-emails twenty-server |
| 35 | + |
| 36 | + |
| 37 | +# Build the front |
| 38 | +FROM common-deps as twenty-front-build |
| 39 | + |
| 40 | +ARG REACT_APP_SERVER_BASE_URL |
| 41 | + |
| 42 | +COPY ./packages/twenty-front /app/packages/twenty-front |
| 43 | +COPY ./packages/twenty-ui /app/packages/twenty-ui |
| 44 | +RUN yarn nx build twenty-front |
| 45 | + |
| 46 | + |
| 47 | +# Final stage: Run the application |
| 48 | +FROM node:18.17.1-alpine as twenty |
| 49 | + |
| 50 | +# Used to run healthcheck in docker |
| 51 | +RUN apk add --no-cache curl jq |
| 52 | + |
| 53 | +COPY ./packages/twenty-docker/prod/twenty/entrypoint.sh /app/entrypoint.sh |
| 54 | +RUN chmod +x /app/entrypoint.sh |
| 55 | + |
| 56 | +WORKDIR /app/packages/twenty-server |
| 57 | + |
| 58 | +ARG REACT_APP_SERVER_BASE_URL |
| 59 | +ENV REACT_APP_SERVER_BASE_URL $REACT_APP_SERVER_BASE_URL |
| 60 | + |
| 61 | +# Copy built applications from previous stages |
| 62 | +COPY --chown=1000 --from=twenty-server-build /app /app |
| 63 | +COPY --chown=1000 --from=twenty-server-build /app/packages/twenty-server /app/packages/twenty-server |
| 64 | +COPY --chown=1000 --from=twenty-front-build /app/packages/twenty-front/build /app/packages/twenty-server/dist/front |
| 65 | + |
| 66 | +# Set metadata and labels |
| 67 | +LABEL org.opencontainers.image.source=https://github.com/twentyhq/twenty |
| 68 | +LABEL org.opencontainers.image.description="This image provides a consistent and reproducible environment for the backend and frontend, ensuring it deploys faster and runs the same way regardless of the deployment environment." |
| 69 | + |
| 70 | +RUN mkdir /app/.local-storage |
| 71 | +RUN chown -R 1000 /app |
| 72 | + |
| 73 | +# Use non root user with uid 1000 |
| 74 | +USER 1000 |
| 75 | + |
| 76 | +CMD ["node", "dist/src/main"] |
| 77 | +ENTRYPOINT ["/app/entrypoint.sh"] |
0 commit comments