From 934a22b4bb3d0dd59f623fd9a45dba840a1f2592 Mon Sep 17 00:00:00 2001 From: Ryan Hamilton Date: Thu, 11 Sep 2025 09:36:45 -0500 Subject: [PATCH] init commit --- .dockerignore | 70 ++++++++++++++++++++++ .env.example | 17 ++++++ .gitea/workflows/build.yml | 48 ++++++++++++++++ .gitignore | 24 ++++++++ Dockerfile | 115 +++++++++++++++++++++++++++++++++++++ README.md | 58 ++++++++++++++++++- SUMMARY.md | 46 +++++++++++++++ docker-compose.yml | 46 +++++++++++++++ 8 files changed, 423 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 .gitea/workflows/build.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 SUMMARY.md create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6ae4386 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,70 @@ +# Docker-specific files +.dockerignore +Dockerfile.* + +# Environment files +.env +.env.local +.env.*.local + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Coverage directory used by tools like istanbul +coverage/ + +# nyc test coverage +.nyc_output + +# Dependency directories +node_modules/ + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# IDE/Editor files +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Build artifacts +dist/ +build/ + +# Configuration files that might contain secrets +config/production.json +config/development.json +config/test.json diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..2a128c1 --- /dev/null +++ b/.env.example @@ -0,0 +1,17 @@ +# Pa11y Dashboard Configuration +# Copy this file to .env and customize as needed + +# Port to expose Pa11y Dashboard on your host machine +PA11Y_PORT=4000 + +# Make the dashboard read-only (true/false) +READONLY=false + +# Optional site message to display on homepage +SITE_MESSAGE=Welcome to Pa11y Dashboard! + +# Enable automatic testing with cron expression +# Examples: +# 0 2 * * * = Daily at 2 AM +# 0 */6 * * * = Every 6 hours +WEBSERVICE_CRON=false diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..ab911e7 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,48 @@ +name: Build and Push Docker Image + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Install system Dependencies + run: | + apt-get update && apt-get install -y curl jq docker.io + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Log in to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: gitea.portal.tulsacounty.org + username: ${{ gitea.actor }} + password: ${{ secrets.REGISTRY_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: gitea.portal.tulsacounty.org/${{ gitea.repository }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=raw,value=latest,enable={{is_default_branch}} + type=sha,prefix={{branch}}- + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c88156 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Environment files +.env +.env.local + +# IDE/Editor files +.vscode/ +.idea/ +*.swp +*.swo + +# OS generated files +.DS_Store +Thumbs.db + +# Docker volumes +data/ + +# Configuration files that might contain secrets +config/*.json +!config/README.md + +# Logs +*.log +logs/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9cad413 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,115 @@ +# Multi-stage build for Pa11y Dashboard +FROM node:18-bullseye-slim as builder + +# Install system dependencies for Chrome +RUN apt-get update && apt-get install -y \ + ca-certificates \ + fonts-liberation \ + libappindicator3-1 \ + libasound2 \ + libatk-bridge2.0-0 \ + libatk1.0-0 \ + libcairo2 \ + libcups2 \ + libdbus-1-3 \ + libexpat1 \ + libfontconfig1 \ + libgbm1 \ + libglib2.0-0 \ + libgtk-3-0 \ + libnspr4 \ + libnss3 \ + libpango-1.0-0 \ + libpangocairo-1.0-0 \ + libx11-6 \ + libx11-xcb1 \ + libxcb1 \ + libxcomposite1 \ + libxcursor1 \ + libxdamage1 \ + libxext6 \ + libxfixes3 \ + libxi6 \ + libxrandr2 \ + libxrender1 \ + libxss1 \ + libxtst6 \ + lsb-release \ + wget \ + git \ + make \ + && rm -rf /var/lib/apt/lists/* + +# Set working directory +WORKDIR /app + +# Clone pa11y-dashboard repository +ARG PA11Y_VERSION=4.2.0 +RUN git clone https://github.com/pa11y/pa11y-dashboard.git . && \ + git checkout v${PA11Y_VERSION} + +# Install dependencies and build +RUN npm ci --only=production && \ + make less && make uglify + +# Production stage +FROM node:18-bullseye-slim + +# Install runtime dependencies for Chrome +RUN apt-get update && apt-get install -y \ + ca-certificates \ + fonts-liberation \ + libappindicator3-1 \ + libasound2 \ + libatk-bridge2.0-0 \ + libatk1.0-0 \ + libcairo2 \ + libcups2 \ + libdbus-1-3 \ + libexpat1 \ + libfontconfig1 \ + libgbm1 \ + libglib2.0-0 \ + libgtk-3-0 \ + libnspr4 \ + libnss3 \ + libpango-1.0-0 \ + libpangocairo-1.0-0 \ + libx11-6 \ + libx11-xcb1 \ + libxcb1 \ + libxcomposite1 \ + libxcursor1 \ + libxdamage1 \ + libxext6 \ + libxfixes3 \ + libxi6 \ + libxrandr2 \ + libxrender1 \ + libxss1 \ + libxtst6 \ + lsb-release \ + wget \ + && rm -rf /var/lib/apt/lists/* + +# Create app user +RUN groupadd -r pa11y && useradd -r -g pa11y pa11y + +# Set working directory +WORKDIR /app + +# Copy application files from builder stage +COPY --from=builder --chown=pa11y:pa11y /app /app + +# Switch to non-root user +USER pa11y + +# Expose port +EXPOSE 4000 + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ + CMD wget --no-verbose --tries=1 --spider http://localhost:4000/ || exit 1 + +# Start the application +CMD ["node", "index.js"] diff --git a/README.md b/README.md index 052c763..1ac4370 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,58 @@ -# pa11y-docker +# Pa11y Dashboard Docker + +A Docker container for [Pa11y Dashboard](https://github.com/pa11y/pa11y-dashboard) - a web interface for the Pa11y accessibility testing tool. + +## Quick Start + +1. **Create environment configuration:** + ```bash + cp .env.example .env + ``` + +2. **Start the services:** + ```bash + docker-compose up -d + ``` + +3. **Access the dashboard:** + - Open your browser to http://localhost:4000 + +## Configuration + +Edit the `.env` file to customize the deployment: + +```env +# Basic settings +PA11Y_PORT=4000 # Port to expose on host +READONLY=false # Make dashboard read-only +SITE_MESSAGE= # Custom homepage message + +# Automation +WEBSERVICE_CRON=false # Enable automatic testing (cron format) +``` + +## Docker Compose Services + +- **pa11y-dashboard**: The main dashboard application (port 4000) +- **mongodb**: Database for storing test results and configuration + +## Usage + +1. Navigate to http://localhost:4000 +2. Click "Add URL" to add websites to test +3. Configure accessibility standards (WCAG2AA recommended) +4. Run tests and view detailed reports + +## Building + +The image is automatically built and pushed to the Gitea registry via GitHub Actions when code is pushed to main/master branches. + +To build manually: +```bash +docker build -t pa11y-dashboard . +``` + +## License + +This Docker packaging is provided under the MIT License. Pa11y Dashboard itself is licensed under GPL-3.0. diff --git a/SUMMARY.md b/SUMMARY.md new file mode 100644 index 0000000..1f93a43 --- /dev/null +++ b/SUMMARY.md @@ -0,0 +1,46 @@ +# Pa11y Dashboard Docker Project Summary + +## What This Provides + +A minimal Docker setup for Pa11y Dashboard that: + +1. **Builds automatically** via Gitea workflows when pushed to main/master +2. **Pushes to your Gitea container registry** +3. **Provides easy deployment** with docker-compose +4. **Includes MongoDB** for data persistence +5. **Configurable via environment variables** + +## Key Files + +- **Dockerfile**: Multi-stage build that pulls Pa11y Dashboard v4.2.0 from GitHub +- **docker-compose.yml**: Runs pa11y-dashboard + MongoDB with health checks +- **.gitea/workflows/build.yml**: Automated build and push to your Gitea registry +- **.env.example**: Simple configuration template + +## Quick Deploy + +```bash +# 1. Copy environment template +cp .env.example .env + +# 2. Start services +docker-compose up -d + +# 3. Access at http://localhost:4000 +``` + +## Gitea Registry + +The workflow will automatically: +- Build the Docker image on push to main/master +- Tag with branch name, latest, and commit SHA +- Push to `gitea.portal.tulsacounty.org/your-repo-name` + +## Environment Variables + +- `PA11Y_PORT=4000` - Host port +- `READONLY=false` - Make read-only +- `SITE_MESSAGE=""` - Homepage message +- `WEBSERVICE_CRON=false` - Auto-testing schedule + +That's it! Simple and focused on your Gitea workflow needs. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1eca831 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,46 @@ +--- +services: + mongodb: + image: mongo:5.0 + restart: unless-stopped + volumes: + - mongodb_data:/data/db + environment: + MONGO_INITDB_DATABASE: pa11y-webservice + networks: + - pa11y-network + healthcheck: + test: echo 'db.runCommand("ping").ok' | mongosh mongodb://localhost:27017/test --quiet + interval: 10s + timeout: 5s + retries: 5 + start_period: 30s + + pa11y-dashboard: + build: . + restart: unless-stopped + depends_on: + mongodb: + condition: service_healthy + ports: + - ${PA11Y_PORT:-4000}:4000 + environment: + NODE_ENV: ${NODE_ENV:-production} + PORT: 4000 + NOINDEX: ${NOINDEX:-true} + READONLY: ${READONLY:-false} + SITE_MESSAGE: ${SITE_MESSAGE:-} + WEBSERVICE_DATABASE: mongodb://mongodb:27017/pa11y-webservice + WEBSERVICE_HOST: 0.0.0.0 + WEBSERVICE_PORT: 3000 + WEBSERVICE_CRON: ${WEBSERVICE_CRON:-false} + networks: + - pa11y-network + +volumes: + mongodb_data: + driver: local + +networks: + pa11y-network: + driver: bridge