From 41f3df82896a81d579384164eb7e5cdfeb5f71e9 Mon Sep 17 00:00:00 2001 From: NinjaPug <36635276+programmingPug@users.noreply.github.com> Date: Mon, 7 Jul 2025 12:44:39 -0400 Subject: [PATCH] Update for documentation and config of repo location --- .env.example | 24 ++++++++ Dockerfile | 25 ++++---- README.md | 79 ++++++++++++++++++++----- build.bat | 25 +++++++- build.sh | 42 ++++++++++--- docker-compose.yml | 10 ++-- docker-entrypoint.sh | 20 +++++++ generate-proxy-config.js | 43 ++++++++++++++ package.json | 5 +- proxy.conf.json | 2 +- src/app/app.component.html | 5 -- src/app/app.component.ts | 23 ++----- src/app/services/environment.service.ts | 49 +++++++++++++++ src/assets/env.js | 8 +++ src/index.html | 5 +- start-dev.bat | 48 +++++++-------- start-dev.sh | 40 ++++++------- unraid-template.xml | 8 +-- 18 files changed, 342 insertions(+), 119 deletions(-) create mode 100644 .env.example create mode 100644 docker-entrypoint.sh create mode 100644 generate-proxy-config.js create mode 100644 src/app/services/environment.service.ts create mode 100644 src/assets/env.js diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..cc16059 --- /dev/null +++ b/.env.example @@ -0,0 +1,24 @@ +# Docker Registry Browser Environment Configuration +# Copy this file to .env and update with your values + +# Registry host and port (without protocol) +REGISTRY_HOST=your-registry.example.com:5000 + +# Protocol to use for registry connection +REGISTRY_PROTOCOL=https + +# Optional: Registry authentication +REGISTRY_USERNAME=your-username +REGISTRY_PASSWORD=your-password + +# Development Examples: +# For local registry: REGISTRY_HOST=localhost:5000 +# For Harbor: REGISTRY_HOST=harbor.example.com +# For Docker Hub: REGISTRY_HOST=registry-1.docker.io (not typically needed) +# For AWS ECR: REGISTRY_HOST=123456789012.dkr.ecr.us-west-2.amazonaws.com + +# Development Usage: +# 1. Copy this file: cp .env.example .env +# 2. Edit .env with your registry details +# 3. Start development server: npm start +# 4. Or use convenience scripts: ./start-dev.sh diff --git a/Dockerfile b/Dockerfile index 8499507..e3fae63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ # Multi-stage build for optimized production image -FROM node:18-alpine as build +FROM node:18-alpine AS build # Set working directory WORKDIR /app # Copy package files and install dependencies COPY package*.json ./ -RUN npm ci --only=production --silent +RUN npm ci --silent # Copy source code COPY . . @@ -26,21 +26,22 @@ COPY --from=build /app/dist/docker-registry-browser /usr/share/nginx/html # Copy nginx configuration COPY nginx.conf /etc/nginx/nginx.conf -# Create nginx user and set permissions -RUN addgroup -g 1001 -S nginx && \ - adduser -S -D -H -u 1001 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx && \ +# Copy entrypoint script +COPY docker-entrypoint.sh /docker-entrypoint.sh +RUN chmod +x /docker-entrypoint.sh + +# Create assets directory for env.js and set permissions +RUN mkdir -p /usr/share/nginx/html/assets && \ chown -R nginx:nginx /usr/share/nginx/html && \ chown -R nginx:nginx /var/cache/nginx && \ chown -R nginx:nginx /var/log/nginx && \ - chown -R nginx:nginx /etc/nginx/conf.d - -# Switch to non-root user -USER nginx + chown -R nginx:nginx /etc/nginx/conf.d && \ + chmod -R 755 /usr/share/nginx/html # Add labels for better container management LABEL maintainer="Your Name " LABEL description="Docker Registry Browser - A web interface for browsing Docker registries" -LABEL version="1.1.0" +LABEL version="1.0.0" # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ @@ -49,5 +50,5 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ # Expose port EXPOSE 80 -# Start nginx -CMD ["nginx", "-g", "daemon off;"] +# Use custom entrypoint to generate environment config (run as root for file creation) +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/README.md b/README.md index ac03bea..cb2a2d4 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,12 @@ A modern, responsive web interface for browsing Docker registries with support f - Support for OCI and Docker v2 manifests - Multi-platform image support +## Prerequisites + +- Docker installed and running +- Access to a Docker registry (local or remote) +- Network connectivity to the registry + ## Quick Start ### Option 1: Docker Run @@ -24,13 +30,13 @@ docker run -d \ --add-host=host.docker.internal:host-gateway \ -e REGISTRY_HOST=localhost:5000 \ -e REGISTRY_PROTOCOL=http \ - your-dockerhub-username/docker-registry-browser:latest + programmingpug/docker-registry-browser:latest ``` ### Option 2: Docker Compose ```bash -git clone https://github.com/your-username/docker-registry-browser.git +git clone https://github.com/programmingPug/docker-registry-browser.git cd docker-registry-browser docker-compose up -d ``` @@ -38,7 +44,7 @@ docker-compose up -d ### Option 3: Build from Source ```bash -git clone https://github.com/your-username/docker-registry-browser.git +git clone https://github.com/programmingPug/docker-registry-browser.git cd docker-registry-browser docker build -t docker-registry-browser . docker run -d -p 8080:80 --add-host=host.docker.internal:host-gateway docker-registry-browser @@ -67,6 +73,26 @@ docker run -d -p 8080:80 --add-host=host.docker.internal:host-gateway docker-reg 2. Create a new compose stack with the provided `docker-compose.yml` 3. Deploy the stack +## Supported Registries + +This browser works with any Docker Registry v2 compatible registry, including: + +- **Local Docker Registry** - Self-hosted registry containers +- **Harbor** - Open source cloud native registry +- **AWS ECR** - Amazon Elastic Container Registry +- **Azure Container Registry** - Microsoft's container registry +- **Google Container Registry** - Google Cloud's container registry +- **GitLab Container Registry** - GitLab's integrated registry +- **Nexus Repository** - Sonatype's repository manager +- **Artifactory** - JFrog's universal repository manager +- **Docker Hub** - (limited support for browsing) + +### Registry Requirements + +- Docker Registry API v2 support +- CORS headers configured (for web access) +- Network accessibility from the browser container + ## Configuration ### Environment Variables @@ -126,26 +152,44 @@ docker run -d -p 8080:80 --add-host=host.docker.internal:host-gateway docker-reg ### Registry Connection Issues -**Problem**: Cannot connect to registry -**Solution**: -1. Verify `REGISTRY_HOST` is correct -2. Check if registry is accessible from container -3. For local registries, ensure `--add-host=host.docker.internal:host-gateway` is set +**Problem**: Cannot connect to registry +**Solutions**: +- Verify `REGISTRY_HOST` is correct (hostname:port format) +- Check if registry is accessible from container +- For local registries, ensure `--add-host=host.docker.internal:host-gateway` is set +- Test registry connectivity: `curl http://your-registry:5000/v2/` ### CORS Issues -**Problem**: API requests blocked by CORS -**Solution**: The nginx configuration includes CORS headers, but ensure your registry allows cross-origin requests +**Problem**: API requests blocked by CORS +**Solutions**: +- The nginx configuration includes CORS headers +- Ensure your registry allows cross-origin requests +- For development, use the included proxy configuration ### Authentication Issues -**Problem**: 401 Unauthorized errors -**Solution**: Set `REGISTRY_USERNAME` and `REGISTRY_PASSWORD` environment variables +**Problem**: 401 Unauthorized errors +**Solutions**: +- Set `REGISTRY_USERNAME` and `REGISTRY_PASSWORD` environment variables +- Verify credentials are correct for your registry +- Check if registry requires authentication ### Manifest Issues -**Problem**: "OCI index found" errors -**Solution**: This should be resolved in the current version which supports OCI manifests +**Problem**: "OCI index found" or manifest parsing errors +**Solutions**: +- Current version supports OCI manifests +- Ensure registry supports Docker Registry API v2 +- Check if image manifests are properly formatted + +### Port Conflicts + +**Problem**: Port 8080 already in use +**Solutions**: +- Change the host port: `-p 8081:80` instead of `-p 8080:80` +- Stop conflicting services or use different ports +- Check what's using the port: `netstat -tlnp | grep 8080` ## Development @@ -192,6 +236,13 @@ MIT License - see LICENSE file for details. ## Changelog +### v1.1.0 +- Updated Angular to v17 +- Improved error handling +- Enhanced UI/UX +- Better multi-platform support +- Optimized build process + ### v1.0.0 - Initial release - Support for Docker v2 and OCI manifests diff --git a/build.bat b/build.bat index baec619..efff65b 100644 --- a/build.bat +++ b/build.bat @@ -46,8 +46,18 @@ if %ERRORLEVEL% neq 0 ( echo. echo Build completed successfully! echo. -echo To run the container: -echo docker run -d --name docker-registry-browser -p 8080:80 --add-host=host.docker.internal:host-gateway %FULL_IMAGE_NAME% +echo To run the container with environment variables: +echo docker run -d --name docker-registry-browser ^ +echo -p 8080:80 ^ +echo --add-host=host.docker.internal:host-gateway ^ +echo -e REGISTRY_HOST=your-registry.com:5000 ^ +echo -e REGISTRY_PROTOCOL=https ^ +echo %FULL_IMAGE_NAME% +echo. +echo Or use docker-compose with .env file: +echo copy .env.example .env +echo # Edit .env with your values +echo docker-compose up -d echo. echo To push to registry (if configured): if "%REGISTRY%"=="" ( @@ -61,7 +71,16 @@ REM Optional: Run the container immediately set /p REPLY="Do you want to run the container now? (y/N): " if /i "%REPLY%"=="y" ( echo Starting container... - docker run -d --name docker-registry-browser -p 8080:80 --add-host=host.docker.internal:host-gateway -e REGISTRY_HOST=localhost:5000 -e REGISTRY_PROTOCOL=http "%FULL_IMAGE_NAME%" + + REM Check if .env file exists + if exist ".env" ( + echo Using .env file for configuration... + docker run -d --name docker-registry-browser -p 8080:80 --add-host=host.docker.internal:host-gateway --env-file .env "%FULL_IMAGE_NAME%" + ) else ( + echo No .env file found, using default values... + echo Copy .env.example to .env and edit it for your registry configuration. + docker run -d --name docker-registry-browser -p 8080:80 --add-host=host.docker.internal:host-gateway -e REGISTRY_HOST=localhost:5000 -e REGISTRY_PROTOCOL=http "%FULL_IMAGE_NAME%" + ) if %ERRORLEVEL% equ 0 ( echo. diff --git a/build.sh b/build.sh index f5cc872..b161a75 100644 --- a/build.sh +++ b/build.sh @@ -32,8 +32,18 @@ docker build -t "$FULL_IMAGE_NAME" . echo "" echo "Build completed successfully!" echo "" -echo "To run the container:" -echo "docker run -d --name docker-registry-browser -p 8080:80 --add-host=host.docker.internal:host-gateway $FULL_IMAGE_NAME" +echo "To run the container with environment variables:" +echo "docker run -d --name docker-registry-browser \\" +echo " -p 8080:80 \\" +echo " --add-host=host.docker.internal:host-gateway \\" +echo " -e REGISTRY_HOST=your-registry.com:5000 \\" +echo " -e REGISTRY_PROTOCOL=https \\" +echo " $FULL_IMAGE_NAME" +echo "" +echo "Or use docker-compose with .env file:" +echo "cp .env.example .env" +echo "# Edit .env with your values" +echo "docker-compose up -d" echo "" echo "To push to registry (if configured):" if [ -n "$REGISTRY" ]; then @@ -48,13 +58,27 @@ read -p "Do you want to run the container now? (y/N): " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then echo "Starting container..." - docker run -d \ - --name docker-registry-browser \ - -p 8080:80 \ - --add-host=host.docker.internal:host-gateway \ - -e REGISTRY_HOST=localhost:5000 \ - -e REGISTRY_PROTOCOL=http \ - "$FULL_IMAGE_NAME" + + # Check if .env file exists + if [ -f ".env" ]; then + echo "Using .env file for configuration..." + docker run -d \ + --name docker-registry-browser \ + -p 8080:80 \ + --add-host=host.docker.internal:host-gateway \ + --env-file .env \ + "$FULL_IMAGE_NAME" + else + echo "No .env file found, using default values..." + echo "Copy .env.example to .env and edit it for your registry configuration." + docker run -d \ + --name docker-registry-browser \ + -p 8080:80 \ + --add-host=host.docker.internal:host-gateway \ + -e REGISTRY_HOST=localhost:5000 \ + -e REGISTRY_PROTOCOL=http \ + "$FULL_IMAGE_NAME" + fi echo "" echo "Container started successfully!" diff --git a/docker-compose.yml b/docker-compose.yml index 4264121..ef12a26 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,12 +8,12 @@ services: ports: - "8080:80" environment: - # Registry configuration - - REGISTRY_HOST=host.docker.internal:5000 - - REGISTRY_PROTOCOL=http + # Registry configuration - update these values + - REGISTRY_HOST=${REGISTRY_HOST:-localhost:5000} + - REGISTRY_PROTOCOL=${REGISTRY_PROTOCOL:-http} # Optional: Basic auth if your registry requires it - # - REGISTRY_USERNAME=username - # - REGISTRY_PASSWORD=password + - REGISTRY_USERNAME=${REGISTRY_USERNAME:-} + - REGISTRY_PASSWORD=${REGISTRY_PASSWORD:-} extra_hosts: # For accessing host services (like local registry) - "host.docker.internal:host-gateway" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..c16954b --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# Generate environment configuration for Docker Registry Browser +# This script is run at container startup to inject environment variables + +# Create env.js with environment variables +cat < /usr/share/nginx/html/assets/env.js +window.env = { + REGISTRY_HOST: '${REGISTRY_HOST:-localhost:5000}', + REGISTRY_PROTOCOL: '${REGISTRY_PROTOCOL:-http}', + REGISTRY_USERNAME: '${REGISTRY_USERNAME:-}', + REGISTRY_PASSWORD: '${REGISTRY_PASSWORD:-}' +}; +EOF + +echo "Environment configuration generated:" +cat /usr/share/nginx/html/assets/env.js + +# Start nginx +exec nginx -g 'daemon off;' diff --git a/generate-proxy-config.js b/generate-proxy-config.js new file mode 100644 index 0000000..6ae0568 --- /dev/null +++ b/generate-proxy-config.js @@ -0,0 +1,43 @@ +const fs = require('fs'); +const path = require('path'); + +// Get registry configuration from environment variables +const registryHost = process.env.REGISTRY_HOST || 'localhost:5000'; +const registryProtocol = process.env.REGISTRY_PROTOCOL || 'http'; +const registryUrl = `${registryProtocol}://${registryHost}`; + +console.log(`Configuring proxy for registry: ${registryUrl}`); + +// Create dynamic proxy configuration +const proxyConfig = { + "/api/*": { + "target": registryUrl, + "secure": registryProtocol === 'https', + "changeOrigin": true, + "logLevel": "debug", + "headers": { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, OPTIONS", + "Access-Control-Allow-Headers": "Content-Type, Authorization" + }, + "pathRewrite": { + "^/api": "" + } + } +}; + +// Add basic auth if credentials are provided +if (process.env.REGISTRY_USERNAME && process.env.REGISTRY_PASSWORD) { + const auth = Buffer.from(`${process.env.REGISTRY_USERNAME}:${process.env.REGISTRY_PASSWORD}`).toString('base64'); + proxyConfig["/api/*"].headers.Authorization = `Basic ${auth}`; + console.log('Added basic authentication to proxy'); +} + +// Write the configuration file +const configPath = path.join(__dirname, 'proxy.conf.json'); +fs.writeFileSync(configPath, JSON.stringify(proxyConfig, null, 2)); + +console.log('Proxy configuration updated successfully'); +console.log('Configuration:', JSON.stringify(proxyConfig, null, 2)); + +module.exports = proxyConfig; diff --git a/package.json b/package.json index 7d0ae5d..a900d1a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "version": "1.1.0", "scripts": { "ng": "ng", - "start": "ng serve --proxy-config proxy.conf.json", + "start": "node generate-proxy-config.js && ng serve --proxy-config proxy.conf.json", + "start:dev": "npm run start", "build": "ng build", "watch": "ng build --watch --configuration development", "serve": "ng serve --host 0.0.0.0 --port 4200" @@ -31,4 +32,4 @@ "@types/node": "^18.7.0", "typescript": "~5.2.0" } -} \ No newline at end of file +} diff --git a/proxy.conf.json b/proxy.conf.json index d780b54..ee46ac4 100644 --- a/proxy.conf.json +++ b/proxy.conf.json @@ -1,6 +1,6 @@ { "/api/*": { - "target": "http://192.168.1.193:5000", + "target": "http://localhost:5000", "secure": false, "changeOrigin": true, "logLevel": "debug", diff --git a/src/app/app.component.html b/src/app/app.component.html index 89c7646..b314f76 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -5,11 +5,6 @@ Docker Registry Browser - - -