Skip to content

Commit 9c7ee59

Browse files
YedPoolclaude
andcommitted
Add LiveKit Token Server Docker container and testing
- Create Dockerfile for token server with FastAPI/uvicorn - Add comprehensive GitHub Actions tests for token server - Test health endpoint, token generation, and API responses - Validate JWT token creation with proper environment variables 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fdb42c2 commit 9c7ee59

2 files changed

Lines changed: 132 additions & 1 deletion

File tree

.github/workflows/test-docker.yml

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,108 @@ jobs:
191191
192192
echo "🧹 Cleaning up..."
193193
docker stop livekit-test || true
194-
docker rm livekit-test || true
194+
docker rm livekit-test || true
195+
196+
test-token-server:
197+
runs-on: ubuntu-latest
198+
timeout-minutes: 10
199+
200+
steps:
201+
- name: Checkout code
202+
uses: actions/checkout@v4
203+
204+
- name: Set up Docker Buildx
205+
uses: docker/setup-buildx-action@v3
206+
207+
- name: Build Token Server Docker image
208+
run: |
209+
cd livekit-token-server
210+
docker build --progress=plain -t livekit-token-server:test .
211+
212+
- name: Test Token Server container startup
213+
run: |
214+
# Start container in background with required environment variables
215+
docker run -d --name token-server-test \
216+
-p 8000:8000 \
217+
-e LIVEKIT_API_KEY=testkey \
218+
-e LIVEKIT_API_SECRET=testsecret \
219+
-e LIVEKIT_URL=ws://localhost:7880 \
220+
livekit-token-server:test
221+
222+
# Show immediate logs
223+
echo "📋 Initial token server logs:"
224+
docker logs token-server-test || true
225+
226+
# Wait for container to start
227+
sleep 10
228+
229+
# Check if container is still running
230+
if docker ps | grep -q token-server-test; then
231+
echo "✅ Token server container started successfully"
232+
else
233+
echo "❌ Token server container failed to start"
234+
docker logs token-server-test
235+
exit 1
236+
fi
237+
238+
- name: Test Token Server health endpoint
239+
run: |
240+
# Wait up to 30 seconds for server to be ready
241+
timeout=30
242+
elapsed=0
243+
244+
while [ $elapsed -lt $timeout ]; do
245+
if curl -s http://localhost:8000/health > /dev/null 2>&1; then
246+
echo "✅ Token server health endpoint responding"
247+
curl -s http://localhost:8000/health | jq .
248+
break
249+
fi
250+
echo "⏳ Waiting for token server... ($elapsed/$timeout seconds)"
251+
sleep 2
252+
elapsed=$((elapsed + 2))
253+
done
254+
255+
if [ $elapsed -ge $timeout ]; then
256+
echo "❌ Token server health endpoint failed to respond"
257+
docker logs token-server-test
258+
exit 1
259+
fi
260+
261+
- name: Test token generation endpoint
262+
run: |
263+
# Test token generation
264+
echo "🔐 Testing token generation..."
265+
response=$(curl -s -X POST http://localhost:8000/token \
266+
-H "Content-Type: application/json" \
267+
-d '{
268+
"room": "test-room",
269+
"identity": "test-user",
270+
"name": "Test User"
271+
}')
272+
273+
echo "Token generation response:"
274+
echo "$response" | jq .
275+
276+
# Check if token was generated successfully
277+
if echo "$response" | jq -e '.token' > /dev/null; then
278+
echo "✅ Token generation successful"
279+
else
280+
echo "❌ Token generation failed"
281+
echo "Response: $response"
282+
exit 1
283+
fi
284+
285+
- name: Test root endpoint
286+
run: |
287+
echo "📡 Testing root endpoint..."
288+
curl -s http://localhost:8000/ | jq .
289+
290+
- name: Token server logs and cleanup
291+
if: always()
292+
run: |
293+
echo "📋 Token server logs:"
294+
docker logs token-server-test || true
295+
296+
echo "🧹 Cleaning up..."
297+
docker stop token-server-test || true
298+
docker rm token-server-test || true

livekit-token-server/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# LiveKit Token Server Docker Image
2+
FROM python:3.11-slim
3+
4+
# Install system dependencies
5+
RUN apt-get update && apt-get install -y \
6+
curl \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
# Set working directory
10+
WORKDIR /app
11+
12+
# Copy Python requirements and install dependencies
13+
COPY requirements.txt .
14+
RUN pip install --no-cache-dir -r requirements.txt
15+
16+
# Copy application code
17+
COPY main.py .
18+
19+
# Expose FastAPI port
20+
EXPOSE 8000
21+
22+
# Health check
23+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
24+
CMD curl -f http://localhost:8000/health || exit 1
25+
26+
# Start FastAPI server
27+
CMD ["python", "main.py"]

0 commit comments

Comments
 (0)