Reduce docker image size
This commit is contained in:
parent
42799389b5
commit
2ecdb07d65
40
Dockerfile
40
Dockerfile
|
|
@ -1,44 +1,36 @@
|
||||||
FROM node:16.14.2 as client-builder
|
FROM node:16.14.2-alpine as client-builder
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
COPY picture-gallery-client/package*.json /usr/src/app/picture-gallery-client/
|
||||||
COPY picture-gallery-client/package*.json picture-gallery-client/
|
|
||||||
WORKDIR /usr/src/app/picture-gallery-client
|
WORKDIR /usr/src/app/picture-gallery-client
|
||||||
RUN npm ci --only=production
|
RUN npm ci --only=production
|
||||||
COPY picture-gallery-client .
|
COPY picture-gallery-client .
|
||||||
RUN npm run build-client
|
RUN npm run build-client
|
||||||
|
|
||||||
FROM node:16.14.2 as server-builder
|
RUN mkdir built && \
|
||||||
|
mv build built && \
|
||||||
|
mv package.minimize.docker.json built/package.json && \
|
||||||
|
cp package-lock.json built && \
|
||||||
|
npm --prefix built/ ci --only=production
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
FROM node:16.14.2-alpine as server-builder
|
||||||
COPY picture-gallery-server/package*.json picture-gallery-server/
|
|
||||||
|
COPY picture-gallery-server/package*.json /usr/src/app/picture-gallery-server/
|
||||||
WORKDIR /usr/src/app/picture-gallery-server
|
WORKDIR /usr/src/app/picture-gallery-server
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
COPY picture-gallery-server .
|
COPY picture-gallery-server .
|
||||||
RUN npm run build-server
|
RUN npm run build-server
|
||||||
|
|
||||||
FROM node:16.14.2
|
RUN mkdir built && \
|
||||||
|
mv dist node_modules built
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
FROM node:16.14.2-alpine
|
||||||
|
|
||||||
COPY picture-gallery-client/package*.json picture-gallery-client/
|
COPY --from=client-builder --chown=node:node /usr/src/app/picture-gallery-client/built /usr/src/app/picture-gallery-client/
|
||||||
COPY picture-gallery-server/package*.json picture-gallery-server/
|
COPY --from=server-builder --chown=node:node /usr/src/app/picture-gallery-server/built /usr/src/app/picture-gallery-server/
|
||||||
|
|
||||||
COPY --from=client-builder /usr/src/app/picture-gallery-client/build /usr/src/app/picture-gallery-client/build
|
|
||||||
COPY --from=server-builder /usr/src/app/picture-gallery-server/dist /usr/src/app/picture-gallery-server/dist
|
|
||||||
|
|
||||||
RUN chown node:node -R /usr/src/app/picture-gallery-client/build && \
|
|
||||||
chown node:node -R /usr/src/app/picture-gallery-server/dist
|
|
||||||
|
|
||||||
# only needed for "react-inject-env"
|
|
||||||
WORKDIR /usr/src/app/picture-gallery-client
|
|
||||||
RUN npm ci --only=production
|
|
||||||
|
|
||||||
WORKDIR /usr/src/app/picture-gallery-server
|
|
||||||
RUN npm ci --only=production
|
|
||||||
|
|
||||||
VOLUME /usr/src/app/public
|
VOLUME /usr/src/app/public
|
||||||
EXPOSE 3001
|
EXPOSE 3001
|
||||||
|
|
||||||
USER node
|
USER node
|
||||||
# we are still in the server directory
|
WORKDIR /usr/src/app/picture-gallery-server
|
||||||
CMD npm --prefix ../picture-gallery-client/ run set-environment && node dist/app.js
|
CMD npm --prefix ../picture-gallery-client/ run set-environment && node dist/app.js
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"name": "picture-gallery-client",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"react-inject-env": "2.1.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"set-environment": "npx react-inject-env set"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue