rvs-prxy/Design_Doc/update-compose-config.sh.md

83 lines
3.6 KiB
Markdown

# update-compose-config.sh Documentation
## Overview
The `update-compose-config.sh` script is designed to update the `docker-compose.app.yml` file on a proxy server, specifically for managing FRP (Fast Reverse Proxy) server configurations. It adds or updates port mappings and Traefik labels for new or existing instances, and can optionally restart the Docker Compose service.
## Features
- Command-line argument parsing for configuration parameters
- Port configuration management in docker-compose files
- Traefik label configuration for HTTP/HTTPS routing
- Backup creation before making changes
- Status checking (not_found, up_to_date, outdated, incomplete)
- Automatic service restart capability
- Safe configuration updates with validation
## Functions
### Core Functions
- `parse_args()`: Parses command-line arguments to configure instance parameters
- `check_ports_config_status()`: Checks if ports configuration is current
- `check_labels_config_status()`: Checks if labels configuration is current
- `update_ports_config()`: Updates or adds port mappings in the compose file
- `update_labels_config()`: Updates or adds Traefik labels in the compose file
- `restart_docker_compose()`: Restarts the Docker Compose service
### Utility Functions
- `usage()`: Displays help information and usage examples
- `find_section_insertion_point()`: Determines where to insert new configurations
- `update_compose_config()`: Main function that coordinates all updates
## Usage
```
./update-compose-config.sh [OPTIONS]
Options:
-f, --file FILE Path to docker-compose.app.yml (default: /data/ssd/rvs-prxy/frps/apps/zzthis/docker-compose.app.yml)
-i, --instance NAME Instance name for the configuration
-r, --rad-port PORT Remote port for rad proxy
-s, --ssh-port PORT Remote port for ssh proxy
-w, --web-port PORT Remote port for web proxy
-d, --domain DOMAIN Domain name for Traefik routing
-h, --help Show this help message
Example:
./update-compose-config.sh -i myinstance -r 8779 -s 13076 -w 13077 -d example.com
```
## Parameters
- **COMPOSE_FILE**: Path to the docker-compose.app.yml file (default: `/data/ssd/rvs-prxy/frps/apps/zzthis/docker-compose.app.yml`)
- **INSTANCE_NAME**: Name of the instance being configured
- **RAD_PORT**: Remote port for rad proxy
- **SSH_PORT**: Remote port for SSH proxy
- **WEB_PORT**: Remote port for web proxy
- **DOMAIN_NAME**: Domain name for Traefik routing rules
## Configuration Sections
The script manages two main configuration sections in the docker-compose file:
### Ports Section
- Adds port mappings in the format: `<REMOTE_PORT>:<REMOTE_PORT>/tcp`
- Marked with comment markers for easy identification and updates
### Labels Section
- Configures Traefik routing rules for HTTP and HTTPS
- Sets up TLS with Let's Encrypt certificate resolver
- Configures load balancer to route to the appropriate web port
## Architecture
The script uses strategic comment markers to identify and update specific sections:
- `# <instance> Self-hosting ports ====`
- `# <instance> Self-hosting labels ====`
- `# =========================`
This allows for precise updates without affecting other configurations in the file.
## Safety Features
- Creates timestamped backups before making changes
- Validates required arguments before proceeding
- Checks configuration status before updating
- Provides option to restart services after configuration
- Safe insertion and removal of configuration blocks
## Service Restart
The script can optionally restart the Docker Compose service after making changes, with support for custom start/stop scripts or standard docker-compose commands.