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

Good docker image for production? (remove source code) #5

Open
AlexandrosMelissas opened this issue Mar 14, 2023 · 0 comments
Open

Comments

@AlexandrosMelissas
Copy link

AlexandrosMelissas commented Mar 14, 2023

Hello. I have noticed you haven't removed the source code for minimum image size. Here is my Dockerfile, do you think the find command is a good idea? Also, how would you go about removing source after building them to js from package dependencies or app dependencies in "packages" folder or "apps" folder?

FROM node:18-alpine as deps
RUN apk add --no-cache libc6-compat
RUN apk update

RUN npm i -g turbo pnpm

FROM node:18-alpine As base
RUN apk add --no-cache libc6-compat

RUN apk update

RUN npm i -g turbo 

WORKDIR /app

COPY . .

RUN turbo prune --scope=api --docker

FROM deps as development

WORKDIR /app

# First install the dependencies (as they change less often)
COPY .gitignore .gitignore
COPY turbo.json turbo.json
COPY --from=base /app/out/json/ .
COPY --from=base /app/out/pnpm-lock.yaml ./pnpm-lock.yaml

RUN pnpm install 

# # Build the project
COPY --from=base /app/out/full/ .

CMD ["turbo", "dev"]


FROM deps as builder

WORKDIR /app

COPY --from=development --chown=node:node /app .

RUN pnpm turbo run build --filter=api... 

RUN pnpm install --prod

WORKDIR /app/apps/api

RUN find . ! -name dist ! -name node_modules ! -name .env -maxdepth 1 -mindepth 1 -exec rm -rf {} +

FROM node:18-alpine As production

WORKDIR /app

COPY --chown=node:node --from=builder /app .

WORKDIR /app/apps/api

CMD [ "node", "./dist/src/main.js" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant