2 Commits
Author SHA1 Message Date
alex e5aee5be82 Add Xvfb monitoring and restart functionality
- Move startup script to scripts/docker-start.sh for better organization
- Add automatic monitoring and restart of Xvfb if it crashes
- Improve error handling and cleanup on container shutdown
- Prevents cache update failures when Xvfb process dies
2025-12-10 10:46:10 +10:00
alex 319d397b41 Add multi-architecture support (amd64 and arm64) for Docker images 2025-12-09 03:16:34 +10:00
4 changed files with 130 additions and 13 deletions
@@ -21,6 +21,12 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
@@ -40,6 +46,7 @@ jobs:
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
+3 -6
View File
@@ -34,12 +34,9 @@ COPY --from=publish /app/publish .
# Create cache directory for screenshots
RUN mkdir -p /app/cache && chmod 777 /app/cache
# Create startup script to run Xvfb and then the app
RUN echo '#!/bin/bash\n\
Xvfb :99 -screen 0 1920x1080x24 > /dev/null 2>&1 &\n\
export DISPLAY=:99\n\
exec dotnet BomLocalService.dll' > /app/start.sh && \
chmod +x /app/start.sh
# Copy startup script
COPY scripts/docker-start.sh /app/start.sh
RUN chmod +x /app/start.sh
# OCI labels for GitHub Container Registry metadata
LABEL org.opencontainers.image.source="https://github.com/alexhopeoconnor/bom-local-service"
+70 -7
View File
@@ -46,7 +46,27 @@ Built on ASP.NET Core 9.0, the service uses a service-oriented architecture with
- **CacheController**: REST endpoints for cache management operations (`/api/cache/{suburb}/{state}`)
- **RadarTestController**: MVC controller serving the demo SPA at `/radar/{suburb}/{state}`
## Building with Docker
## Installation
### Docker Image
Pre-built Docker images are available on GitHub Container Registry:
**Image:** `ghcr.io/alexhopeoconnor/bom-local-service`
**Multi-architecture support:** Images are built for both `linux/amd64` and `linux/arm64` platforms
**Pull the latest version:**
```bash
docker pull ghcr.io/alexhopeoconnor/bom-local-service:latest
```
**Pull a specific version:**
```bash
docker pull ghcr.io/alexhopeoconnor/bom-local-service:v0.0.1
```
See all available versions on the [releases page](https://github.com/alexhopeoconnor/bom-local-service/releases).
### Prerequisites
@@ -55,9 +75,34 @@ Built on ASP.NET Core 9.0, the service uses a service-oriented architecture with
### Quick Start
#### Option 1: Using Pre-built Docker Image (Recommended)
Pull the latest image from GitHub Container Registry:
```bash
docker pull ghcr.io/alexhopeoconnor/bom-local-service:latest
```
Then run the container:
```bash
docker run -d \
--name bom-local-service \
-p 8082:8080 \
-v $(pwd)/cache:/app/cache \
--shm-size=1gb \
--ipc=host \
ghcr.io/alexhopeoconnor/bom-local-service:latest
```
**Available tags:**
- `latest` - Latest release
- `v0.0.1` - Specific version (see [releases](https://github.com/alexhopeoconnor/bom-local-service/releases) for all versions)
#### Option 2: Build from Source
1. **Clone the repository**:
```bash
git clone <repository-url>
git clone https://github.com/alexhopeoconnor/bom-local-service.git
cd bom-local-service
```
@@ -86,14 +131,32 @@ Built on ASP.NET Core 9.0, the service uses a service-oriented architecture with
### Using Docker Compose
The included `docker-compose.yml` provides a convenient way to run the service with all configuration options:
The included `docker-compose.yml` provides a convenient way to run the service with all configuration options.
**Using pre-built image (recommended):**
Update `docker-compose.yml` to use the GitHub Container Registry image:
```yaml
services:
bom-local-service:
image: ghcr.io/alexhopeoconnor/bom-local-service:latest
# Remove or comment out the 'build:' section
```
Then run:
```bash
docker-compose up -d
```
**Building from source:**
If you want to build locally, keep the `build:` section in `docker-compose.yml` and run:
```bash
docker-compose up -d
```
This will:
- Build the image if it doesn't exist
- Pull/build the image as configured
- Start the service on port 8082 (configurable via `HOST_PORT`)
- Mount the `./cache` directory for persistent storage
- Apply all environment variable configurations
@@ -180,7 +243,7 @@ docker run -d \
-e CACHEEXPIRATIONMINUTES=15 \
--shm-size=1gb \
--ipc=host \
bom-local-service
ghcr.io/alexhopeoconnor/bom-local-service:latest
```
#### Custom Cache Directory
@@ -193,7 +256,7 @@ docker run -d \
-e CACHEDIRECTORY=/app/cache \
--shm-size=1gb \
--ipc=host \
bom-local-service
ghcr.io/alexhopeoconnor/bom-local-service:latest
```
#### Development Mode with Debug
@@ -208,7 +271,7 @@ docker run -d \
-e DEBUG__WAITMS=5000 \
--shm-size=1gb \
--ipc=host \
bom-local-service
ghcr.io/alexhopeoconnor/bom-local-service:latest
```
#### Using docker-compose with Custom Settings
+50
View File
@@ -0,0 +1,50 @@
#!/bin/bash
set -e
# Function to start Xvfb
start_xvfb() {
if ! pgrep -f "Xvfb :99" > /dev/null; then
echo "Starting Xvfb on display :99..."
Xvfb :99 -screen 0 1920x1080x24 -ac +extension GLX +render -noreset > /dev/null 2>&1 &
sleep 1
if ! pgrep -f "Xvfb :99" > /dev/null; then
echo "ERROR: Xvfb failed to start" >&2
return 1
fi
echo "Xvfb started successfully"
fi
return 0
}
# Function to monitor and restart Xvfb if it dies (runs as background process)
monitor_xvfb() {
# Monitor while PID 1 (dotnet after exec) is still running
while kill -0 1 2>/dev/null; do
sleep 5
if ! pgrep -f "Xvfb :99" > /dev/null; then
echo "WARNING: Xvfb process not found, restarting..." >&2
start_xvfb || true
fi
done
}
# Cleanup function
cleanup() {
echo "Shutting down Xvfb..."
pkill -f "Xvfb :99" || true
}
# Set up signal handlers for cleanup
trap cleanup SIGTERM SIGINT EXIT
# Start Xvfb
start_xvfb || exit 1
# Export DISPLAY
export DISPLAY=:99
# Start monitoring in background (will check if PID 1 is still running)
monitor_xvfb &
# Start the .NET application (replaces shell as PID 1)
exec dotnet BomLocalService.dll