mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
feat: Add testcontainers and Playwright (no-changelog) (#16662)
Co-authored-by: Tomi Turtiainen <10324676+tomi@users.noreply.github.com>
This commit is contained in:
@@ -22,7 +22,7 @@ const scriptDir = path.dirname(new URL(import.meta.url).pathname);
|
||||
const isInScriptsDir = path.basename(scriptDir) === 'scripts';
|
||||
const rootDir = isInScriptsDir ? path.join(scriptDir, '..') : scriptDir;
|
||||
|
||||
// --- Configuration ---
|
||||
// #region ===== Configuration =====
|
||||
const config = {
|
||||
compiledAppDir: process.env.BUILD_OUTPUT_DIR || path.join(rootDir, 'compiled'),
|
||||
rootDir: rootDir,
|
||||
@@ -31,7 +31,9 @@ const config = {
|
||||
// Define backend patches to keep during deployment
|
||||
const PATCHES_TO_KEEP = ['pdfjs-dist', 'pkce-challenge', 'bull'];
|
||||
|
||||
// --- Helper Functions ---
|
||||
// #endregion ===== Configuration =====
|
||||
|
||||
// #region ===== Helper Functions =====
|
||||
const timers = new Map();
|
||||
|
||||
function startTimer(name) {
|
||||
@@ -63,7 +65,9 @@ function printDivider() {
|
||||
echo(chalk.gray('-----------------------------------------------'));
|
||||
}
|
||||
|
||||
// --- Main Build Process ---
|
||||
// #endregion ===== Helper Functions =====
|
||||
|
||||
// #region ===== Main Build Process =====
|
||||
printHeader('n8n Build & Production Preparation');
|
||||
echo(`INFO: Output Directory: ${config.compiledAppDir}`);
|
||||
printDivider();
|
||||
@@ -196,7 +200,9 @@ printDivider();
|
||||
// Calculate total time
|
||||
const totalBuildTime = getElapsedTime('total_build');
|
||||
|
||||
// --- Final Output ---
|
||||
// #endregion ===== Main Build Process =====
|
||||
|
||||
// #region ===== Final Output =====
|
||||
echo('');
|
||||
echo(chalk.green.bold('================ BUILD SUMMARY ================'));
|
||||
echo(chalk.green(`✅ n8n built successfully!`));
|
||||
@@ -215,5 +221,7 @@ echo(chalk.blue('📋 Build Manifest:'));
|
||||
echo(` ${path.resolve(config.compiledAppDir)}/build-manifest.json`);
|
||||
echo(chalk.green.bold('=============================================='));
|
||||
|
||||
// #endregion ===== Final Output =====
|
||||
|
||||
// Exit with success
|
||||
process.exit(0);
|
||||
|
||||
@@ -1,88 +1,170 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* This script is used to build the n8n docker image locally.
|
||||
* It simulates how we build for CI and should allow for local testing.
|
||||
* By default it outputs the tag 'dev' and the image name 'n8n-local:dev'.
|
||||
* It can be overridden by setting the IMAGE_BASE_NAME and IMAGE_TAG environment variables.
|
||||
* Build n8n Docker image locally
|
||||
*
|
||||
* This script simulates the CI build process for local testing.
|
||||
* Default output: 'n8nio/n8n:local'
|
||||
* Override with IMAGE_BASE_NAME and IMAGE_TAG environment variables.
|
||||
*/
|
||||
|
||||
import { $, echo, fs, chalk } from 'zx';
|
||||
import { $, echo, fs, chalk, os } from 'zx';
|
||||
import { fileURLToPath } from 'url';
|
||||
import path from 'path';
|
||||
|
||||
// Disable verbose mode for cleaner output
|
||||
$.verbose = false;
|
||||
process.env.FORCE_COLOR = '1';
|
||||
process.env.DOCKER_BUILDKIT = '1';
|
||||
|
||||
// --- Determine script location ---
|
||||
const scriptDir = path.dirname(new URL(import.meta.url).pathname);
|
||||
const isInScriptsDir = path.basename(scriptDir) === 'scripts';
|
||||
const rootDir = isInScriptsDir ? path.join(scriptDir, '..') : scriptDir;
|
||||
// #region ===== Helper Functions =====
|
||||
|
||||
/**
|
||||
* Get Docker platform string based on host architecture
|
||||
* @returns {string} Platform string (e.g., 'linux/amd64')
|
||||
*/
|
||||
function getDockerPlatform() {
|
||||
const arch = os.arch();
|
||||
const dockerArch = {
|
||||
x64: 'amd64',
|
||||
arm64: 'arm64',
|
||||
}[arch];
|
||||
|
||||
if (!dockerArch) {
|
||||
throw new Error(`Unsupported architecture: ${arch}. Only x64 and arm64 are supported.`);
|
||||
}
|
||||
|
||||
return `linux/${dockerArch}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format duration in seconds
|
||||
* @param {number} ms - Duration in milliseconds
|
||||
* @returns {string} Formatted duration
|
||||
*/
|
||||
function formatDuration(ms) {
|
||||
return `${Math.floor(ms / 1000)}s`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Docker image size
|
||||
* @param {string} imageName - Full image name with tag
|
||||
* @returns {Promise<string>} Image size or 'Unknown'
|
||||
*/
|
||||
async function getImageSize(imageName) {
|
||||
try {
|
||||
const { stdout } = await $`docker images ${imageName} --format "{{.Size}}"`;
|
||||
return stdout.trim();
|
||||
} catch {
|
||||
return 'Unknown';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a command exists
|
||||
* @param {string} command - Command to check
|
||||
* @returns {Promise<boolean>} True if command exists
|
||||
*/
|
||||
async function commandExists(command) {
|
||||
try {
|
||||
await $`command -v ${command}`;
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// #endregion ===== Helper Functions =====
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const isInScriptsDir = path.basename(__dirname) === 'scripts';
|
||||
const rootDir = isInScriptsDir ? path.join(__dirname, '..') : __dirname;
|
||||
|
||||
// --- Configuration ---
|
||||
const config = {
|
||||
dockerfilePath: path.join(rootDir, 'docker/images/n8n/Dockerfile'),
|
||||
imageBaseName: process.env.IMAGE_BASE_NAME || 'n8n-local',
|
||||
imageTag: process.env.IMAGE_TAG || 'dev',
|
||||
imageBaseName: process.env.IMAGE_BASE_NAME || 'n8nio/n8n',
|
||||
imageTag: process.env.IMAGE_TAG || 'local',
|
||||
buildContext: rootDir,
|
||||
compiledAppDir: path.join(rootDir, 'compiled'),
|
||||
get fullImageName() {
|
||||
return `${this.imageBaseName}:${this.imageTag}`;
|
||||
},
|
||||
};
|
||||
|
||||
config.fullImageName = `${config.imageBaseName}:${config.imageTag}`;
|
||||
// #region ===== Main Build Process =====
|
||||
|
||||
// --- Check Prerequisites ---
|
||||
echo(chalk.blue.bold('===== Docker Build for n8n ====='));
|
||||
echo(`INFO: Image: ${config.fullImageName}`);
|
||||
echo(chalk.gray('-----------------------------------------------'));
|
||||
const platform = getDockerPlatform();
|
||||
|
||||
// Check if compiled directory exists
|
||||
if (!(await fs.pathExists(config.compiledAppDir))) {
|
||||
echo(chalk.red(`Error: Compiled app directory not found at ${config.compiledAppDir}`));
|
||||
echo(chalk.yellow('Please run build-n8n.mjs first!'));
|
||||
async function main() {
|
||||
echo(chalk.blue.bold('===== Docker Build for n8n ====='));
|
||||
echo(`INFO: Image: ${config.fullImageName}`);
|
||||
echo(`INFO: Platform: ${platform}`);
|
||||
echo(chalk.gray('-'.repeat(47)));
|
||||
|
||||
await checkPrerequisites();
|
||||
|
||||
// Build Docker image
|
||||
const buildTime = await buildDockerImage();
|
||||
|
||||
// Get image details
|
||||
const imageSize = await getImageSize(config.fullImageName);
|
||||
|
||||
// Display summary
|
||||
displaySummary({
|
||||
imageName: config.fullImageName,
|
||||
platform,
|
||||
size: imageSize,
|
||||
buildTime,
|
||||
});
|
||||
}
|
||||
|
||||
async function checkPrerequisites() {
|
||||
if (!(await fs.pathExists(config.compiledAppDir))) {
|
||||
echo(chalk.red(`Error: Compiled app directory not found at ${config.compiledAppDir}`));
|
||||
echo(chalk.yellow('Please run build-n8n.mjs first!'));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!(await commandExists('docker'))) {
|
||||
echo(chalk.red('Error: Docker is not installed or not in PATH'));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async function buildDockerImage() {
|
||||
const startTime = Date.now();
|
||||
echo(chalk.yellow('INFO: Building Docker image...'));
|
||||
|
||||
try {
|
||||
const { stdout } = await $`DOCKER_BUILDKIT=1 docker build \
|
||||
--platform ${platform} \
|
||||
-t ${config.fullImageName} \
|
||||
-f ${config.dockerfilePath} \
|
||||
${config.buildContext}`;
|
||||
|
||||
echo(stdout);
|
||||
return formatDuration(Date.now() - startTime);
|
||||
} catch (error) {
|
||||
echo(chalk.red(`ERROR: Docker build failed: ${error.stderr || error.message}`));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function displaySummary({ imageName, platform, size, buildTime }) {
|
||||
echo('');
|
||||
echo(chalk.green.bold('═'.repeat(54)));
|
||||
echo(chalk.green.bold(' DOCKER BUILD COMPLETE'));
|
||||
echo(chalk.green.bold('═'.repeat(54)));
|
||||
echo(chalk.green(`✅ Image built: ${imageName}`));
|
||||
echo(` Platform: ${platform}`);
|
||||
echo(` Size: ${size}`);
|
||||
echo(` Build time: ${buildTime}`);
|
||||
echo(chalk.green.bold('═'.repeat(54)));
|
||||
}
|
||||
|
||||
// #endregion ===== Main Build Process =====
|
||||
|
||||
main().catch((error) => {
|
||||
echo(chalk.red(`Unexpected error: ${error.message}`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Check Docker
|
||||
try {
|
||||
await $`command -v docker`;
|
||||
} catch {
|
||||
echo(chalk.red('Error: Docker is not installed or not in PATH'));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// --- Build Docker Image ---
|
||||
const startTime = Date.now();
|
||||
echo(chalk.yellow('INFO: Building Docker image...'));
|
||||
|
||||
try {
|
||||
const buildOutput = await $`docker build \
|
||||
-t ${config.fullImageName} \
|
||||
-f ${config.dockerfilePath} \
|
||||
${config.buildContext}`;
|
||||
|
||||
echo(buildOutput.stdout);
|
||||
} catch (error) {
|
||||
echo(chalk.red(`ERROR: Docker build failed: ${error.stderr || error.message}`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const buildTime = Math.floor((Date.now() - startTime) / 1000);
|
||||
|
||||
// Get image size
|
||||
let imageSize = 'Unknown';
|
||||
try {
|
||||
const sizeOutput = await $`docker images ${config.fullImageName} --format "{{.Size}}"`;
|
||||
imageSize = sizeOutput.stdout.trim();
|
||||
} catch (error) {
|
||||
echo(chalk.yellow('Warning: Could not get image size'));
|
||||
}
|
||||
|
||||
// --- Summary ---
|
||||
echo('');
|
||||
echo(chalk.green.bold('================ DOCKER BUILD COMPLETE ================'));
|
||||
echo(chalk.green(`✅ Image built: ${config.fullImageName}`));
|
||||
echo(` Size: ${imageSize}`);
|
||||
echo(` Build time: ${buildTime}s`);
|
||||
echo(chalk.green.bold('===================================================='));
|
||||
|
||||
// Exit with success
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
@@ -14,10 +14,10 @@ const scriptDir = path.dirname(new URL(import.meta.url).pathname);
|
||||
const isInScriptsDir = path.basename(scriptDir) === 'scripts';
|
||||
const rootDir = isInScriptsDir ? path.join(scriptDir, '..') : scriptDir;
|
||||
|
||||
// --- Configuration ---
|
||||
// #region ===== Configuration =====
|
||||
const config = {
|
||||
imageBaseName: process.env.IMAGE_BASE_NAME || 'n8n-local',
|
||||
imageTag: process.env.IMAGE_TAG || 'dev',
|
||||
imageBaseName: process.env.IMAGE_BASE_NAME || 'n8nio/n8n',
|
||||
imageTag: process.env.IMAGE_TAG || 'local',
|
||||
trivyImage: process.env.TRIVY_IMAGE || 'aquasec/trivy:latest',
|
||||
severity: process.env.TRIVY_SEVERITY || 'CRITICAL,HIGH,MEDIUM,LOW',
|
||||
outputFormat: process.env.TRIVY_FORMAT || 'table',
|
||||
@@ -56,7 +56,9 @@ const printSummary = (status, time, message) => {
|
||||
echo(chalk.blue.bold('========================'));
|
||||
};
|
||||
|
||||
// --- Main Process ---
|
||||
// #endregion ===== Configuration =====
|
||||
|
||||
// #region ===== Main Process =====
|
||||
(async () => {
|
||||
printHeader('Trivy Security Scan for n8n Image');
|
||||
|
||||
@@ -150,3 +152,5 @@ const printSummary = (status, time, message) => {
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
// #endregion ===== Main Process =====
|
||||
|
||||
Reference in New Issue
Block a user