From a0061ab467f283ed0b3bf139bcbe23b129e76c87 Mon Sep 17 00:00:00 2001 From: SashkoMarchuk Date: Tue, 2 Sep 2025 10:10:44 +0200 Subject: [PATCH 1/2] Refactor Dockerfile.n8n for improved npm package installation and environment configuration - Updated the npm install command to install packages directly into n8n's app directory, enhancing organization and ownership management. - Replaced N8N_EXTERNAL_MODULES_ALLOWLIST with NODE_FUNCTION_ALLOW_EXTERNAL for better clarity in external module configuration. These changes streamline the Docker build process and improve the overall setup for the n8n service. --- Dockerfile.n8n | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Dockerfile.n8n b/Dockerfile.n8n index 1b465b1..8c447d0 100644 --- a/Dockerfile.n8n +++ b/Dockerfile.n8n @@ -10,16 +10,15 @@ ARG SLACKIFY_MARKDOWN_VERSION=^4.5.0 USER root RUN apk add --no-cache git=2.47.3-r0 -# Create n8n data directory and install packages locally -RUN mkdir -p /home/node/.n8n && \ - npm install --no-audit --no-fund --ignore-scripts --prefix /home/node/.n8n \ +# Install external packages into n8n's app directory so Code nodes can require them +RUN npm install --no-audit --no-fund --ignore-scripts --prefix /usr/local/lib/node_modules/n8n \ showdown@${SHOWDOWN_VERSION} \ slackify-markdown@${SLACKIFY_MARKDOWN_VERSION} && \ npm cache clean --force && \ - chown -R node:node /home/node/.n8n + chown -R node:node /usr/local/lib/node_modules/n8n -# Configure n8n external modules allowlist -ENV N8N_EXTERNAL_MODULES_ALLOWLIST="showdown,slackify-markdown" +# Configure external modules allowlist used by Code/Function nodes +ENV NODE_FUNCTION_ALLOW_EXTERNAL="showdown,slackify-markdown" # Create app directory WORKDIR /home/node @@ -33,4 +32,4 @@ USER node EXPOSE ${N8N_PORT} # The entrypoint script is already defined in the base image -# Don't override the CMD +# Don't override the CMD \ No newline at end of file From ef15246b5699469915f5768fb2f3e368802ab356 Mon Sep 17 00:00:00 2001 From: SashkoMarchuk Date: Tue, 2 Sep 2025 11:03:47 +0200 Subject: [PATCH 2/2] chore(docker): merge git install and npm package install into single RUN layer --- Dockerfile.n8n | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Dockerfile.n8n b/Dockerfile.n8n index 8c447d0..3a76429 100644 --- a/Dockerfile.n8n +++ b/Dockerfile.n8n @@ -6,16 +6,15 @@ ARG N8N_PORT=5678 ARG SHOWDOWN_VERSION=^2.1.0 ARG SLACKIFY_MARKDOWN_VERSION=^4.5.0 -# Install git for backup script and other packages +# Install git for backup script and other packages + install external packages in one layer USER root -RUN apk add --no-cache git=2.47.3-r0 - -# Install external packages into n8n's app directory so Code nodes can require them -RUN npm install --no-audit --no-fund --ignore-scripts --prefix /usr/local/lib/node_modules/n8n \ +RUN set -eux; \ + apk add --no-cache git=2.47.3-r0 && \ + npm install --no-audit --no-fund --ignore-scripts --prefix /usr/local/lib/node_modules/n8n \ showdown@${SHOWDOWN_VERSION} \ slackify-markdown@${SLACKIFY_MARKDOWN_VERSION} && \ - npm cache clean --force && \ - chown -R node:node /usr/local/lib/node_modules/n8n + npm cache clean --force && \ + chown -R node:node /usr/local/lib/node_modules/n8n # Configure external modules allowlist used by Code/Function nodes ENV NODE_FUNCTION_ALLOW_EXTERNAL="showdown,slackify-markdown"