From bcd04981ef6e61fe30c1403c05df1761cdc9b547 Mon Sep 17 00:00:00 2001 From: oleg Date: Fri, 1 Dec 2023 12:58:55 +0100 Subject: [PATCH] ci: Fix Docker build and use multi-step approach (no-changelog) (#7893) Due to new dependencies released in `1.19`, the docker build is failing due to missing build dependencie. To get around this, we split the build into two phases. In the building phase, we install the build dependencies required to compile new module bindings and copy the result in the second phase. Github issue / Community forum post (link here to close automatically): --------- Signed-off-by: Oleg Ivaniv --- docker/images/n8n/Dockerfile | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/docker/images/n8n/Dockerfile b/docker/images/n8n/Dockerfile index 14398820a1..b964e6801b 100644 --- a/docker/images/n8n/Dockerfile +++ b/docker/images/n8n/Dockerfile @@ -1,31 +1,33 @@ ARG NODE_VERSION=18 -FROM n8nio/base:${NODE_VERSION} +FROM n8nio/base:${NODE_VERSION} as builder ARG N8N_VERSION RUN if [ -z "$N8N_VERSION" ] ; then echo "The N8N_VERSION argument is missing!" ; exit 1; fi -ENV N8N_VERSION=${N8N_VERSION} -ENV NODE_ENV=production -ENV N8N_RELEASE_TYPE=stable RUN set -eux; \ - apkArch="$(apk --print-arch)"; \ - case "$apkArch" in \ - 'armv7') apk --no-cache add --virtual build-dependencies python3 build-base;; \ - esac && \ + apk --no-cache add --virtual build-dependencies python3 build-base && \ npm install -g --omit=dev n8n@${N8N_VERSION} && \ - case "$apkArch" in \ - 'armv7') apk del build-dependencies;; \ - esac && \ + apk del build-dependencies build-base && \ rm -rf /usr/local/lib/node_modules/n8n/node_modules/@n8n/chat && \ rm -rf /usr/local/lib/node_modules/n8n/node_modules/n8n-design-system && \ rm -rf /usr/local/lib/node_modules/n8n/node_modules/n8n-editor-ui/node_modules && \ find /usr/local/lib/node_modules/n8n -type f -name "*.ts" -o -name "*.js.map" -o -name "*.vue" | xargs rm -f && \ rm -rf /root/.npm +# Final clean image +FROM n8nio/base:${NODE_VERSION} +COPY --from=builder /usr/local/lib/node_modules/n8n /usr/local/lib/node_modules/n8n +RUN ln -s /usr/local/lib/node_modules/n8n/bin/n8n /usr/local/bin/n8n + COPY docker-entrypoint.sh / RUN \ mkdir .n8n && \ chown node:node .n8n + +ENV N8N_VERSION=${N8N_VERSION} +ENV NODE_ENV=production +ENV N8N_RELEASE_TYPE=stable + USER node ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]