From 3cefc016c5d902f6a7e4c301b688491fbbdb0ab8 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 16 Jun 2022 20:38:24 +0100 Subject: [PATCH] Slimming build down from 4GB to 1.8GB for single image. --- hosting/single/Dockerfile | 44 +++++++++++++++++++++++++++------------ scripts/cleanup.sh | 11 ++++++++++ 2 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 scripts/cleanup.sh diff --git a/hosting/single/Dockerfile b/hosting/single/Dockerfile index 4490586906..f0df9373c5 100644 --- a/hosting/single/Dockerfile +++ b/hosting/single/Dockerfile @@ -1,5 +1,28 @@ +FROM node:14-slim as build + +# install node-gyp dependencies +RUN apt-get update && apt-get install -y --no-install-recommends g++ make python + +# add pin script +WORKDIR / +ADD scripts/pinVersions.js scripts/cleanup.sh ./ +RUN chmod +x /cleanup.sh + +# build server +WORKDIR /app +ADD packages/server . +RUN node /pinVersions.js && yarn && yarn build && /cleanup.sh + +# build worker +WORKDIR /worker +ADD packages/worker . +RUN node /pinVersions.js && yarn && yarn build && /cleanup.sh + FROM couchdb:3.2.1 +COPY --from=build /app /app +COPY --from=build /worker /worker + ENV DEPLOYMENT_ENVIRONMENT=docker \ POSTHOG_TOKEN=phc_fg5I3nDOf6oJVMHSaycEhpPdlgS8rzXG2r6F2IpxCHS \ COUCHDB_PASSWORD=budibase \ @@ -40,20 +63,10 @@ RUN mkdir /etc/nginx/logs && \ touch /etc/nginx/logs/error.log && \ touch /etc/nginx/logs/nginx.pid -# add pin script WORKDIR / -ADD scripts/pinVersions.js . - -# setup server and install client for oracle datasource -WORKDIR /app -ADD packages/server . -RUN node /pinVersions.js && yarn && yarn build && \ - /bin/bash -e scripts/integrations/oracle/instantclient/linux/x86-64/install.sh - -# setup worker -WORKDIR /worker -ADD packages/worker . -RUN node /pinVersions.js && yarn && yarn build +RUN mkdir -p scripts/integrations/oracle +ADD packages/server/scripts/integrations/oracle scripts/integrations/oracle +RUN /bin/bash -e ./scripts/integrations/oracle/instantclient/linux/x86-64/install.sh # setup clouseau WORKDIR / @@ -81,10 +94,15 @@ WORKDIR / ADD hosting/single/runner.sh . RUN chmod +x ./runner.sh +# cleanup cache +RUN yarn cache clean -f + EXPOSE 10000 VOLUME /opt/couchdb/data VOLUME /minio # must set this just before running ENV NODE_ENV=production +WORKDIR / + CMD ["./runner.sh"] diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh new file mode 100644 index 0000000000..d0f557a876 --- /dev/null +++ b/scripts/cleanup.sh @@ -0,0 +1,11 @@ +#!/bin/bash +dir=$(pwd) +mv dist / +mv package.json / +cd / +rm -r $dir +mkdir $dir +mv /dist $dir +mv /package.json $dir +cd $dir +NODE_ENV=production yarn