From 6b68e5283681fa72abb78784b47ed20e1fb3f794 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Oct 2023 10:02:18 +0200 Subject: [PATCH] Use v2 dockerfiles --- hosting/docker-compose.build.yaml | 4 +- packages/server/Dockerfile | 39 ++++----------- packages/server/Dockerfile.v2 | 79 +++++++++++++++++++++++++++++++ packages/worker/Dockerfile | 30 +++--------- packages/worker/Dockerfile.v2 | 53 +++++++++++++++++++++ 5 files changed, 151 insertions(+), 54 deletions(-) create mode 100644 packages/server/Dockerfile.v2 create mode 100644 packages/worker/Dockerfile.v2 diff --git a/hosting/docker-compose.build.yaml b/hosting/docker-compose.build.yaml index f21b9519e4..e192620b59 100644 --- a/hosting/docker-compose.build.yaml +++ b/hosting/docker-compose.build.yaml @@ -6,7 +6,7 @@ services: app-service: build: context: .. - dockerfile: packages/server/Dockerfile + dockerfile: packages/server/Dockerfile.v2 container_name: build-bbapps environment: SELF_HOSTED: 1 @@ -36,7 +36,7 @@ services: worker-service: build: context: .. - dockerfile: packages/worker/Dockerfile + dockerfile: packages/worker/Dockerfile.v2 container_name: build-bbworker environment: SELF_HOSTED: 1 diff --git a/packages/server/Dockerfile b/packages/server/Dockerfile index d5a86b037d..e1b3b208c7 100644 --- a/packages/server/Dockerfile +++ b/packages/server/Dockerfile @@ -18,12 +18,12 @@ ENV TOP_LEVEL_PATH=/ # handle node-gyp RUN apt-get update \ - && apt-get install -y --no-install-recommends g++ make python3 jq + && apt-get install -y --no-install-recommends g++ make python3 RUN yarn global add pm2 # Install client for oracle datasource RUN apt-get install unzip libaio1 -COPY packages/server/scripts/integrations/oracle/ scripts/integrations/oracle/ +COPY scripts/integrations/oracle/ scripts/integrations/oracle/ RUN /bin/bash -e scripts/integrations/oracle/instantclient/linux/x86-64/install.sh # Install postgres client for pg_dump utils @@ -35,37 +35,18 @@ RUN apt update && apt upgrade -y \ && apt install postgresql-client-15 -y \ && apt remove software-properties-common apt-transport-https curl gpg -y -WORKDIR / -COPY scripts/removeWorkspaceDependencies.sh scripts/removeWorkspaceDependencies.sh -RUN chmod +x ./scripts/removeWorkspaceDependencies.sh - - -WORKDIR /string-templates -COPY packages/string-templates/package.json package.json -RUN ../scripts/removeWorkspaceDependencies.sh package.json -RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --production=true -COPY packages/string-templates . - - -WORKDIR /app -COPY packages/server/package.json . -COPY packages/server/dist/yarn.lock . -RUN cd ../string-templates && yarn link && cd - && yarn link @budibase/string-templates - -COPY scripts/removeWorkspaceDependencies.sh scripts/removeWorkspaceDependencies.sh -RUN chmod +x ./scripts/removeWorkspaceDependencies.sh -RUN ./scripts/removeWorkspaceDependencies.sh package.json - -RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --production=true \ +COPY package.json . +COPY dist/yarn.lock . +RUN yarn install --production=true \ # Remove unneeded data from file system to reduce image size - && yarn cache clean && apt-get remove -y --purge --auto-remove g++ make python jq \ + && yarn cache clean && apt-get remove -y --purge --auto-remove g++ make python \ && rm -rf /tmp/* /root/.node-gyp /usr/local/lib/node_modules/npm/node_modules/node-gyp -COPY packages/server/dist/ dist/ -COPY packages/server/docker_run.sh . -COPY packages/server/builder/ builder/ -COPY packages/server/client/ client/ +COPY dist/ dist/ +COPY docker_run.sh . +COPY builder/ builder/ +COPY client/ client/ EXPOSE 4001 diff --git a/packages/server/Dockerfile.v2 b/packages/server/Dockerfile.v2 new file mode 100644 index 0000000000..d5a86b037d --- /dev/null +++ b/packages/server/Dockerfile.v2 @@ -0,0 +1,79 @@ +FROM node:18-slim + +LABEL com.centurylinklabs.watchtower.lifecycle.pre-check="scripts/watchtower-hooks/pre-check.sh" +LABEL com.centurylinklabs.watchtower.lifecycle.pre-update="scripts/watchtower-hooks/pre-update.sh" +LABEL com.centurylinklabs.watchtower.lifecycle.post-update="scripts/watchtower-hooks/post-update.sh" +LABEL com.centurylinklabs.watchtower.lifecycle.post-check="scripts/watchtower-hooks/post-check.sh" + +WORKDIR /app + +ENV PORT=4001 +ENV COUCH_DB_URL=https://couchdb.budi.live:5984 +ENV BUDIBASE_ENVIRONMENT=PRODUCTION +ENV SERVICE=app-service +ENV POSTHOG_TOKEN=phc_bIjZL7oh2GEUd2vqvTBH8WvrX0fWTFQMs6H5KQxiUxU +ENV TENANT_FEATURE_FLAGS=*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR +ENV ACCOUNT_PORTAL_URL=https://account.budibase.app +ENV TOP_LEVEL_PATH=/ + +# handle node-gyp +RUN apt-get update \ + && apt-get install -y --no-install-recommends g++ make python3 jq +RUN yarn global add pm2 + +# Install client for oracle datasource +RUN apt-get install unzip libaio1 +COPY packages/server/scripts/integrations/oracle/ scripts/integrations/oracle/ +RUN /bin/bash -e scripts/integrations/oracle/instantclient/linux/x86-64/install.sh + +# Install postgres client for pg_dump utils +RUN apt update && apt upgrade -y \ + && apt install software-properties-common apt-transport-https curl gpg -y \ + && curl -fsSl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /usr/share/keyrings/postgresql.gpg > /dev/null \ + && echo deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/postgresql.gpg] http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main | tee /etc/apt/sources.list.d/postgresql.list \ + && apt update -y \ + && apt install postgresql-client-15 -y \ + && apt remove software-properties-common apt-transport-https curl gpg -y + +WORKDIR / + +COPY scripts/removeWorkspaceDependencies.sh scripts/removeWorkspaceDependencies.sh +RUN chmod +x ./scripts/removeWorkspaceDependencies.sh + + +WORKDIR /string-templates +COPY packages/string-templates/package.json package.json +RUN ../scripts/removeWorkspaceDependencies.sh package.json +RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --production=true +COPY packages/string-templates . + + +WORKDIR /app +COPY packages/server/package.json . +COPY packages/server/dist/yarn.lock . +RUN cd ../string-templates && yarn link && cd - && yarn link @budibase/string-templates + +COPY scripts/removeWorkspaceDependencies.sh scripts/removeWorkspaceDependencies.sh +RUN chmod +x ./scripts/removeWorkspaceDependencies.sh +RUN ./scripts/removeWorkspaceDependencies.sh package.json + +RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --production=true \ + # Remove unneeded data from file system to reduce image size + && yarn cache clean && apt-get remove -y --purge --auto-remove g++ make python jq \ + && rm -rf /tmp/* /root/.node-gyp /usr/local/lib/node_modules/npm/node_modules/node-gyp + +COPY packages/server/dist/ dist/ +COPY packages/server/docker_run.sh . +COPY packages/server/builder/ builder/ +COPY packages/server/client/ client/ + +EXPOSE 4001 + +# have to add node environment production after install +# due to this causing yarn to stop installing dev dependencies +# which are actually needed to get this environment up and running +ENV NODE_ENV=production +ENV CLUSTER_MODE=${CLUSTER_MODE} +ENV TOP_LEVEL_PATH=/app + +CMD ["./docker_run.sh"] diff --git a/packages/worker/Dockerfile b/packages/worker/Dockerfile index 0d60db6fc5..4230ee86f8 100644 --- a/packages/worker/Dockerfile +++ b/packages/worker/Dockerfile @@ -5,38 +5,22 @@ LABEL com.centurylinklabs.watchtower.lifecycle.pre-update="scripts/watchtower-ho LABEL com.centurylinklabs.watchtower.lifecycle.post-update="scripts/watchtower-hooks/post-update.sh" LABEL com.centurylinklabs.watchtower.lifecycle.post-check="scripts/watchtower-hooks/post-check.sh" +WORKDIR /app # handle node-gyp -RUN apk add --no-cache --virtual .gyp python3 make g++ jq +RUN apk add --no-cache --virtual .gyp python3 make g++ RUN yarn global add pm2 -WORKDIR / -COPY scripts/removeWorkspaceDependencies.sh scripts/removeWorkspaceDependencies.sh -RUN chmod +x ./scripts/removeWorkspaceDependencies.sh - - -WORKDIR /string-templates -COPY packages/string-templates/package.json package.json -RUN ../scripts/removeWorkspaceDependencies.sh package.json -RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --production=true -COPY packages/string-templates . - - -WORKDIR /app -COPY packages/worker/package.json . -COPY packages/worker/dist/yarn.lock . -RUN cd ../string-templates && yarn link && cd - && yarn link @budibase/string-templates - -RUN ../scripts/removeWorkspaceDependencies.sh package.json - -RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --production=true +COPY package.json . +COPY dist/yarn.lock . +RUN yarn install --production=true # Remove unneeded data from file system to reduce image size RUN apk del .gyp \ && yarn cache clean -COPY packages/worker/dist/ dist/ -COPY packages/worker/docker_run.sh . +COPY dist/ dist/ +COPY docker_run.sh . EXPOSE 4001 diff --git a/packages/worker/Dockerfile.v2 b/packages/worker/Dockerfile.v2 new file mode 100644 index 0000000000..0d60db6fc5 --- /dev/null +++ b/packages/worker/Dockerfile.v2 @@ -0,0 +1,53 @@ +FROM node:18-alpine + +LABEL com.centurylinklabs.watchtower.lifecycle.pre-check="scripts/watchtower-hooks/pre-check.sh" +LABEL com.centurylinklabs.watchtower.lifecycle.pre-update="scripts/watchtower-hooks/pre-update.sh" +LABEL com.centurylinklabs.watchtower.lifecycle.post-update="scripts/watchtower-hooks/post-update.sh" +LABEL com.centurylinklabs.watchtower.lifecycle.post-check="scripts/watchtower-hooks/post-check.sh" + + +# handle node-gyp +RUN apk add --no-cache --virtual .gyp python3 make g++ jq +RUN yarn global add pm2 + +WORKDIR / + +COPY scripts/removeWorkspaceDependencies.sh scripts/removeWorkspaceDependencies.sh +RUN chmod +x ./scripts/removeWorkspaceDependencies.sh + + +WORKDIR /string-templates +COPY packages/string-templates/package.json package.json +RUN ../scripts/removeWorkspaceDependencies.sh package.json +RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --production=true +COPY packages/string-templates . + + +WORKDIR /app +COPY packages/worker/package.json . +COPY packages/worker/dist/yarn.lock . +RUN cd ../string-templates && yarn link && cd - && yarn link @budibase/string-templates + +RUN ../scripts/removeWorkspaceDependencies.sh package.json + +RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --production=true +# Remove unneeded data from file system to reduce image size +RUN apk del .gyp \ + && yarn cache clean + +COPY packages/worker/dist/ dist/ +COPY packages/worker/docker_run.sh . + +EXPOSE 4001 + +# have to add node environment production after install +# due to this causing yarn to stop installing dev dependencies +# which are actually needed to get this environment up and running +ENV NODE_ENV=production +ENV CLUSTER_MODE=${CLUSTER_MODE} +ENV SERVICE=worker-service +ENV POSTHOG_TOKEN=phc_bIjZL7oh2GEUd2vqvTBH8WvrX0fWTFQMs6H5KQxiUxU +ENV TENANT_FEATURE_FLAGS=*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR +ENV ACCOUNT_PORTAL_URL=https://account.budibase.app + +CMD ["./docker_run.sh"]