Skip to content

Commit bc2cce0

Browse files
committed
feat: Add ttyd web terminal daemon for productization
- Added ttyd to Dockerfile for web-based terminal access - Created configurable entrypoint script with ttyd daemon support - Added comprehensive ttyd environment variables for customization - Updated README with ttyd usage instructions and examples - Exposed port 7681 for web terminal interface - Support for authentication, custom paths, and security options
1 parent a5e99d2 commit bc2cce0

File tree

3 files changed

+183
-1
lines changed

3 files changed

+183
-1
lines changed

Dockerfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,27 @@ RUN apt-get update && apt-get install -y \
129129
exa \
130130
&& rm -rf /var/lib/apt/lists/*
131131

132+
# Install ttyd for web-based terminal access
133+
RUN wget -O /tmp/ttyd https://github.com/tsl0922/ttyd/releases/latest/download/ttyd.x86_64 && \
134+
chmod +x /tmp/ttyd && \
135+
mv /tmp/ttyd /usr/local/bin/ttyd
136+
132137
# Create working directory
133138
WORKDIR /workspace
134139

135140
# Set up a non-root user for better security (optional, can be overridden)
136141
RUN useradd -m -s /bin/bash developer && \
137142
echo 'developer ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
138143

144+
# Copy entrypoint script
145+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
146+
RUN chmod +x /usr/local/bin/entrypoint.sh
147+
139148
# Expose common ports for web development
140-
EXPOSE 3000 3001 5000 5173 8080 8000 5432
149+
EXPOSE 3000 3001 5000 5173 8080 8000 5432 7681
150+
151+
# Set entrypoint to run ttyd as daemon
152+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
141153

142154
# Set default command
143155
CMD ["/bin/bash"]

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This runtime includes:
1212
- **shadcn/ui** - Modern React component library with Tailwind CSS
1313
- **Claude Code CLI** - AI-powered coding assistant
1414
- **Buildah** - Container building tool that works in unprivileged mode
15+
- **ttyd** - Web-based terminal access for remote development
1516
- **Development Tools** - Git, GitHub CLI, ripgrep, and more
1617

1718
## Quick Start
@@ -75,6 +76,8 @@ buildah push fullstackagent/fullstack-web-runtime:latest docker://fullstackagent
7576

7677
The runtime supports the following environment variables:
7778

79+
### Core Configuration
80+
7881
| Variable | Description | Default | Required |
7982
|----------|-------------|---------|----------|
8083
| `ANTHROPIC_BASE_URL` | Base URL for Anthropic API | - | No |
@@ -84,6 +87,20 @@ The runtime supports the following environment variables:
8487
| `DOCKER_HUB_NAME` | Docker Hub username for pushing images | - | For pushing |
8588
| `DOCKER_HUB_PASSWD` | Docker Hub password for pushing images | - | For pushing |
8689

90+
### ttyd Web Terminal Configuration
91+
92+
| Variable | Description | Default | Required |
93+
|----------|-------------|---------|----------|
94+
| `TTYD_PORT` | Port for web terminal access | 7681 | No |
95+
| `TTYD_USERNAME` | Username for authentication | - | No |
96+
| `TTYD_PASSWORD` | Password for authentication | - | No |
97+
| `TTYD_INTERFACE` | Network interface to bind | 0.0.0.0 | No |
98+
| `TTYD_BASE_PATH` | Base URL path for ttyd | / | No |
99+
| `TTYD_MAX_CLIENTS` | Maximum concurrent clients (0=unlimited) | 0 | No |
100+
| `TTYD_READONLY` | Enable read-only mode | false | No |
101+
| `TTYD_ALLOW_ORIGIN` | CORS allow origin header | * | No |
102+
| `DISABLE_TTYD` | Disable ttyd completely | false | No |
103+
87104
### Setting Environment Variables
88105

89106
When running the container:
@@ -106,6 +123,59 @@ docker run -it --rm \
106123
fullstackagent/fullstack-web-runtime:latest
107124
```
108125

126+
## Web Terminal Access (ttyd)
127+
128+
The runtime includes ttyd, providing secure web-based terminal access. This is particularly useful for:
129+
- Remote development environments
130+
- Cloud-based IDEs
131+
- Product demonstrations
132+
- Educational platforms
133+
134+
### Basic Usage
135+
136+
```bash
137+
# Run with default ttyd configuration (port 7681, no auth)
138+
docker run -it --rm -p 7681:7681 fullstackagent/fullstack-web-runtime:latest
139+
140+
# Access the web terminal at: http://localhost:7681
141+
```
142+
143+
### Secure Usage with Authentication
144+
145+
```bash
146+
# Run with authentication enabled
147+
docker run -it --rm \
148+
-p 7681:7681 \
149+
-e TTYD_USERNAME=admin \
150+
-e TTYD_PASSWORD=secretpassword \
151+
fullstackagent/fullstack-web-runtime:latest
152+
```
153+
154+
### Custom Configuration
155+
156+
```bash
157+
# Run with custom port and path
158+
docker run -it --rm \
159+
-p 8080:8080 \
160+
-e TTYD_PORT=8080 \
161+
-e TTYD_BASE_PATH=/terminal \
162+
-e TTYD_USERNAME=developer \
163+
-e TTYD_PASSWORD=secure123 \
164+
fullstackagent/fullstack-web-runtime:latest
165+
166+
# Access at: http://localhost:8080/terminal
167+
```
168+
169+
### Disable ttyd
170+
171+
If you don't need web terminal access:
172+
173+
```bash
174+
docker run -it --rm \
175+
-e DISABLE_TTYD=true \
176+
fullstackagent/fullstack-web-runtime:latest
177+
```
178+
109179
## Usage Examples
110180

111181
### Create a Next.js Application
@@ -161,6 +231,7 @@ The following ports are exposed by default:
161231
- `8080` - General web server
162232
- `8000` - Django/FastAPI
163233
- `5432` - PostgreSQL connection
234+
- `7681` - ttyd web terminal interface
164235

165236
## Volume Mounts
166237

@@ -202,6 +273,9 @@ Recommended volume mounts:
202273
- Podman
203274
- Skopeo
204275

276+
### Web Terminal
277+
- ttyd (web-based terminal with authentication support)
278+
205279
### Utilities
206280
- ripgrep (fast search)
207281
- fd-find (fast file finder)

entrypoint.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
3+
# Entrypoint script for Full-Stack Web Runtime
4+
# This script starts ttyd as a daemon for web terminal access
5+
6+
# Configuration
7+
TTYD_PORT=${TTYD_PORT:-7681}
8+
TTYD_USERNAME=${TTYD_USERNAME:-}
9+
TTYD_PASSWORD=${TTYD_PASSWORD:-}
10+
TTYD_INTERFACE=${TTYD_INTERFACE:-0.0.0.0}
11+
TTYD_BASE_PATH=${TTYD_BASE_PATH:-/}
12+
TTYD_MAX_CLIENTS=${TTYD_MAX_CLIENTS:-0}
13+
TTYD_READONLY=${TTYD_READONLY:-false}
14+
TTYD_CHECK_ORIGIN=${TTYD_CHECK_ORIGIN:-false}
15+
TTYD_ALLOW_ORIGIN=${TTYD_ALLOW_ORIGIN:-*}
16+
17+
# Build ttyd command with options
18+
TTYD_CMD="ttyd"
19+
20+
# Add interface and port
21+
TTYD_CMD="$TTYD_CMD --interface $TTYD_INTERFACE"
22+
TTYD_CMD="$TTYD_CMD --port $TTYD_PORT"
23+
24+
# Add base path if specified
25+
if [ "$TTYD_BASE_PATH" != "/" ]; then
26+
TTYD_CMD="$TTYD_CMD --base-path $TTYD_BASE_PATH"
27+
fi
28+
29+
# Add authentication if username and password are provided
30+
if [ -n "$TTYD_USERNAME" ] && [ -n "$TTYD_PASSWORD" ]; then
31+
TTYD_CMD="$TTYD_CMD --credential $TTYD_USERNAME:$TTYD_PASSWORD"
32+
fi
33+
34+
# Add max clients limit
35+
if [ "$TTYD_MAX_CLIENTS" -gt 0 ]; then
36+
TTYD_CMD="$TTYD_CMD --max-clients $TTYD_MAX_CLIENTS"
37+
fi
38+
39+
# Add readonly mode if enabled
40+
if [ "$TTYD_READONLY" = "true" ]; then
41+
TTYD_CMD="$TTYD_CMD --readonly"
42+
fi
43+
44+
# Add CORS settings
45+
if [ "$TTYD_CHECK_ORIGIN" = "false" ]; then
46+
TTYD_CMD="$TTYD_CMD --check-origin"
47+
fi
48+
49+
# Add allow origin
50+
TTYD_CMD="$TTYD_CMD --allow-origin $TTYD_ALLOW_ORIGIN"
51+
52+
# Function to start ttyd in background
53+
start_ttyd() {
54+
echo "Starting ttyd web terminal on port $TTYD_PORT..."
55+
echo "Access the web terminal at: http://localhost:$TTYD_PORT$TTYD_BASE_PATH"
56+
57+
if [ -n "$TTYD_USERNAME" ]; then
58+
echo "Authentication enabled. Username: $TTYD_USERNAME"
59+
else
60+
echo "Warning: No authentication configured. Consider setting TTYD_USERNAME and TTYD_PASSWORD for security."
61+
fi
62+
63+
# Start ttyd in background
64+
$TTYD_CMD /bin/bash &
65+
TTYD_PID=$!
66+
echo "ttyd started with PID: $TTYD_PID"
67+
}
68+
69+
# Function to stop ttyd gracefully
70+
stop_ttyd() {
71+
if [ -n "$TTYD_PID" ]; then
72+
echo "Stopping ttyd (PID: $TTYD_PID)..."
73+
kill $TTYD_PID 2>/dev/null
74+
fi
75+
}
76+
77+
# Trap signals to ensure clean shutdown
78+
trap stop_ttyd EXIT SIGTERM SIGINT
79+
80+
# Check if ttyd should be disabled
81+
if [ "$DISABLE_TTYD" = "true" ]; then
82+
echo "ttyd is disabled via DISABLE_TTYD environment variable"
83+
else
84+
# Start ttyd daemon
85+
start_ttyd
86+
fi
87+
88+
# If a command was provided, execute it
89+
if [ $# -gt 0 ]; then
90+
echo "Executing command: $@"
91+
exec "$@"
92+
else
93+
# If no command provided, start an interactive bash shell
94+
echo "Starting interactive bash shell..."
95+
exec /bin/bash
96+
fi

0 commit comments

Comments
 (0)