This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
# Puppeteer API Healthcheck
|
||||
|
||||
A Docker container that monitors the Puppeteer API and automatically restarts the target container when the API becomes unresponsive.
|
||||
|
||||
## Features
|
||||
|
||||
- Monitors the Puppeteer API endpoint every minute
|
||||
- Automatically restarts the target container after 3 consecutive failures
|
||||
- Configurable via environment variables
|
||||
- Comprehensive logging
|
||||
- Docker socket access for container management
|
||||
|
||||
## Environment Variables
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ------------------ | ------------------------------------ | -------------------------------- |
|
||||
| `BASE_URL` | `https://puppeteer.workwithkora.com` | Base URL of the Puppeteer API |
|
||||
| `TEST_URL` | `https://www.google.com` | URL to test the API with |
|
||||
| `API_KEY` | `Q7Sd#hhFkyHy*T` | API key for authentication |
|
||||
| `TARGET_CONTAINER` | `puppeteer-api` | Name of the container to restart |
|
||||
| `CHECK_INTERVAL` | `60` | Health check interval in seconds |
|
||||
|
||||
## Usage
|
||||
|
||||
### Docker Run
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name puppeteer-healthcheck \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-e BASE_URL="https://puppeteer.workwithkora.com" \
|
||||
-e TEST_URL="https://www.google.com" \
|
||||
-e API_KEY="your-api-key" \
|
||||
-e TARGET_CONTAINER="puppeteer-api" \
|
||||
-e CHECK_INTERVAL="60" \
|
||||
your-registry/puppeteer-healthcheck:latest
|
||||
```
|
||||
|
||||
### Docker Compose
|
||||
|
||||
```yaml
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
puppeteer-healthcheck:
|
||||
build: .
|
||||
container_name: puppeteer-healthcheck
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
environment:
|
||||
- BASE_URL=https://puppeteer.workwithkora.com
|
||||
- TEST_URL=https://www.google.com
|
||||
- API_KEY=your-api-key
|
||||
- TARGET_CONTAINER=puppeteer-api
|
||||
- CHECK_INTERVAL=60
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- puppeteer-api
|
||||
```
|
||||
|
||||
## How It Works
|
||||
|
||||
1. The healthcheck container makes a GET request to the Puppeteer API every minute
|
||||
2. It uses the configured test URL and API key for authentication
|
||||
3. If the request fails (non-200 status or timeout), it increments a failure counter
|
||||
4. After 3 consecutive failures, it attempts to restart the target container
|
||||
5. If the restart is successful, the failure counter is reset
|
||||
6. The process continues indefinitely
|
||||
|
||||
## Logging
|
||||
|
||||
The container logs all health check activities to both stdout and a log file (`/app/healthcheck.log`). Log levels include:
|
||||
|
||||
- INFO: Normal operations and successful health checks
|
||||
- WARNING: Failed health checks
|
||||
- ERROR: Container restart attempts and failures
|
||||
|
||||
## Security Considerations
|
||||
|
||||
- The container requires access to the Docker socket to restart other containers
|
||||
- Ensure proper API key management
|
||||
- Consider running with limited privileges where possible
|
||||
- The container runs as a non-root user for security
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Container not found
|
||||
|
||||
- Ensure the `TARGET_CONTAINER` environment variable matches the exact name of your puppeteer-api container
|
||||
- Verify the container is running and accessible
|
||||
|
||||
### Permission denied
|
||||
|
||||
- Ensure the Docker socket is properly mounted
|
||||
- Check that the container has the necessary permissions to access the Docker daemon
|
||||
|
||||
### API key issues
|
||||
|
||||
- Verify the API key is correct and has the necessary permissions
|
||||
- Check that the base URL is accessible from the container
|
||||
|
||||
## Building
|
||||
|
||||
```bash
|
||||
docker build -t puppeteer-healthcheck .
|
||||
```
|
||||
|
||||
## Version
|
||||
|
||||
Current version: 1.0.0
|
||||
Reference in New Issue
Block a user