2024-05-24 03:32:50 -07:00
|
|
|
ARG NODE_VERSION=20
|
2020-05-15 00:31:55 -07:00
|
|
|
|
2022-08-31 06:25:52 -07:00
|
|
|
# 1. Create an image to build n8n
|
2024-07-15 06:48:23 -07:00
|
|
|
FROM --platform=linux/amd64 n8nio/base:${NODE_VERSION} AS builder
|
2020-05-15 00:31:55 -07:00
|
|
|
|
2024-01-26 04:18:49 -08:00
|
|
|
# Build the application from source
|
|
|
|
WORKDIR /src
|
|
|
|
COPY . /src
|
2024-09-17 07:37:07 -07:00
|
|
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store --mount=type=cache,id=pnpm-metadata,target=/root/.cache/pnpm/metadata DOCKER_BUILD=true pnpm install --frozen-lockfile
|
2022-11-09 08:32:05 -08:00
|
|
|
RUN pnpm build
|
2024-01-26 04:18:49 -08:00
|
|
|
|
|
|
|
# Delete all dev dependencies
|
2023-01-30 02:02:05 -08:00
|
|
|
RUN jq 'del(.pnpm.patchedDependencies)' package.json > package.json.tmp; mv package.json.tmp package.json
|
2024-07-15 06:48:23 -07:00
|
|
|
RUN node .github/scripts/trim-fe-packageJson.js
|
2024-01-26 04:18:49 -08:00
|
|
|
|
|
|
|
# Delete any source code, source-mapping, or typings
|
2022-11-30 18:12:34 -08:00
|
|
|
RUN find . -type f -name "*.ts" -o -name "*.js.map" -o -name "*.vue" -o -name "tsconfig.json" -o -name "*.tsbuildinfo" | xargs rm -rf
|
2020-05-15 00:31:55 -07:00
|
|
|
|
2024-01-26 04:18:49 -08:00
|
|
|
# Deploy the `n8n` package into /compiled
|
|
|
|
RUN mkdir /compiled
|
2024-09-18 02:59:08 -07:00
|
|
|
RUN NODE_ENV=production DOCKER_BUILD=true pnpm --filter=n8n --prod --no-optional deploy /compiled
|
2020-05-15 00:31:55 -07:00
|
|
|
|
2022-08-31 06:25:52 -07:00
|
|
|
# 2. Start with a new clean image with just the code that is needed to run n8n
|
|
|
|
FROM n8nio/base:${NODE_VERSION}
|
2024-01-26 04:18:49 -08:00
|
|
|
ENV NODE_ENV=production
|
|
|
|
|
2023-10-03 12:24:53 -07:00
|
|
|
ARG N8N_RELEASE_TYPE=dev
|
2024-01-26 04:18:49 -08:00
|
|
|
ENV N8N_RELEASE_TYPE=${N8N_RELEASE_TYPE}
|
2023-06-07 04:28:06 -07:00
|
|
|
|
2024-01-26 04:18:49 -08:00
|
|
|
WORKDIR /home/node
|
|
|
|
COPY --from=builder /compiled /usr/local/lib/node_modules/n8n
|
2023-06-07 04:28:06 -07:00
|
|
|
COPY docker/images/n8n/docker-entrypoint.sh /
|
2022-08-31 10:34:30 -07:00
|
|
|
|
2024-10-14 06:19:17 -07:00
|
|
|
# Setup the Task Runner Launcher
|
|
|
|
ARG TARGETPLATFORM
|
|
|
|
ARG LAUNCHER_VERSION=0.1.1
|
|
|
|
ENV N8N_RUNNERS_USE_LAUNCHER=true \
|
|
|
|
N8N_RUNNERS_LAUNCHER_PATH=/usr/local/bin/task-runner-launcher
|
|
|
|
COPY docker/images/n8n/n8n-task-runners.json /etc/n8n-task-runners.json
|
|
|
|
# First, download, verify, then extract the launcher binary
|
|
|
|
# Second, chmod with 4555 to allow the use of setuid
|
|
|
|
# Third, create a new user and group to execute the Task Runners under
|
|
|
|
RUN \
|
|
|
|
if [[ "$TARGETPLATFORM" = "linux/amd64" ]]; then export ARCH_NAME="x86_64"; \
|
|
|
|
elif [[ "$TARGETPLATFORM" = "linux/arm64" ]]; then export ARCH_NAME="aarch64"; fi; \
|
|
|
|
mkdir /launcher-temp && \
|
|
|
|
cd /launcher-temp && \
|
|
|
|
wget https://github.com/n8n-io/task-runner-launcher/releases/download/${LAUNCHER_VERSION}/task-runner-launcher-$ARCH_NAME-unknown-linux-musl.zip && \
|
|
|
|
wget https://github.com/n8n-io/task-runner-launcher/releases/download/${LAUNCHER_VERSION}/task-runner-launcher-$ARCH_NAME-unknown-linux-musl.sha256 && \
|
|
|
|
sha256sum -c task-runner-launcher-$ARCH_NAME-unknown-linux-musl.sha256 && \
|
|
|
|
unzip -d $(dirname ${N8N_RUNNERS_LAUNCHER_PATH}) task-runner-launcher-$ARCH_NAME-unknown-linux-musl.zip task-runner-launcher && \
|
|
|
|
cd - && \
|
|
|
|
rm -r /launcher-temp && \
|
|
|
|
chmod 4555 ${N8N_RUNNERS_LAUNCHER_PATH} && \
|
|
|
|
addgroup -g 2000 task-runner && \
|
|
|
|
adduser -D -u 2000 -g "Task Runner User" -G task-runner task-runner
|
|
|
|
|
2022-08-31 10:34:30 -07:00
|
|
|
RUN \
|
2024-06-20 07:44:13 -07:00
|
|
|
cd /usr/local/lib/node_modules/n8n && \
|
|
|
|
npm rebuild sqlite3 && \
|
|
|
|
cd - && \
|
2024-01-26 04:18:49 -08:00
|
|
|
ln -s /usr/local/lib/node_modules/n8n/bin/n8n /usr/local/bin/n8n && \
|
2022-08-31 10:34:30 -07:00
|
|
|
mkdir .n8n && \
|
|
|
|
chown node:node .n8n
|
2024-01-26 04:18:49 -08:00
|
|
|
|
2024-02-19 02:50:20 -08:00
|
|
|
ENV SHELL /bin/sh
|
2022-08-31 06:25:52 -07:00
|
|
|
USER node
|
2022-12-07 06:54:26 -08:00
|
|
|
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
|