-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Optimize dockerfiles #113
Comments
Hey bro @Abbhiishek mind giving this a shot? |
sure |
Awesome bro! @Abbhiishek assigning this to you |
I have created a draft for web: # Alpine image
FROM node:20-alpine AS alpine
RUN apk update
RUN apk add --no-cache libc6-compat
# Setup pnpm and turbo on the alpine base
FROM alpine as base
RUN npm install pnpm turbo --global
RUN pnpm config set store-dir ~/.pnpm-store
# Prune projects
FROM base AS pruner
ARG PROJECT
WORKDIR /app
COPY . .
RUN turbo prune --scope=${PROJECT} --docker
# Build the project
FROM base AS builder
ARG PROJECT
WORKDIR /app
# Copy lockfile and package.json's of isolated subworkspace
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
COPY --from=pruner /app/out/json/ .
# First install the dependencies (as they change less often)
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm install --frozen-lockfile
# Copy source code of isolated subworkspace
COPY --from=pruner /app/out/full/ .
RUN turbo build --filter=${PROJECT}
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm prune --prod --no-optional
RUN rm -rf ./**/*/src
# Final image
FROM alpine AS runner
ARG PROJECT
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nodejs
USER nodejs
WORKDIR /app
COPY --from=builder --chown=nodejs:nodejs /app .
WORKDIR /app/apps/${PROJECT}
ARG PORT=3000
ENV PORT=${PORT}
ENV NODE_ENV=production
EXPOSE ${PORT}
CMD node dist/main
I am passing project as web for building the web micro however :( the below mentioned error occurred
|
@Abbhiishek Yeah actually you got a base very wrong :) You are using I think you can just build the project, and then copy over the dist to the main image. Without any deps or anything. Building and copying happens in the docker image not to mention |
ohhh my bad 🥲! i tried doing it traditionally but there was some path issues i will give it try once again |
Not an issue my friend! |
Hey bro @Abbhiishek made any further progress on this? |
hey i was able to dockerise but my application is not building correctly. Files are not imported to the container. Still working on this issue. Will keep you updated :) |
Wow that's strange, do drop in a thread on discord if you wanna discuss this! |
i am giving a try to use https://www.npmjs.com/package/@nx-tools/nx-container plugin. |
Hey bro, just hold up for a day or 2. We are migrating our project to Turbo. I believe it will be much more easier for you to do so once the migration is done! |
turbo 😀 |
sure |
@Abbhiishek hey bro! The migration is complete. You can start your work on this. |
@Abbhiishek yes since we now have turbo, every microservice now has its own package.json that has deps specific to that package. |
hey @rajdip-b i was able to contain web. |
Awesome bro!!! |
🎉 This issue has been resolved in version 1.3.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Description
Currently, the Dockerfiles for
web
andapi
are crossing 1GB size. We would like to reduce the final build size so that we get a significant lower build time in out CIs.The files are:
apps/api/Dockerfile
apps/web/Dockerfile
Things you can do:
The text was updated successfully, but these errors were encountered: