Skip to content

Commit

Permalink
perf: #176 optimize api dockerfile for faster build time
Browse files Browse the repository at this point in the history
  • Loading branch information
kash2104 authored and rajdip-b committed Nov 14, 2024
1 parent 8e618ca commit 6d995f2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions apps/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,35 @@ ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

COPY --chown=root:root --chmod=755 package.json turbo.json pnpm-*.yaml ./
COPY --chown=root:root --chmod=755 apps/api/package.json apps/api/tsconfig.json apps/api/
COPY --chown=root:root --chmod=755 packages packages

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install --ignore-scripts --frozen-lockfile && \
rm -rf /root/.npm /root/.node-gyp /tmp/npm-*
pnpm install --ignore-scripts --frozen-lockfile && \
rm -rf /root/.npm /root/.node-gyp /tmp/npm-*

COPY --chown=root:root --chmod=755 packages packages
COPY --chown=root:root --chmod=755 apps/api/package.json apps/api/tsconfig.json apps/api/


COPY --chown=root:root --chmod=755 apps/api/src apps/api/src

RUN pnpm db:generate-types && \
pnpm build:api && \
pnpm sourcemaps:api

USER node
# USER node

FROM node:20-alpine AS prod

# Don't run production as root
USER node

ENV NODE_ENV=dev
ENV NODE_ENV=production

WORKDIR /app

COPY --chown=root:root --chmod=755 --from=build /app/node_modules /app/node_modules
COPY --chown=root:root --chmod=755 --from=build /app/apps/api/node_modules /app/apps/api/node_modules
COPY --chown=root:root --chmod=755 --from=build /app/apps/api/dist /app/apps/api/dist
# COPY --chown=root:root --chmod=755 --from=build /app/node_modules /app/node_modules
COPY --chown=node:node --chmod=755 --from=build /app/apps/api/node_modules /app/apps/api/node_modules
COPY --chown=node:node --chmod=755 --from=build /app/apps/api/dist /app/apps/api/dist

EXPOSE ${API_PORT}

Expand Down

0 comments on commit 6d995f2

Please sign in to comment.