ci(frontend, preview service): rework dockerfiles to use clean packaged local dependencies

This commit is contained in:
Gergő Jedlicska
2022-04-09 16:08:02 +02:00
parent b574817200
commit 45f47fed60
3 changed files with 27 additions and 70 deletions
-59
View File
@@ -1,59 +0,0 @@
FROM node:16.13-bullseye-slim as node
FROM node as build
# Having multiple steps in builder doesn't increase the final image size
# So having verbose steps for readability and caching should be the target
WORKDIR /opt/viewer
COPY packages/viewer/package*.json ./
RUN npm install
COPY packages/viewer .
RUN npm run build
WORKDIR /opt/frontend
# Copy package defs first they are the least likely to change
# Keeping this order will least likely trigger full rebuild
COPY packages/frontend/package*.json ./
RUN npm install ../viewer
RUN npm ci
WORKDIR /opt
COPY packages/server/package*.json server/
ENV NODE_ENV production
RUN npm --prefix server ci server
# Copy remaining files across for frontend. Changes to these files
# will be more common than changes to the dependencies. This should
# speed up rebuilds.
COPY packages/frontend frontend
WORKDIR /opt/frontend
RUN npm run build
FROM node as runtime
RUN apk add --no-cache tini=0.19.0-r0
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.7.3/wait /wait
RUN chmod +x /wait
# Use a non-root user for increased security.
USER node
ENV NODE_ENV production
# Copy dependencies and static files from build layer
COPY --from=build --chown=node /opt/frontend/dist /home/node/frontend/dist
COPY --from=build --chown=node /opt/server /home/node/server
# Run the application from the non root users home directory
WORKDIR /home/node/server
# Copy remaining files across for the server. Changes to these
# files will be more common than changes to the dependencies.
# This should speed up rebuilds.
COPY --chown=node packages/server /home/node/server
# Init for containers https://github.com/krallin/tini
ENTRYPOINT [ "/sbin/tini", "--" ]
CMD /wait && node bin/www
+14 -3
View File
@@ -1,23 +1,34 @@
# NOTE: Docker context should be set to git root directory, to include the viewer
# build stage
FROM node:16.13-bullseye-slim as build-stage
FROM node:16.13-bullseye-slim as deps-build
WORKDIR /opt/objectloader
COPY packages/objectloader /opt/objectloader
RUN npm install
RUN npm run build
# this whole thing is required cause npm 6.* doesn't allow for pack output dir specification
RUN mkdir /packages
# invoke npm pack and move its result to the packages folder when done
RUN npm pack --pack-destination=/packages/
WORKDIR /opt/viewer
COPY packages/viewer/package*.json ./
# this installs objectloader from a tarball
RUN npm i $(find /packages -type f -name "speckle*.tgz")
RUN npm install
RUN npm install ../objectloader
COPY packages/viewer .
RUN npm run build
RUN npm pack --pack-destination=/packages/
RUN ls /packages
FROM node:16.13-bullseye-slim as build-stage
WORKDIR /opt/frontend
COPY --from=deps-build /packages /packages
COPY packages/frontend/package*.json ./
RUN npm install ../viewer
# RUN npm install ../viewer
RUN npm i $(find /packages -type f -name "speckle*.tgz")
RUN npm ci
COPY packages/frontend .
RUN npm run build
+13 -8
View File
@@ -2,7 +2,7 @@
# build stage
FROM node:14.16-buster-slim as build-stage
FROM node:14.16-buster-slim as deps-build
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
@@ -12,25 +12,32 @@ COPY packages/objectloader/package*.json ./
RUN npm install --production=false
COPY packages/objectloader .
RUN npm run build
# this whole thing is required cause npm 6.* doesn't allow for pack output dir specification
RUN mkdir /packages
# invoke npm pack and move its result to the packages folder when done
RUN mv $(npm pack) /packages/
WORKDIR /opt/viewer
COPY packages/viewer/package*.json ./
RUN npm install ../objectloader
# this installs objectloader from a tarball
RUN npm i $(find /packages -type f -name "speckle*.tgz")
# Install dependencies and devDependencies
RUN npm install --production=false
COPY packages/viewer .
RUN npm run build
RUN mv $(npm pack) /packages/
FROM node:14.16-buster-slim as build-stage
WORKDIR /opt/preview-service
COPY --from=deps-build /packages /packages
COPY packages/preview-service/package*.json ./
RUN npm install ../objectloader && rm -rf ../objectloader/node_modules
RUN npm install ../viewer && rm -rf ../viewer/node_modules
# this installs viewer and objectloader from a tarball
RUN npm i $(find /packages -type f -name "speckle*.tgz")
RUN npm ci --production=false
COPY packages/preview-service .
RUN npm run build-fe
FROM node:14.16-buster-slim as node
RUN apt-get update && apt-get install -y \
@@ -48,8 +55,6 @@ RUN chmod +x /wait
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
COPY --from=build-stage /opt/objectloader /opt/objectloader
COPY --from=build-stage /opt/viewer /opt/viewer
COPY --from=build-stage /opt/preview-service /opt/preview-service
WORKDIR /opt/preview-service