From 0348021ab201fe22aebfacc2df6bf0120606b893 Mon Sep 17 00:00:00 2001 From: "atharva.dev" Date: Wed, 22 Oct 2025 09:54:06 +0000 Subject: [PATCH] devcontainer added --- .devcontainer/Dockerfile | 43 +++++++++ .devcontainer/README.md | 158 ++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 91 +++++++++++++++++ .devcontainer/docker-compose.yml | 37 +++++++ .devcontainer/post-create.sh | 161 +++++++++++++++++++++++++++++++ 5 files changed, 490 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/README.md create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .devcontainer/post-create.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..25f7898 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,43 @@ +# Use the official Node.js development container as base +FROM mcr.microsoft.com/devcontainers/javascript-node:1-20-bullseye + +# Set the working directory +WORKDIR /workspaces + +# Install additional system dependencies that might be needed for n8n +RUN apt-get update && apt-get install -y \ + python3 \ + python3-pip \ + build-essential \ + curl \ + git \ + && rm -rf /var/lib/apt/lists/* + +# Switch to node user for security +USER node + +# Set up npm configuration for the node user +RUN npm config set prefix '/home/node/.npm-global' +ENV PATH=/home/node/.npm-global/bin:$PATH + +# Create necessary directories +RUN mkdir -p /home/node/.n8n \ + && mkdir -p /home/node/.npm-global + +# Pre-install some global packages to speed up container startup +RUN npm install -g npm@latest typescript ts-node nodemon + +# Set the default shell to bash for better development experience +SHELL ["/bin/bash", "-c"] + +# Expose the default n8n port +EXPOSE 5678 + +# Set environment variables for n8n +ENV N8N_HOST=0.0.0.0 +ENV N8N_PORT=5678 +ENV N8N_PROTOCOL=http +ENV NODE_ENV=development + +# Set the default command +CMD ["bash"] diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 0000000..9761db6 --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,158 @@ +# Seclore n8n Development Container + +This devcontainer provides a complete development environment for the Seclore n8n custom node project. + +## ๐Ÿš€ Quick Start + +1. **Open in Container**: + - Open this project in VS Code + - Click "Reopen in Container" when prompted + - Or use Command Palette: `Dev Containers: Reopen in Container` + +2. **Wait for Setup**: + - The container will automatically install dependencies + - This may take a few minutes on first run + +3. **Start Development**: + ```bash + start_dev # Build and start n8n with custom nodes + ``` + +4. **Access n8n**: + - Open http://localhost:5678 in your browser + - Your custom Seclore Protect node will be available + +## ๐Ÿ“ฆ What's Included + +### Software +- **Node.js 20.x** - Latest LTS version +- **npm** - Latest version +- **n8n** - Latest version (globally installed) +- **TypeScript** - For development +- **ts-node** - TypeScript execution +- **nodemon** - Auto-restart on changes + +### VS Code Extensions +- **TypeScript & JavaScript**: Enhanced language support +- **ESLint & Prettier**: Code formatting and linting +- **Node.js IntelliSense**: Smart completions for Node.js +- **npm IntelliSense**: Package import suggestions +- **Git Tools**: GitLens and Git Graph +- **REST Client**: API testing tools +- **Docker**: Container management + +### Development Tools +- **build_and_test**: Build project and run linter +- **start_dev**: Build and start n8n with custom nodes +- **watch_build**: Auto-rebuild on file changes +- **~/start-n8n.sh**: Direct n8n startup script + +## ๐Ÿ”ง Development Workflow + +### 1. Make Changes +Edit your TypeScript files in: +- `nodes/SecloreProtect/` - Main node logic +- `Services/` - API service classes +- `credentials/` - Credential definitions + +### 2. Build & Test +```bash +build_and_test # Compile TypeScript and run linter +``` + +### 3. Start n8n +```bash +start_dev # Build and start n8n +# OR +~/start-n8n.sh # Start n8n directly (after manual build) +``` + +### 4. Auto-rebuild (Optional) +```bash +watch_build # Watch for changes and auto-rebuild +``` + +## ๐ŸŒ Port Forwarding + +The container automatically forwards these ports: +- **5678**: n8n web interface +- **3000**: Development server +- **8080**: Alternative port + +## ๐Ÿ“ Volume Mounts + +- **Project Files**: `/workspaces/Seclore n8n` (your source code) +- **n8n Data**: `~/.n8n` (n8n configuration and data) +- **Node Modules**: Cached for faster rebuilds + +## ๐Ÿ” Environment Variables + +The container sets up these environment variables: +```bash +N8N_HOST=0.0.0.0 +N8N_PORT=5678 +N8N_PROTOCOL=http +NODE_ENV=development +N8N_LOG_LEVEL=debug +N8N_CUSTOM_EXTENSIONS=/workspaces/Seclore n8n +``` + +## ๐Ÿ› ๏ธ Customization + +### Adding Extensions +Edit `.devcontainer/devcontainer.json` and add extension IDs to the `extensions` array. + +### Changing Ports +Modify the `forwardPorts` array in `devcontainer.json`. + +### Additional Software +Add installation commands to `.devcontainer/post-create.sh`. + +## ๐Ÿ› Troubleshooting + +### Container Won't Start +- Check Docker is running +- Ensure you have enough disk space +- Try rebuilding: `Dev Containers: Rebuild Container` + +### n8n Won't Start +- Check if port 5678 is available +- Verify the build completed successfully +- Check logs for error messages + +### Build Errors +- Run `npm install` to ensure dependencies are installed +- Check TypeScript compilation errors +- Verify all import paths are correct + +### Custom Node Not Visible +- Ensure the build completed successfully +- Check that `N8N_CUSTOM_EXTENSIONS` points to the correct path +- Restart n8n after making changes + +## ๐Ÿ“š Useful Commands + +```bash +# Development +npm run build # Build the project +npm run lint # Run ESLint +npm run lint:fix # Fix ESLint issues + +# n8n +n8n start # Start n8n manually +n8n --help # n8n help + +# Container +cat ~/welcome.txt # Show welcome message +source ~/dev-scripts.sh # Reload development functions +``` + +## ๐ŸŽฏ Tips + +1. **Use the integrated terminal** in VS Code for the best experience +2. **Enable auto-save** in VS Code for faster development cycles +3. **Use the REST Client extension** to test your APIs +4. **Check the n8n logs** in the terminal for debugging +5. **Use `watch_build`** during active development for auto-rebuilds + +Happy coding! ๐Ÿš€ diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..afebf6e --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,91 @@ +{ + "name": "Seclore n8n Development", + "image": "mcr.microsoft.com/devcontainers/javascript-node:1-20-bullseye", + + "features": { + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers/features/github-cli:1": {} + }, + + "customizations": { + "vscode": { + "extensions": [ + // TypeScript and JavaScript + "ms-vscode.vscode-typescript-next", + "bradlc.vscode-tailwindcss", + "esbenp.prettier-vscode", + "dbaeumer.vscode-eslint", + + // Node.js specific + "ms-vscode.vscode-node-azure-pack", + "christian-kohler.npm-intellisense", + "eg2.vscode-npm-script", + "leizongmin.node-module-intellisense", + + // General development + "ms-vscode.vscode-json", + "redhat.vscode-yaml", + "ms-vscode.hexdump", + "ms-vscode.vscode-markdown", + + // Git and version control + "mhutchie.git-graph", + "eamodio.gitlens", + + // API and REST + "humao.rest-client", + "rangav.vscode-thunder-client", + + // Utilities + "formulahendry.auto-rename-tag", + "streetsidesoftware.code-spell-checker", + "ms-vscode.vscode-todo-highlight", + "gruntfuggly.todo-tree", + + // Docker (for n8n) + "ms-azuretools.vscode-docker" + ], + + "settings": { + "typescript.preferences.includePackageJsonAutoImports": "on", + "typescript.suggest.autoImports": true, + "typescript.updateImportsOnFileMove.enabled": "always", + "editor.formatOnSave": true, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit", + "source.organizeImports": "explicit" + }, + "files.associations": { + "*.json": "jsonc" + }, + "npm.enableScriptExplorer": true, + "npm.scriptExplorerAction": "run" + } + } + }, + + "forwardPorts": [5678, 3000, 8080], + "portsAttributes": { + "5678": { + "label": "n8n", + "onAutoForward": "notify" + }, + "3000": { + "label": "Development Server", + "onAutoForward": "notify" + }, + "8080": { + "label": "Alternative Port", + "onAutoForward": "ignore" + } + }, + + "postCreateCommand": ".devcontainer/post-create.sh", + + "remoteUser": "node", + + "mounts": [ + "source=${localWorkspaceFolder}/.n8n,target=/home/node/.n8n,type=bind,consistency=cached" + ] +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..7bf8325 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,37 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + + volumes: + - ../..:/workspaces:cached + - node_modules:/workspaces/Seclore\ n8n/node_modules + - n8n_data:/home/node/.n8n + + ports: + - "5678:5678" # n8n + - "3000:3000" # Development server + - "8080:8080" # Alternative port + + environment: + - N8N_HOST=0.0.0.0 + - N8N_PORT=5678 + - N8N_PROTOCOL=http + - NODE_ENV=development + - N8N_LOG_LEVEL=debug + + # Keep container running + command: sleep infinity + + # Use node user for security + user: node + + # Set working directory + working_dir: /workspaces/Seclore n8n + +volumes: + node_modules: + n8n_data: diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh new file mode 100644 index 0000000..c5f1de9 --- /dev/null +++ b/.devcontainer/post-create.sh @@ -0,0 +1,161 @@ +#!/bin/bash + +# Make script executable and set proper permissions +chmod +x /workspaces/*/devcontainer/post-create.sh + +echo "๐Ÿš€ Setting up Seclore n8n Development Environment..." + +# Update npm to latest version +echo "๐Ÿ“ฆ Updating npm..." +npm install -g npm@latest + +# Install n8n globally +echo "๐Ÿ”ง Installing n8n..." +npm install -g n8n + +# Install common development tools +echo "๐Ÿ› ๏ธ Installing development tools..." +npm install -g typescript ts-node nodemon + +# Install project dependencies +echo "๐Ÿ“‹ Installing project dependencies..." +npm install + +# Create .n8n directory if it doesn't exist +mkdir -p ~/.n8n + +# Set up n8n environment variables +echo "โš™๏ธ Setting up n8n configuration..." +cat > ~/.n8n/.env << EOF +# n8n Configuration +N8N_BASIC_AUTH_ACTIVE=false +N8N_HOST=0.0.0.0 +N8N_PORT=5678 +N8N_PROTOCOL=http + +# Development settings +NODE_ENV=development +N8N_LOG_LEVEL=debug + +# Custom nodes path +N8N_CUSTOM_EXTENSIONS=/workspaces/Seclore\ n8n +EOF + +# Create a startup script for n8n +echo "๐Ÿ“ Creating n8n startup script..." +cat > ~/start-n8n.sh << 'EOF' +#!/bin/bash +echo "๐ŸŽฏ Starting n8n with custom Seclore nodes..." +echo "๐Ÿ“ Custom nodes path: /workspaces/Seclore n8n" +echo "๐ŸŒ n8n will be available at: http://localhost:5678" +echo "" + +# Build the custom nodes first +cd "/workspaces/Seclore n8n" +npm run build + +# Start n8n with custom nodes +N8N_CUSTOM_EXTENSIONS="/workspaces/Seclore n8n" n8n start +EOF + +chmod +x ~/start-n8n.sh + +# Create development scripts +echo "๐Ÿ“‹ Creating development scripts..." +cat > ~/dev-scripts.sh << 'EOF' +#!/bin/bash + +# Function to build and test the custom node +build_and_test() { + echo "๐Ÿ”จ Building Seclore n8n nodes..." + cd "/workspaces/Seclore n8n" + npm run build + + if [ $? -eq 0 ]; then + echo "โœ… Build successful!" + echo "๐Ÿงช Running linter..." + npm run lint + else + echo "โŒ Build failed!" + return 1 + fi +} + +# Function to start n8n in development mode +start_dev() { + echo "๐Ÿš€ Starting n8n in development mode..." + build_and_test && ~/start-n8n.sh +} + +# Function to watch for changes and rebuild +watch_build() { + echo "๐Ÿ‘€ Watching for changes..." + cd "/workspaces/Seclore n8n" + npm run build:watch +} + +# Export functions +export -f build_and_test +export -f start_dev +export -f watch_build + +echo "๐Ÿ“š Available commands:" +echo " build_and_test - Build and lint the project" +echo " start_dev - Build and start n8n with custom nodes" +echo " watch_build - Watch for changes and rebuild automatically" +echo " ~/start-n8n.sh - Start n8n directly (after manual build)" +EOF + +chmod +x ~/dev-scripts.sh + +# Add to bashrc for easy access +echo "source ~/dev-scripts.sh" >> ~/.bashrc + +# Create a welcome message +echo "๐Ÿ“„ Creating welcome message..." +cat > ~/welcome.txt << 'EOF' +๐ŸŽ‰ Seclore n8n Development Environment Ready! + +๐Ÿ“ Project Structure: + /workspaces/Seclore n8n/ + โ”œโ”€โ”€ nodes/SecloreProtect/ # Custom n8n node + โ”œโ”€โ”€ credentials/ # Credential types + โ””โ”€โ”€ Services/ # API services + +๐Ÿš€ Quick Start: + 1. Run: start_dev # Build and start n8n + 2. Open: http://localhost:5678 # Access n8n interface + 3. Use: build_and_test # Build and test changes + +๐Ÿ”ง Development Commands: + - start_dev : Build project and start n8n + - build_and_test : Build project and run linter + - watch_build : Auto-rebuild on file changes + - ~/start-n8n.sh : Start n8n (manual build required) + +๐Ÿ“ฆ Installed Tools: + - Node.js 20.x + - npm (latest) + - n8n (latest) + - TypeScript + - ts-node + - nodemon + +๐Ÿ”Œ VS Code Extensions: + - TypeScript & JavaScript support + - ESLint & Prettier + - Node.js IntelliSense + - Git tools + - REST client for API testing + +Happy coding! ๐ŸŽฏ +EOF + +# Display welcome message +echo "" +echo "โœ… Setup complete!" +echo "" +cat ~/welcome.txt +echo "" +echo "๐Ÿ’ก Tip: Run 'cat ~/welcome.txt' anytime to see this guide again." +echo ""