templates/README.md

๐Ÿงฉ Adding Starter Templates to Devex

Devex allows users to spin up containerized REPL environments using predefined templates. To contribute your own starter template, follow the steps below.
๐Ÿ“„ Before You Begin Make sure to read the Contribution Guide at the root of the repo before proceeding.

๐Ÿš€ Steps to Add a New Template

โœ… Step 1: Add Template Folder in templates/

  • โ€ข
    Create a new folder inside templates/.
  • โ€ข
    This folder name will act as the template key and must:
    • โ€ขBe unique.
    • โ€ขBe URL-friendly (use - instead of spaces).
    • โ€ขMatch exactly across all usages (templates, runner, web, core).
    • โ€ขBe below 8MB in size.
Example: For a template named node, create templates/node/.

โš™๏ธ Step 2: Add a Dockerfile in runner/

  • โ€ขCreate a Dockerfile in runner/ named <template-key>.dockerfile.
Example: For a node template: Create runner/node.dockerfile

๐Ÿ”ง Sample Dockerfile

Dockerfile
# ---- Step 1: Build Stage ---- FROM golang:1.24 AS builder WORKDIR /app COPY go.mod go.sum ./ RUN go mod tidy COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -o runner ./cmd/main.go # ---- Step 2: Final Runtime Stage ---- FROM node:20-slim WORKDIR /app RUN apt-get update && \ apt-get install -y --no-install-recommends \ bash \ curl \ ca-certificates && \ rm -rf /var/lib/apt/lists/* RUN npm install -g nodemon typescript ts-node RUN curl -sS https://starship.rs/install.sh | sh -s -- -y && \ echo 'eval "$(starship init bash)"' >> /root/.bashrc COPY --from=builder /app/runner . EXPOSE 8080 CMD ["/app/runner"]
๐Ÿšซ Note: Do not modify the Go runner source code.
๐Ÿ’ก Add any static files needed by your template inside templates/<template-key>/.

๐Ÿง  Step 3: Register the Template in the Web UI

Edit web/libs/templates.tsx and register your new template:
tsx
node: { key: "node", name: "Node.js", description: "JavaScript runtime environment", icon: ( <IconBrandNodejs className="bg-green-800 h-9 w-9 p-2 rounded-full" /> ), },
๐Ÿงฉ The key must match the template folder and Dockerfile name exactly.

๐Ÿ›ก Step 4: Add Template to Whitelist in Backend

Edit core/models/template.go and add your template under the allowed list:
go
"node": { BaseImage: "node:20-slim", Port: 8081, },
๐Ÿ” This step ensures only validated templates are accepted by the backend.

๐Ÿ“ Final Notes

  • โ€ขDo not change the core Go runner logic.
  • โ€ขKeep Dockerfiles lean and efficient.
  • โ€ขUse only required dependencies in each template.
  • โ€ขAvoid hardcoding secrets or large assets directly in the template.

๐Ÿ“ฆ Example Template Keys

Here are a few examples of existing or recommended template keys:
KeyDescription
nodeNode.js runtime with ts-node
goGo CLI tool template
pythonPython script environment

๐Ÿ™Œ Contributing

We welcome all contributions to Devex! Please read the Contribution Guide and follow the steps above when adding new templates.