chore: optimize dockerfile to speed up building and reduce docker image size (#520)
This commit is contained in:
parent
b288cd612e
commit
6cd16826fd
56
Dockerfile
56
Dockerfile
|
@ -1,28 +1,56 @@
|
||||||
# build front-end
|
# build front-end
|
||||||
FROM node:lts-alpine AS builder
|
FROM node:lts-alpine AS frontend
|
||||||
|
|
||||||
|
RUN npm install pnpm -g
|
||||||
|
|
||||||
COPY ./ /app
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apk add --no-cache git \
|
COPY ./package.json /app
|
||||||
&& npm install pnpm -g \
|
|
||||||
&& pnpm install \
|
COPY ./pnpm-lock.yaml /app
|
||||||
&& pnpm run build \
|
|
||||||
&& rm -rf /root/.npm /root/.pnpm-store /usr/local/share/.cache /tmp/*
|
RUN pnpm install
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
|
# build backend
|
||||||
|
FROM node:lts-alpine as backend
|
||||||
|
|
||||||
|
RUN npm install pnpm -g
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY /service/package.json /app
|
||||||
|
|
||||||
|
COPY /service/pnpm-lock.yaml /app
|
||||||
|
|
||||||
|
RUN pnpm install
|
||||||
|
|
||||||
|
COPY /service /app
|
||||||
|
|
||||||
|
RUN pnpm build
|
||||||
|
|
||||||
# service
|
# service
|
||||||
FROM node:lts-alpine
|
FROM node:lts-alpine
|
||||||
|
|
||||||
COPY /service /app
|
RUN npm install pnpm -g
|
||||||
COPY --from=builder /app/dist /app/public
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN apk add --no-cache git \
|
|
||||||
&& npm install pnpm -g \
|
|
||||||
&& pnpm install --only=production \
|
|
||||||
&& rm -rf /root/.npm /root/.pnpm-store /usr/local/share/.cache /tmp/*
|
|
||||||
|
|
||||||
|
COPY /service/package.json /app
|
||||||
|
|
||||||
|
COPY /service/pnpm-lock.yaml /app
|
||||||
|
|
||||||
|
RUN pnpm install --production && rm -rf /root/.npm /root/.pnpm-store /usr/local/share/.cache /tmp/*
|
||||||
|
|
||||||
|
COPY /service /app
|
||||||
|
|
||||||
|
COPY --from=frontend /app/dist /app/public
|
||||||
|
|
||||||
|
COPY --from=backend /app/build /app/build
|
||||||
|
|
||||||
EXPOSE 3002
|
EXPOSE 3002
|
||||||
|
|
||||||
CMD ["pnpm", "run", "start"]
|
CMD ["pnpm", "run", "prod"]
|
||||||
|
|
Loading…
Reference in New Issue