Skip to content

Commit c6c7056

Browse files
committed
Create playground app
1 parent 52699b3 commit c6c7056

19 files changed

Lines changed: 2919 additions & 0 deletions

src/playground/.devcontainer.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "Playground Apps Manager",
3+
"dockerComposeFile": "docker-compose.yaml",
4+
"service": "app",
5+
"shutdownAction": "none",
6+
"workspaceFolder": "/workspace",
7+
"initializeCommand": "DOCKER_GID=`getent group docker | cut -d: -f3` && echo \"DOCKER_GID=${DOCKER_GID}\" > .env && mkdir -p apps && chmod 777 apps",
8+
"remoteUser": "root"
9+
}

src/playground/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# example
2+
3+
Web-based manager for creating and deploying custom devcontainer applications
4+
5+
## Access
6+
7+
Once deployed in Workbench, access the web interface at the app URL (port 8080).
8+
9+
For local testing:
10+
1. Create Docker network: `docker network create app-network`
11+
2. Run the app: `devcontainer up --workspace-folder .`
12+
3. Access at: `http://localhost:8080`
13+
14+
## Customization
15+
16+
Edit the following files to customize your app:
17+
18+
- `.devcontainer.json` - Devcontainer configuration and features
19+
- `docker-compose.yaml` - Docker Compose configuration (change the `command` to customize ttyd options)
20+
- `devcontainer-template.json` - Template options and metadata
21+
22+
## Usage
23+
24+
1. Fork the repository
25+
2. Modify the configuration files as needed
26+
3. In Workbench UI, create a custom app pointing to your forked repository
27+
4. Select this app template (example)

src/playground/caddy/Caddyfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
debug
3+
admin 0.0.0.0:2019
4+
}
5+
6+
http://:8080 {
7+
# Dynamic routes will be added here via API
8+
route {
9+
# Default route to playground UI
10+
reverse_proxy playground:8080
11+
}
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": "playground",
3+
"version": "1.0.0",
4+
"name": "Playground Apps Manager",
5+
"description": "Web-based manager for creating and deploying custom devcontainer applications"
6+
}

src/playground/docker-compose.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
services:
2+
app:
3+
# The container name must be "application-server"
4+
container_name: "application-server"
5+
image: "caddy:2.11-alpine"
6+
restart: always
7+
volumes:
8+
- ./caddy:/etc/caddy:ro
9+
- caddy_data:/data
10+
ports:
11+
- 8080:8080
12+
networks:
13+
- app-network
14+
- playground-apps
15+
16+
playground:
17+
build:
18+
context: ./playground
19+
container_name: "playground"
20+
user: "playground:${DOCKER_GID}"
21+
restart: always
22+
depends_on:
23+
app:
24+
condition: service_started
25+
db:
26+
condition: service_healthy
27+
environment:
28+
PORT: "8080"
29+
DB_HOST: "db"
30+
DB_PORT: "5432"
31+
DB_NAME: "playground"
32+
DB_USER: "playground_user"
33+
DB_PASSWORD: "playground_password"
34+
CADDY_HOST: "application-server"
35+
CADDY_PORT: "2019"
36+
volumes:
37+
# mount Host machine's docker.sock to container's docker.sock
38+
- /var/run/docker.sock:/var/run/docker.sock
39+
# mount Host machine's /etc/group to container's /etc/host-group
40+
- /etc/group:/etc/host-group
41+
# mount apps directory for devcontainer builds
42+
- ./apps:/workspace/apps
43+
# mount startup scripts from parent directory
44+
- ./startupscript:/workspace/startupscript
45+
# mount features directory for devcontainer features
46+
- ../../features:/workspace/features:ro
47+
networks:
48+
- playground-apps
49+
- playground
50+
51+
db:
52+
image: "postgres:18-alpine"
53+
restart: always
54+
environment:
55+
POSTGRES_USER: "playground_user"
56+
POSTGRES_PASSWORD: "playground_password"
57+
POSTGRES_DB: "playground"
58+
volumes:
59+
- pg_data:/var/lib/postgresql/data
60+
networks:
61+
- playground
62+
healthcheck:
63+
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
64+
interval: 10s
65+
timeout: 5s
66+
retries: 5
67+
start_period: 10s
68+
69+
volumes:
70+
caddy_data:
71+
pg_data:
72+
73+
networks:
74+
# The Docker network must be named "app-network". This is an external network
75+
# that is created outside of this docker-compose file.
76+
app-network:
77+
external: true
78+
playground:
79+
playground-apps:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM golang:1.25-alpine AS build
2+
3+
WORKDIR /app
4+
5+
COPY go.mod go.sum ./
6+
RUN go mod download
7+
COPY . .
8+
9+
RUN go build -o /playground .
10+
11+
FROM alpine:latest
12+
13+
# Install Node.js, npm, Docker CLI, docker-compose, buildx, ttyd, bash, and devcontainer CLI
14+
RUN apk add --no-cache nodejs npm docker-cli docker-cli-compose docker-cli-buildx ttyd bash && \
15+
npm install -g @devcontainers/cli
16+
17+
RUN addgroup -S playground -g 1001 && adduser -S playground -u 1001 -G playground
18+
19+
WORKDIR /workspace
20+
COPY --chown=playground:playground --from=build /playground /playground
21+
22+
# Create startup script to run ttyd in background and playground in foreground
23+
RUN cat > /start.sh <<'EOF'
24+
#!/bin/sh
25+
ttyd --writable --port 7681 --base-path /_shell bash &
26+
exec /playground
27+
EOF
28+
29+
RUN chmod +x /start.sh
30+
31+
USER playground
32+
33+
EXPOSE 8080 7681
34+
35+
CMD [ "/start.sh" ]

0 commit comments

Comments
 (0)