Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Optimized the API Dockerfile for better build time. #527

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions apps/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,37 @@ 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 apps/api/package.json apps/api/tsconfig.json /app

COPY --chown=root:root --chmod=755 packages packages

# Install dependencies using pnpm with cache mount
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 apps/api/src apps/api/src
COPY --chown=root:root --chmod=755 apps/api/src /app/src

RUN pnpm db:generate-types && \
pnpm build:api && \
pnpm sourcemaps:api
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=node:node --chmod=755 --from=build /app/node_modules /app/node_modules

COPY --chown=node:node --chmod=755 --from=build /app/dist /app/dist

EXPOSE ${API_PORT}

ENTRYPOINT ["node", "/app/apps/api/dist/main.js"]
ENTRYPOINT ["node", "/app/dist/main.js"]
Loading