Skip to content

Commit

Permalink
preview-service smaller docker image size (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristi8 authored May 13, 2021
1 parent 4e34f84 commit 7709f57
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .circleci/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ echo "$K8S_CLUSTER_CERTIFICATE" | base64 --decode > k8s_cert.crt
--server=$K8S_SERVER \
--certificate-authority=k8s_cert.crt \
--token=$K8S_TOKEN \
rollout status -w deployment/$TARGET_SPECKLE_DEPLOYMENT-frontend --timeout=1m
rollout status -w deployment/$TARGET_SPECKLE_DEPLOYMENT-frontend --timeout=3m

./kubectl \
--kubeconfig=/dev/null \
--server=$K8S_SERVER \
--certificate-authority=k8s_cert.crt \
--token=$K8S_TOKEN \
rollout status -w deployment/$TARGET_SPECKLE_DEPLOYMENT-server --timeout=1m
rollout status -w deployment/$TARGET_SPECKLE_DEPLOYMENT-server --timeout=3m

./kubectl \
--kubeconfig=/dev/null \
--server=$K8S_SERVER \
--certificate-authority=k8s_cert.crt \
--token=$K8S_TOKEN \
rollout status -w deployment/$TARGET_SPECKLE_DEPLOYMENT-preview-service --timeout=1m
rollout status -w deployment/$TARGET_SPECKLE_DEPLOYMENT-preview-service --timeout=3m
40 changes: 26 additions & 14 deletions packages/preview-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
# NOTE: Docker context should be set to git root directory, to include the viewer

FROM node:14.16.0-buster-slim as node

RUN apt-get update && apt-get install -y \
tini \
&& rm -rf /var/lib/apt/lists/*

# chromium dependencies
RUN apt-get update && apt-get install -y \
ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils \
&& rm -rf /var/lib/apt/lists/*

# build stage
FROM node:14.16-buster-slim as build-stage

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /app


WORKDIR /opt/objectloader
COPY packages/objectloader/package*.json ./
Expand All @@ -33,12 +23,34 @@ RUN npm run build

WORKDIR /opt/preview-service
COPY packages/preview-service/package*.json ./
RUN npm install ../objectloader
RUN npm install ../viewer
RUN npm install ../objectloader && rm -rf ../objectloader/node_modules
RUN npm install ../viewer && rm -rf ../viewer/node_modules
RUN npm ci --production=false
COPY packages/preview-service .
RUN npm run build-fe



FROM node:14.16.0-buster-slim as node

RUN apt-get update && apt-get install -y \
tini \
&& rm -rf /var/lib/apt/lists/*

# chromium dependencies
RUN apt-get update && apt-get install -y \
ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils \
&& rm -rf /var/lib/apt/lists/*

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


ENTRYPOINT [ "tini", "--" ]
CMD ["node", "bin/www"]
6 changes: 5 additions & 1 deletion packages/preview-service/routes/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ function sleep( ms ) {
}

async function getScreenshot( objectUrl ) {
const browser = await puppeteer.launch( { args: [ '--no-sandbox', '--disable-setuid-sandbox' ] } )
let launchParams = { args: [ '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage' ] }
// if ( process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD === 'true' ) {
// launchParams.executablePath = 'chromium'
// }
const browser = await puppeteer.launch( launchParams )
const page = await browser.newPage()
await page.goto( 'http://127.0.0.1:3001/render/' )

Expand Down

0 comments on commit 7709f57

Please sign in to comment.