Skip to content

Commit a983709

Browse files
authored
Merge pull request #105 from abdulrehmann231/feat/phpTemplate
feat: implemented e2b php template
2 parents 0340cb1 + 0385671 commit a983709

File tree

9 files changed

+198
-3
lines changed

9 files changed

+198
-3
lines changed

templates/deploy.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const { execSync } = require("child_process")
2+
const path = require("path")
3+
const fs = require("fs")
4+
5+
// Get template name from command line args
6+
const templateName = process.argv[2]
7+
8+
function deployTemplate(dir) {
9+
try {
10+
// Change to template directory
11+
process.chdir(dir)
12+
console.log(`Deploying template in ${dir}...`)
13+
14+
// Run e2b template build
15+
execSync("e2b template build", { stdio: "inherit" })
16+
17+
console.log(`Successfully deployed template in ${dir}`)
18+
} catch (error) {
19+
console.error(`Error deploying template in ${dir}:`, error.message)
20+
process.exit(1)
21+
}
22+
}
23+
24+
// If template name is provided, deploy only that template
25+
if (templateName) {
26+
const templateDir = path.join(__dirname, templateName)
27+
if (!fs.existsSync(templateDir)) {
28+
console.error(`Template directory ${templateName} not found`)
29+
process.exit(1)
30+
}
31+
if (!fs.existsSync(path.join(templateDir, "e2b.toml"))) {
32+
console.error(`No e2b.toml found in ${templateName}`)
33+
process.exit(1)
34+
}
35+
deployTemplate(templateDir)
36+
} else {
37+
// Deploy all templates that have e2b.toml
38+
const entries = fs.readdirSync(__dirname, { withFileTypes: true })
39+
for (const entry of entries) {
40+
if (entry.isDirectory()) {
41+
const templateDir = path.join(__dirname, entry.name)
42+
if (fs.existsSync(path.join(templateDir, "e2b.toml"))) {
43+
deployTemplate(templateDir)
44+
}
45+
}
46+
}
47+
}

templates/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@
77
"scripts": {
88
"build": "tsc",
99
"dev": "tsc --watch",
10-
"deploy": "sh deploy.sh"
10+
"deploy": "node deploy.js"
1111
},
1212
"exports": {
1313
".": "./dist/index.js",
1414
"./configs": "./dist/index.js",
1515
"./nextjs": "./nextjs",
1616
"./reactjs": "./reactjs",
1717
"./streamlit": "./streamlit",
18-
"./vanillajs": "./vanillajs"
18+
"./vanillajs": "./vanillajs",
19+
"./php": "./php"
1920
},
2021
"files": [
2122
"dist",
2223
"nextjs",
2324
"reactjs",
2425
"streamlit",
25-
"vanillajs"
26+
"vanillajs",
27+
"php"
2628
],
2729
"devDependencies": {
2830
"typescript": "^5.8.3",

templates/php/.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ignore Git and system files
2+
.*
3+
4+
# Ignore E2B files
5+
e2b*
6+
7+
# Ignore environment-specific node_modules
8+
node_modules

templates/php/.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

templates/php/e2b.Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Use the E2B base image
2+
FROM e2bdev/code-interpreter:latest
3+
4+
# Install PHP and Apache
5+
RUN apt-get update && \
6+
DEBIAN_FRONTEND=noninteractive apt-get install -y \
7+
php \
8+
php-cli \
9+
php-common \
10+
libapache2-mod-php \
11+
apache2 && \
12+
apt-get clean && \
13+
rm -rf /var/lib/apt/lists/*
14+
15+
# Install Node.js (which includes npm)
16+
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
17+
apt-get install -y nodejs
18+
19+
# Clear npm cache to avoid conflicts
20+
RUN npm cache clean --force
21+
22+
# Initialize npm and install Vite and the PHP plugin
23+
WORKDIR /home/user/project
24+
RUN npm init -y && \
25+
npm install --save-dev vite vite-plugin-php
26+
27+
# Enable Apache rewrite module
28+
RUN a2enmod rewrite
29+
30+
# Configure Apache for the project directory
31+
RUN echo '<VirtualHost *:80>\n\
32+
DocumentRoot /home/user/project\n\
33+
<Directory /home/user/project>\n\
34+
Options Indexes FollowSymLinks\n\
35+
AllowOverride All\n\
36+
Require all granted\n\
37+
</Directory>\n\
38+
</VirtualHost>' > /etc/apache2/sites-available/000-default.conf
39+
40+
# Set proper permissions for the project directory
41+
RUN mkdir -p /home/user/project && \
42+
chown -R www-data:www-data /home/user/project && \
43+
chmod -R 755 /home/user/project
44+
45+
# Copy everything from the current directory into /home/user/project
46+
COPY . /home/user/project
47+
48+
# Expose port 80
49+
EXPOSE 80
50+
51+
# Start Apache
52+
CMD ["apache2-foreground"]
53+
54+

templates/php/e2b.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This is a config for E2B sandbox template.
2+
# You can use template ID (8zr0kth5jzu5pdfq9afh) or template name (gitwit-php) to create a sandbox:
3+
4+
# Python SDK
5+
# from e2b import Sandbox, AsyncSandbox
6+
# sandbox = Sandbox("gitwit-php") # Sync sandbox
7+
# sandbox = await AsyncSandbox.create("gitwit-php") # Async sandbox
8+
9+
# JS SDK
10+
# import { Sandbox } from 'e2b'
11+
# const sandbox = await Sandbox.create('gitwit-php')
12+
13+
team_id = "34eab90a-97dc-4be5-87e3-a17b6e6e8bc6"
14+
dockerfile = "e2b.Dockerfile"
15+
template_name = "gitwit-php"
16+
template_id = " "

templates/php/index.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>PHP Project</title>
7+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
8+
</head>
9+
<body class="bg-light">
10+
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
11+
<div class="container">
12+
<a class="navbar-brand" href="#">Sandbox</a>
13+
</div>
14+
</nav>
15+
16+
<di
17+
18+
v class="container mt-5">
19+
<div class="row justify-content-center">
20+
<div class="col-md-8">
21+
<div class="card shadow-lg">
22+
<div class="card-header bg-primary text-white">
23+
<h2 class="text-center">Start Building your amazing project</h2>
24+
</div>
25+
<div class="card-body text-center">
26+
<h1 class="display-4 text-primary">
27+
<?php echo "Hello, PHP!"; ?>
28+
</h1>
29+
<p class="lead mt-3">This is a dynamic page powered by PHP and styled with Bootstrap.</p>
30+
</div>
31+
</div>
32+
</div>
33+
</div>
34+
</div>
35+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
36+
</body>
37+
</html>

templates/php/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "php-vite-template",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "vite build",
8+
"preview": "vite preview"
9+
},
10+
"devDependencies": {
11+
"vite": "^5.0.0",
12+
"vite-plugin-php": "^1.0.0"
13+
}
14+
}

templates/php/vite.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import path from "path"
2+
import { defineConfig } from "vite"
3+
import php from "vite-plugin-php"
4+
export default defineConfig({
5+
plugins: [php()],
6+
server: {
7+
host: "0.0.0.0",
8+
allowedHosts: true, // Allow all hosts
9+
},
10+
resolve: {
11+
alias: {
12+
"@": path.resolve(__dirname, "./src"),
13+
},
14+
},
15+
})

0 commit comments

Comments
 (0)