From 0385671f6325b41be6fd9f2ad9677c4b634107b2 Mon Sep 17 00:00:00 2001 From: abdulrehmann231 Date: Thu, 14 Aug 2025 12:51:42 -0700 Subject: [PATCH] feat: implemented e2b php template --- templates/deploy.js | 47 +++++++++++++++++++++++++++++++ templates/package.json | 8 ++++-- templates/php/.dockerignore | 8 ++++++ templates/php/.gitattributes | 2 ++ templates/php/e2b.Dockerfile | 54 ++++++++++++++++++++++++++++++++++++ templates/php/e2b.toml | 16 +++++++++++ templates/php/index.php | 37 ++++++++++++++++++++++++ templates/php/package.json | 14 ++++++++++ templates/php/vite.config.js | 15 ++++++++++ 9 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 templates/deploy.js create mode 100644 templates/php/.dockerignore create mode 100644 templates/php/.gitattributes create mode 100644 templates/php/e2b.Dockerfile create mode 100644 templates/php/e2b.toml create mode 100644 templates/php/index.php create mode 100644 templates/php/package.json create mode 100644 templates/php/vite.config.js diff --git a/templates/deploy.js b/templates/deploy.js new file mode 100644 index 00000000..13709859 --- /dev/null +++ b/templates/deploy.js @@ -0,0 +1,47 @@ +const { execSync } = require("child_process") +const path = require("path") +const fs = require("fs") + +// Get template name from command line args +const templateName = process.argv[2] + +function deployTemplate(dir) { + try { + // Change to template directory + process.chdir(dir) + console.log(`Deploying template in ${dir}...`) + + // Run e2b template build + execSync("e2b template build", { stdio: "inherit" }) + + console.log(`Successfully deployed template in ${dir}`) + } catch (error) { + console.error(`Error deploying template in ${dir}:`, error.message) + process.exit(1) + } +} + +// If template name is provided, deploy only that template +if (templateName) { + const templateDir = path.join(__dirname, templateName) + if (!fs.existsSync(templateDir)) { + console.error(`Template directory ${templateName} not found`) + process.exit(1) + } + if (!fs.existsSync(path.join(templateDir, "e2b.toml"))) { + console.error(`No e2b.toml found in ${templateName}`) + process.exit(1) + } + deployTemplate(templateDir) +} else { + // Deploy all templates that have e2b.toml + const entries = fs.readdirSync(__dirname, { withFileTypes: true }) + for (const entry of entries) { + if (entry.isDirectory()) { + const templateDir = path.join(__dirname, entry.name) + if (fs.existsSync(path.join(templateDir, "e2b.toml"))) { + deployTemplate(templateDir) + } + } + } +} diff --git a/templates/package.json b/templates/package.json index df319503..68e5ffed 100644 --- a/templates/package.json +++ b/templates/package.json @@ -7,7 +7,7 @@ "scripts": { "build": "tsc", "dev": "tsc --watch", - "deploy": "sh deploy.sh" + "deploy": "node deploy.js" }, "exports": { ".": "./dist/index.js", @@ -15,14 +15,16 @@ "./nextjs": "./nextjs", "./reactjs": "./reactjs", "./streamlit": "./streamlit", - "./vanillajs": "./vanillajs" + "./vanillajs": "./vanillajs", + "./php": "./php" }, "files": [ "dist", "nextjs", "reactjs", "streamlit", - "vanillajs" + "vanillajs", + "php" ], "devDependencies": { "typescript": "^5.8.3", diff --git a/templates/php/.dockerignore b/templates/php/.dockerignore new file mode 100644 index 00000000..374ef1b4 --- /dev/null +++ b/templates/php/.dockerignore @@ -0,0 +1,8 @@ +# Ignore Git and system files +.* + +# Ignore E2B files +e2b* + +# Ignore environment-specific node_modules +node_modules \ No newline at end of file diff --git a/templates/php/.gitattributes b/templates/php/.gitattributes new file mode 100644 index 00000000..dfe07704 --- /dev/null +++ b/templates/php/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/templates/php/e2b.Dockerfile b/templates/php/e2b.Dockerfile new file mode 100644 index 00000000..2f28c349 --- /dev/null +++ b/templates/php/e2b.Dockerfile @@ -0,0 +1,54 @@ +# Use the E2B base image +FROM e2bdev/code-interpreter:latest + +# Install PHP and Apache +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + php \ + php-cli \ + php-common \ + libapache2-mod-php \ + apache2 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install Node.js (which includes npm) +RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ + apt-get install -y nodejs + +# Clear npm cache to avoid conflicts +RUN npm cache clean --force + +# Initialize npm and install Vite and the PHP plugin +WORKDIR /home/user/project +RUN npm init -y && \ + npm install --save-dev vite vite-plugin-php + +# Enable Apache rewrite module +RUN a2enmod rewrite + +# Configure Apache for the project directory +RUN echo '\n\ + DocumentRoot /home/user/project\n\ + \n\ + Options Indexes FollowSymLinks\n\ + AllowOverride All\n\ + Require all granted\n\ + \n\ + ' > /etc/apache2/sites-available/000-default.conf + +# Set proper permissions for the project directory +RUN mkdir -p /home/user/project && \ + chown -R www-data:www-data /home/user/project && \ + chmod -R 755 /home/user/project + +# Copy everything from the current directory into /home/user/project +COPY . /home/user/project + +# Expose port 80 +EXPOSE 80 + +# Start Apache +CMD ["apache2-foreground"] + + diff --git a/templates/php/e2b.toml b/templates/php/e2b.toml new file mode 100644 index 00000000..5e83c570 --- /dev/null +++ b/templates/php/e2b.toml @@ -0,0 +1,16 @@ +# This is a config for E2B sandbox template. +# You can use template ID (8zr0kth5jzu5pdfq9afh) or template name (gitwit-php) to create a sandbox: + +# Python SDK +# from e2b import Sandbox, AsyncSandbox +# sandbox = Sandbox("gitwit-php") # Sync sandbox +# sandbox = await AsyncSandbox.create("gitwit-php") # Async sandbox + +# JS SDK +# import { Sandbox } from 'e2b' +# const sandbox = await Sandbox.create('gitwit-php') + +team_id = "34eab90a-97dc-4be5-87e3-a17b6e6e8bc6" +dockerfile = "e2b.Dockerfile" +template_name = "gitwit-php" +template_id = " " diff --git a/templates/php/index.php b/templates/php/index.php new file mode 100644 index 00000000..71304074 --- /dev/null +++ b/templates/php/index.php @@ -0,0 +1,37 @@ + + + + + + PHP Project + + + + + + +
+
+
+
+

Start Building your amazing project

+
+
+

+ +

+

This is a dynamic page powered by PHP and styled with Bootstrap.

+
+
+
+
+ + + + diff --git a/templates/php/package.json b/templates/php/package.json new file mode 100644 index 00000000..a8941ac3 --- /dev/null +++ b/templates/php/package.json @@ -0,0 +1,14 @@ +{ + "name": "php-vite-template", + "version": "1.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build", + "preview": "vite preview" + }, + "devDependencies": { + "vite": "^5.0.0", + "vite-plugin-php": "^1.0.0" + } +} diff --git a/templates/php/vite.config.js b/templates/php/vite.config.js new file mode 100644 index 00000000..2fd2dfe9 --- /dev/null +++ b/templates/php/vite.config.js @@ -0,0 +1,15 @@ +import path from "path" +import { defineConfig } from "vite" +import php from "vite-plugin-php" +export default defineConfig({ + plugins: [php()], + server: { + host: "0.0.0.0", + allowedHosts: true, // Allow all hosts + }, + resolve: { + alias: { + "@": path.resolve(__dirname, "./src"), + }, + }, +})