Skip to content

Commit b83be0f

Browse files
author
lee
committed
dockerized scim-server
1 parent 8e928f1 commit b83be0f

File tree

10 files changed

+733
-22
lines changed

10 files changed

+733
-22
lines changed

API_AND_URLS.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,15 @@ curl -H "Authorization: Bearer api-key-12345" \
353353

354354
### Health Check
355355
- **URL**: `http://localhost:7001/healthz`
356-
- **Description**: Health check endpoint for readiness/liveness probes
356+
- **Description**: Basic health check endpoint for readiness/liveness probes
357357
- **Authentication**: Not required
358+
- **Access**: Public - accessible from any network
359+
360+
### Detailed Health Check
361+
- **URL**: `http://localhost:7001/health`
362+
- **Description**: Detailed health check endpoint with database status and comprehensive information
363+
- **Authentication**: Not required
364+
- **Access**: Internal networks only (localhost, private networks, Docker networks)
358365

359366
### API Information
360367
- **URL**: `http://localhost:7001/api`

DOCKER.md

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# Docker Setup for SCIM Server
2+
3+
This repository includes Docker configuration to run the SCIM server in a containerized environment.
4+
5+
## Prerequisites
6+
7+
- Docker
8+
- Docker Compose
9+
10+
## Quick Start
11+
12+
1. **Build and start the container:**
13+
```bash
14+
docker-compose up --build
15+
```
16+
17+
2. **Run in background:**
18+
```bash
19+
docker-compose up -d --build
20+
```
21+
22+
3. **Stop the container:**
23+
```bash
24+
docker-compose down
25+
```
26+
27+
## Configuration
28+
29+
### Environment Variables
30+
31+
The following environment variables can be configured in `docker-compose.yml`:
32+
33+
- `PYTHONPATH`: Set to `/app` (default)
34+
- `LOG_LEVEL`: Set to `info` (default)
35+
36+
### Volumes
37+
38+
The following directories are mounted for persistence:
39+
40+
- `./scim.db``/app/scim.db` (main database)
41+
- `./logs``/app/logs` (application logs)
42+
- `./test_scim.db``/app/test_scim.db` (test database)
43+
44+
### Ports
45+
46+
- `7001` - Main SCIM server port
47+
48+
## Health Checks
49+
50+
The container includes robust health checks that verify the application is running properly:
51+
52+
### Basic Health Check
53+
```bash
54+
curl http://localhost:7001/healthz
55+
```
56+
Returns: `{"status": "ok", "timestamp": "..."}`
57+
58+
**Access**: Public - accessible from any network
59+
60+
### Detailed Health Check
61+
```bash
62+
curl http://localhost:7001/health
63+
```
64+
Returns comprehensive health information including database status.
65+
66+
**Access**: Internal networks only - restricted to:
67+
- Localhost (127.0.0.1, ::1)
68+
- Private networks (RFC 1918: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16)
69+
- Docker networks (172.16.0.0/12, 192.168.0.0/16)
70+
- Link-local addresses (169.254.0.0/16, fe80::/10)
71+
72+
**Security**: The `/health` endpoint is restricted to internal networks for security, while `/healthz` remains publicly accessible for load balancers and external monitoring.
73+
74+
### Health Check Configuration
75+
76+
- **Start Period**: 60 seconds (allows time for application startup)
77+
- **Interval**: 30 seconds (how often to check)
78+
- **Timeout**: 10 seconds (timeout for each check)
79+
- **Retries**: 5 (number of failures before marking unhealthy)
80+
81+
**Note**: Health check endpoints do not require authentication and are designed for Docker health monitoring.
82+
83+
## Development
84+
85+
### Building the Image
86+
87+
```bash
88+
docker build -t scim-server .
89+
```
90+
91+
### Running the Container
92+
93+
```bash
94+
docker run -p 7001:7001 -v $(pwd)/scim.db:/app/scim.db -v $(pwd)/logs:/app/logs scim-server
95+
```
96+
97+
### Viewing Logs
98+
99+
```bash
100+
# Docker Compose logs
101+
docker-compose logs -f
102+
103+
# Direct container logs
104+
docker logs scim-server
105+
```
106+
107+
### Checking Health Status
108+
109+
```bash
110+
# Check container health status
111+
docker ps
112+
113+
# Check health check logs
114+
docker inspect scim-server | grep -A 10 "Health"
115+
```
116+
117+
## API Endpoints
118+
119+
Once running, the SCIM server will be available at:
120+
121+
- Health Check: `http://localhost:7001/healthz`
122+
- Detailed Health: `http://localhost:7001/health`
123+
- SCIM Endpoints: `http://localhost:7001/scim-identifier/{server_id}/scim/v2/`
124+
125+
## Troubleshooting
126+
127+
### Container Won't Start
128+
129+
1. Check if port 7001 is already in use:
130+
```bash
131+
lsof -i :7001
132+
```
133+
134+
2. Check container logs:
135+
```bash
136+
docker-compose logs
137+
```
138+
139+
3. Check health check status:
140+
```bash
141+
docker ps
142+
docker inspect scim-server
143+
```
144+
145+
### Health Check Failures
146+
147+
If health checks are failing:
148+
149+
1. Check if the application is starting properly:
150+
```bash
151+
docker-compose logs scim-server
152+
```
153+
154+
2. Test the health endpoint manually:
155+
```bash
156+
curl http://localhost:7001/healthz
157+
curl http://localhost:7001/health
158+
```
159+
160+
3. Verify the container is running:
161+
```bash
162+
docker exec scim-server ps aux
163+
```
164+
165+
### IP Restriction Issues
166+
167+
If you're getting "Access denied from external network" errors when accessing `/health`:
168+
169+
1. **From Docker container**: The `/health` endpoint is restricted to internal networks only
170+
2. **From host machine**: Use `localhost` or `127.0.0.1` to access the endpoint
171+
3. **From external networks**: Use `/healthz` instead, which is publicly accessible
172+
4. **For monitoring systems**: Configure your monitoring to use `/healthz` for external checks
173+
174+
**Allowed networks for `/health`**:
175+
- Localhost: `127.0.0.1`, `::1`
176+
- Private networks: `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`
177+
- Docker networks: `172.16.0.0/12`, `192.168.0.0/16`
178+
- Link-local: `169.254.0.0/16`, `fe80::/10`
179+
180+
### Database Issues
181+
182+
If you encounter database issues, you can reset the database:
183+
184+
1. Stop the container:
185+
```bash
186+
docker-compose down
187+
```
188+
189+
2. Remove the database file:
190+
```bash
191+
rm scim.db
192+
```
193+
194+
3. Restart the container:
195+
```bash
196+
docker-compose up --build
197+
```
198+
199+
### Permission Issues
200+
201+
If you encounter permission issues with mounted volumes, ensure the current user has write permissions to the mounted directories.
202+
203+
## Production Considerations
204+
205+
For production deployment:
206+
207+
1. Use environment-specific configuration
208+
2. Consider using PostgreSQL instead of SQLite
209+
3. Set up proper logging and monitoring
210+
4. Configure SSL/TLS termination
211+
5. Use secrets management for API keys
212+
6. Monitor health check metrics
213+
7. Set up alerting for health check failures

Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Use Python 3.11 slim image as base
2+
FROM python:3.11-slim as base
3+
4+
# Set environment variables
5+
ENV PYTHONDONTWRITEBYTECODE=1 \
6+
PYTHONUNBUFFERED=1 \
7+
PYTHONPATH=/app \
8+
PIP_NO_CACHE_DIR=1 \
9+
PIP_DISABLE_PIP_VERSION_CHECK=1
10+
11+
# Install system dependencies
12+
RUN apt-get update && apt-get install -y \
13+
gcc \
14+
curl \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
# Create app directory
18+
WORKDIR /app
19+
20+
# Copy requirements first for better caching
21+
COPY requirements.txt .
22+
23+
# Install Python dependencies
24+
RUN pip install --no-cache-dir -r requirements.txt
25+
26+
# Copy application code
27+
COPY . .
28+
29+
# Create logs directory
30+
RUN mkdir -p logs
31+
32+
# Create non-root user for security
33+
RUN groupadd -r scim && useradd -r -g scim scim
34+
RUN chown -R scim:scim /app
35+
USER scim
36+
37+
# Expose port
38+
EXPOSE 7001
39+
40+
# Health check using curl with longer timeout and start period
41+
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=5 \
42+
CMD curl -f http://localhost:7001/healthz || exit 1
43+
44+
# Default command
45+
CMD ["uvicorn", "scim_server.main:app", "--host", "0.0.0.0", "--port", "7001"]

0 commit comments

Comments
 (0)