chore: Use n8n org as default with test containers (#20721)

This commit is contained in:
Tomi Turtiainen
2025-10-13 17:28:31 +03:00
committed by GitHub
parent be53e8dcaa
commit eadea9f887
4 changed files with 37 additions and 3 deletions
@@ -1,9 +1,11 @@
import { getDockerImageFromEnv } from './docker-image';
// Custom error class for when the Docker image is not found locally/remotely
// This can happen when using the "n8nio/n8n:local" image, which is not available on Docker Hub
// This image is available after running `pnpm build:docker` at the root of the repository
export class DockerImageNotFoundError extends Error {
constructor(containerName: string, originalError?: Error) {
const dockerImage = process.env.N8N_DOCKER_IMAGE ?? 'n8nio/n8n:local';
const dockerImage = getDockerImageFromEnv();
const message = `Failed to start container ${containerName}: Docker image '${dockerImage}' not found locally!
@@ -0,0 +1,30 @@
/**
* Get the Docker image to use for the n8n container
*/
export function getDockerImageFromEnv(defaultImage = 'n8nio/n8n:local') {
const configuredImage = process.env.N8N_DOCKER_IMAGE;
if (!configuredImage) {
return defaultImage;
}
const hasImageOrg = configuredImage.includes('/');
const hasImageTag = configuredImage.includes(':');
// Full image reference with org and tag (e.g., "n8nio/n8n:beta")
if (hasImageOrg && hasImageTag) {
return configuredImage;
}
// Image with org but no tag (e.g., "n8nio/n8n")
if (hasImageOrg) {
return configuredImage;
}
// Image with tag provided (e.g., "n8n:beta")
if (hasImageTag) {
return `n8nio/${configuredImage}`;
}
// Only tag name (e.g., "beta", "1.0.0")
return `n8nio/n8n:${configuredImage}`;
}
@@ -1,6 +1,7 @@
#!/usr/bin/env tsx
import { parseArgs } from 'node:util';
import { getDockerImageFromEnv } from './docker-image';
import { DockerImageNotFoundError } from './docker-image-not-found-error';
import type { N8NConfig, N8NStack } from './n8n-test-container-creation';
import { createN8NStack } from './n8n-test-container-creation';
@@ -210,7 +211,7 @@ async function main() {
}
function displayConfig(config: N8NConfig) {
const dockerImage = process.env.N8N_DOCKER_IMAGE ?? 'n8nio/n8n:local';
const dockerImage = getDockerImageFromEnv();
log.info(`Docker image: ${dockerImage}`);
// Determine actual database
@@ -16,6 +16,7 @@ import assert from 'node:assert';
import type { StartedNetwork, StartedTestContainer } from 'testcontainers';
import { GenericContainer, Network, Wait } from 'testcontainers';
import { getDockerImageFromEnv } from './docker-image';
import { DockerImageNotFoundError } from './docker-image-not-found-error';
import { N8nImagePullPolicy } from './n8n-image-pull-policy';
import {
@@ -37,7 +38,7 @@ const N8N_E2E_IMAGE = 'n8nio/n8n:local';
const MOCKSERVER_IMAGE = 'mockserver/mockserver:5.15.0';
// Default n8n image (can be overridden via N8N_DOCKER_IMAGE env var)
const N8N_IMAGE = process.env.N8N_DOCKER_IMAGE ?? N8N_E2E_IMAGE;
const N8N_IMAGE = getDockerImageFromEnv(N8N_E2E_IMAGE);
// Base environment for all n8n instances
const BASE_ENV: Record<string, string> = {