mod: Dockerfile for Release and Edge to Decrease Docker Image Size

This commit is contained in:
TheSpiritMan
2024-02-15 17:31:57 +05:45
parent 10ea8dbf71
commit fa026d9849
2 changed files with 46 additions and 21 deletions
+22 -11
View File
@@ -1,22 +1,33 @@
FROM node:18-alpine
RUN apk update && apk upgrade --no-cache && apk add --update --no-cache make gcc g++ git curl openssl openssh
RUN mkdir -p /usr/src/app
# Build Source Into JS
FROM node:18-alpine as builder
RUN apk add --update --no-cache make gcc g++ git curl openssl openssh
WORKDIR /usr/src/app
# Build backend code
COPY . /usr/src/app
COPY . ./
RUN npm ci && \
npm cache clean --force && \
npm run build && \
mv ./edge-override.json ./config-override.json
# Install only production dependencies
FROM node:18-alpine as deps
WORKDIR /usr/src/app
COPY packag*.json ./
RUN npm ci --omit=dev && \
npm cache clean --force
# This quick hack invalidates the cache.
# Final Image in Production
FROM node:18-alpine as runner
RUN apk add --update --no-cache make gcc g++ git curl openssl openssh
WORKDIR /usr/src/app
ADD https://www.google.com /time.now
COPY --from=builder /usr/src/app/built ./built
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/dist-frontend ./dist-frontend
COPY --from=builder /usr/src/app/public ./public
COPY --from=builder /usr/src/app/template ./template
COPY --from=builder /usr/src/app/dockerfiles ./dockerfiles
COPY --from=builder /usr/src/app/package.json /usr/src/app/config-override.json ./
ENV NODE_ENV production
ENV PORT 3000
+24 -10
View File
@@ -1,18 +1,32 @@
FROM node:18-alpine
RUN apk update && apk upgrade --no-cache && apk add --update --no-cache make gcc g++ git curl openssl openssh
RUN mkdir -p /usr/src/app
# Build Source Into JS
FROM node:18-alpine as builder
RUN apk add --update --no-cache make gcc g++ git curl openssl openssh
WORKDIR /usr/src/app
# Build backend code
COPY . /usr/src/app
COPY . ./
RUN npm ci && \
npm cache clean --force && \
npm run build
# Install only production dependencies
FROM node:18-alpine as deps
WORKDIR /usr/src/app
COPY packag*.json ./
RUN npm ci --omit=dev && \
npm cache clean --force
# Final Image in Production
FROM node:18-alpine as runner
RUN apk add --update --no-cache make gcc g++ git curl openssl openssh
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/built ./built
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/dist-frontend ./dist-frontend
COPY --from=builder /usr/src/app/public ./public
COPY --from=builder /usr/src/app/template ./template
COPY --from=builder /usr/src/app/dockerfiles ./dockerfiles
COPY --from=builder /usr/src/app/package.json /usr/src/app/edge-override.json ./
ENV NODE_ENV production
ENV PORT 3000