diff --git a/.env.development b/.env.development deleted file mode 100644 index a9b159d..0000000 --- a/.env.development +++ /dev/null @@ -1,25 +0,0 @@ -# Environment Configuration for Reverse Proxy Architecture -# Copy this file to .env, .env.development, or .env.production and fill in your values - -# Instance Configuration -INSTANCE_NAME=wacraftlink # Unique identifier for the service instance (alphanumeric, hyphens, underscores only) - -# Internal Service Container Configuration -INTERNAL_SERVICE_PORT=3000 # Port exposed by the target Docker container (e.g., 3000) -DOCKER_NETWORK=traefik_domain_proxy # Docker network for connecting to internal service container - -# FRP Server Configuration -# Public IP address of the FRP server -FRP_SERVER_ADDR=199.241.138.188 # tf ssd -#FRP_SERVER_ADDR=54.169.179.106 # wacraftlink AWS -FRP_SERVER_PORT=16999 # Port for FRP communication (default 16999) - -# Domain Configuration -# Public domain for Traefik routing -#DOMAIN_NAME=t1.wacraftlink.com.hk # Testing -DOMAIN_NAME=www.wacraftlink.com.hk # production - -# Proxy Configuration - Remote ports for external access -#PROXY_RAD_PORT=8779 # Remote port for rad proxy (default 8779, use 8776 if following standard) -#PROXY_SSH_PORT=13076 # Remote port for SSH proxy (default 13076) -PROXY_WEB_PORT=12077 # Remote port for web proxy - accessible via domain (default 13077) \ No newline at end of file diff --git a/.env.sample b/.env.sample index b56d68e..7cdb5b8 100644 --- a/.env.sample +++ b/.env.sample @@ -69,3 +69,4 @@ TARGET_SERVICE_PORT=3000 # Port the application service is listen # Traefik configuration TRAEFIK_VER=v3.5.4 # Traefik Docker image version to use LETSENCRYPT_EMAIL=admin@yourdomain.com # Email for Let's Encrypt certificate registration +RESTART_TRAEFIK=false # Set to 'true' to restart Traefik after configuration (default: false for dynamic loading) \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1dc9f94 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# .env +.env* +# Code Parameters Sample +!.envSample diff --git a/Design_Doc/DevProc.md b/Design_Doc/DevProc.md index b46e7e1..ffe649f 100644 --- a/Design_Doc/DevProc.md +++ b/Design_Doc/DevProc.md @@ -7,6 +7,10 @@ ## a Demo to create a new application base the current architecture design ## make a generic rvs-prxy system + +- i find `setup_traefik_only()` and `create_traefik_container_on_target()` have similar function as **Post-Execution Command Reference**, it seems duplicated. Analysis both, then merge all fucntions into one. By the way, regarding **Post-Execution Command Reference**, reference from `/ws/repos/auto/autoSysDepl/Design_Doc/DevProc.md` -> Section "Creating Automated Script to Setup an Environment" -> "Common content for a auto. script" -> "Automated Development Environment Provisioning via `auto-sys-deploy.sh`" -> "Post-Execution Command Reference" to implement current **Post-Execution Command Reference**, such as: "Run Container locally" cmd. + - i find `show_traefik_commands()` which shows the "Post-Execution Command Reference", it is called by `setup_traefik_only()` and `create_traefik_container_on_target()`. Why does it need to show up twice time to user? Improve the code, the "Post-Execution Command Reference" should show once when you complete all tasks. + - Implement what we discussed we summary at `Design_Doc/*.md` files. You now implement this script code following all we discussed into `auto-sys-deploy.sh` beside the `.env.development` which as the parameters we aim to passing in. - 1) I rename the file name of implmentation of script from `instructions.md` to `implement_script.md`; 2) i have a wrong assumption before as at any computer. It is wrong, end-user runs the script (we are now workinig on it) must be same computer to the mentioned service which opens the port "INTERNAL_SERVICE_PORT", and connect to it by docker network "DOCKER_NETWORK"; 3) i do not download manually, i aim to run the script by this way as download and run: `ssh -i ~/.ssh/itl-devs1 -o StrictHostKeyChecking=accept-new -p 13076 ubuntu@cmty-repos2.ivantito.com "cat /repos/repos/cmptr-infra/rvs-prxy/auto-sys-deploy.sh" bash -s -- setup-rvs-prxy` or another server as `ssh -i ~/.ssh/itl-devs1 -o StrictHostKeyChecking=accept-new -p 13072 ubuntu@cmty-repos1.ivantito.com "cat /wws/repos/cmptr-infra/rvs-prxy/auto-sys-deploy.sh" bash -s -- setup-rvs-prxy`, 4) i mentioned end-user must well prepare the `.env*` (using .env.development as example at this moment); 5) modify the `auto-sys-deploy.sh` and corresponding doc. at `Design_Doc/*.md` files. - Reference `Design_Doc\auto-sys-deploy-ref.sh` and `Design_Doc\update-compose-config-ref.sh`, We merged the these two script into ONE script `auto-sys-deploy.sh`. Re-verify the merge of code to form finally `auto-sys-deploy.sh`. After this merge, then we do not need `SCRIPT_PATH` and `DOWNLOAD_SOURCE` any more, remove these two variables from `auto-sys-deploy.sh` and any documents. @@ -180,4 +184,5 @@ - etc. ## Understand how previous to do +- From `.env.sample` or `.env.development` -> `INSTANCE_NAME` variable, find out the purpose of this variable in this project, then explain to me. - Analysis and explain these two scripts to me: `auto-sys-deploy-ref.sh` and `update-compose-config-ref.sh`; Write your explaination into `Design_Doc/auto-sys-deploy.sh.md` and `Design_Doc/update-compose-config.sh.md` corresponding. \ No newline at end of file diff --git a/Design_Doc/tech/traefik/DevProc.md b/Design_Doc/tech/traefik/DevProc.md index 2b496f9..0a00778 100644 --- a/Design_Doc/tech/traefik/DevProc.md +++ b/Design_Doc/tech/traefik/DevProc.md @@ -1,6 +1,21 @@ ## Init. to setup traefik ### With local App., skip frp + +- I aim one Target Server has one unique Traefik instance running only -- container name as traefik, and its data volume name as traefik_data, they are all fixed names in one Target Server. Since no >1 instance of traefik can run in one Target Server instance. So if Traefik does not exist, will create it dynmaically, Otherwise, use exsiting one including all container and volume. Write down this issue by using "Documentation Architecture" from `/ws/repos/auto/autoSysDepl/Design_Doc/DevProc.md` -> Section "Creating Automated Script to Setup an Environment" -> "Common content for a auto. script" -> "Documentation". + - I mean to write down the above concept (your just wrote at /ws/repos/auto/autoSysDepl/Design_Doc/traefik_single_instance.md) into `/ws/repos/cmptr-infra/rvs-prxy` project by applying the approach from "Documentation Architecture" from `/ws/repos/auto/autoSysDepl/Design_Doc/DevProc.md` -> Section "Creating Automated Script to Setup an Environment" -> "Common content for a auto. script" -> "Documentation". So, re-write into rvs-prxy project. Then, i aim to implement he above concept into `auto-sys-deploy.sh` code too. + - When the traefik is at Target Server, we do not need to setup again, since it is one unique traefik at one Target Server. Further, i aim to do not need to restart traefik in default, since traefik has dynamical loading. Add a new parameter flag into `.env` (update corresponding `.envSample`) for restart or not, default as do not need to restart. + + - I see the output log as following: + ``` + ... + [INFO] Traefik container 'traefik' created/updated and started successfully on target server using image: traefik:v3.5.4 with volume: traefik_data + ... + ``` + - that it seems traefik is still restarted even the `.env` with `RESTART_TRAEFIK=false`. My original meaning as `RESTART_TRAEFIK=false`, then no Traefik container restart. + - Result -- the Traefik container already exists on the target server, it won't be + recreated or restarted, regardless of the RESTART_TRAEFIK setting. The RESTART_TRAEFIK parameter still controls whether to restart after configuring application services (which is handled in the configure_traefik_on_target function). + - Current codebase is as `Design_Doc\architecture.md` -> Section "Architecture Block Diagram", which is current code `auto-sys-deploy.sh` and `.env.example` with `.env.development`. I aim to convert to `README.md` -> Section "Architecture". - First we do not do too many modification, just keep the old code there, only skip to run them. - The new code base from `README.md` -> Section "Architecture" as: We aim to handle the target as "Proxy Server". So modify the `.env.example` with `.env.development` which reference `.env.deploy.eg` and `.envDeploySample`, includes: Target server information, SSH key file name, Destination path for host or docker volume folder, Docker volume name in case using docker volume; This information is for "Target Proxy Server" connection. Reference `deploy.eg.sh` with those `.env` file for connecting to "Target Proxy Server". diff --git a/Design_Doc/tech/traefik/traefik_single_instance.md b/Design_Doc/tech/traefik/traefik_single_instance.md new file mode 100644 index 0000000..9dbfad0 --- /dev/null +++ b/Design_Doc/tech/traefik/traefik_single_instance.md @@ -0,0 +1,134 @@ +# Single Traefik Instance Per Target Server - Documentation Architecture + +## Problem Statement + +The current reverse proxy system implementation in the rvs-prxy project allows multiple Traefik instances to run on a single Target Server, which violates the architectural requirement for a unique Traefik instance per server. The system should ensure: +- Container name is always `traefik` +- Data volume name is always `traefik_data` +- Only one instance runs per Target Server +- If Traefik doesn't exist, create it dynamically +- If Traefik exists, use the existing container and volume + +## Current Implementation Issue + +In the current `rvs-prxy/auto-sys-deploy.sh` implementation, when `FRP=false` (Traefik mode), the script creates Traefik containers and volumes using the `INSTANCE_NAME` as a prefix: + +```bash +# Current approach creates: +# - Container: ${INSTANCE_NAME}-traefik (from THIS_INSTANCE variable) +# - Volume: ${INSTANCE_NAME}-traefik_data (from THIS_INSTANCE-traefik_data) +``` + +This approach allows multiple Traefik deployments on the same target server, leading to: +- Port conflicts on standard ports (80, 443, 8080) +- Resource duplication and inefficient utilization +- Management complexity with multiple instances +- Potential routing conflicts + +## Proposed Solution Architecture + +### Traefik Instance Management Logic + +The system must implement a check-and-reuse approach before creating Traefik resources: + +```bash +# Pseudo-code implementation +IF Traefik container exists (named "traefik") THEN + USE existing container +ELSE + CREATE new container with name "traefik" +ENDIF + +IF Traefik volume exists (named "traefik_data") THEN + USE existing volume +ELSE + CREATE new volume with name "traefik_data" +ENDIF +``` + +### Container Configuration Requirements +- **Container Name**: Fixed as "traefik" (not using INSTANCE_NAME prefix) +- **Restart Policy**: `unless-stopped` for high availability +- **Port Mapping**: Standard ports 80, 443, 8080 (dashboard on localhost only) +- **Volume Mounts**: `/var/run/docker.sock` for Docker provider, `traefik_data` for persistence + +### Volume Configuration Requirements +- **Volume Name**: Fixed as "traefik_data" (not using INSTANCE_NAME prefix) +- **Purpose**: Store ACME certificates, dynamic configurations, and runtime data +- **Permissions**: Ensure proper ownership (1000:1000) for certificate files +- **Persistence**: Maintain across container restarts and updates + +### Dynamic Configuration Management +Instead of multiple Traefik instances, each new application should be configured as a dynamic configuration within the single instance: + +- Store application-specific routing in `/etc/traefik/config/` within the shared volume +- Use Traefik's file provider to load configurations dynamically +- Name configuration files uniquely to avoid conflicts +- Restart Traefik only when necessary to load new configurations + +## Implementation Integration with Existing Script + +### Integration with Current Script Logic +The implementation must extend the existing foundation while ensuring the container and volume names remain fixed: + +- Modify the `create_traefik_container_on_target` function to use fixed names +- Update volume creation to use `traefik_data` instead of `${THIS_INSTANCE}-traefik_data` +- Preserve existing Traefik configuration and docker-compose generation logic +- Maintain compatibility with existing parameters in `.env*` files + +### SSH Connection Configuration +Since the rvs-prxy script operates in Traefik mode by connecting to a target server via SSH, the implementation must: +- Execute container and volume checks via SSH commands on the target server +- Use SSH to create or verify existing Traefik resources +- Maintain existing SSH connection patterns and authentication methods +- Preserve the existing `ssh_exec` and `scp_upload` functions + +### Docker Resource Translation Rules Adjustment +- Modify volume creation to use fixed name `traefik_data` instead of prefixed names +- Update container creation to use fixed name `traefik` +- Maintain all other volume, network, and port configuration patterns + +### Container Auto-Restart Policy Enforcement +- The `restart: unless-stopped` policy must be applied to the fixed-name container +- This ensures the unique Traefik instance remains available across host reboots + +## Verification and Testing Approach + +### Pre-Deployment Verification +- Check if container named "traefik" exists on target system via SSH +- Verify if volume named "traefik_data" exists on target system via SSH +- Confirm existing Traefik instance is operational (if present) +- Validate port availability for Traefik (80, 443, 8080) + +### Post-Deployment Verification +- Confirm "traefik" container is running with expected configuration +- Verify application routing is correctly configured within Traefik +- Test application accessibility via configured domain +- Validate SSL certificate acquisition if applicable + +## Security and Access Considerations + +### SSH Connection Configuration +- Maintain existing SSH connection patterns to target server +- Ensure secure file transfer of configuration files to target server +- Preserve SSH key authentication and fallback mechanisms +- Use existing `ssh_exec` function for all remote operations + +### Network Security +- Restrict Traefik dashboard access to localhost only (127.0.0.1:8080) +- Maintain existing network integration patterns +- Ensure secure communication between application and Traefik containers + +## Error Handling and Recovery + +### Failure Scenarios +- Handle cases where fixed-name container already exists but with different configuration +- Implement proper error messages for port conflicts +- Provide clear guidance when existing Traefik instance is incompatible +- Enable graceful fallback when volume creation fails + +### Recovery Procedures +- Document manual cleanup procedures for inconsistent states +- Provide restart commands for the fixed-name Traefik container +- Include volume inspection and cleanup commands +- Maintain existing troubleshooting patterns from the script \ No newline at end of file diff --git a/README.md b/README.md index 9d5873f..e61ff1d 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,26 @@ ## Purpose: Setup Reverse Proxy for your Application ``` +----------------------------+ -+---------------------+ | | -| Any your computer | | Target Server | -| | | | -| +-------------+ | | +-----------------------+ | -| | | | Setup Reverse Proxy | | | | -| | This +-------------------------------->| Reverse Proxy Setting | | -| | Automatical | | for your existing | | eg. www.domain.com | | -| | System |<-+ | application | | | | -| | | | | | +------++---------------+ | -| +-------------+ | | | | | -| | | | v | -| .env | | +-------------+ | -| | | | | | -+---------------------+ | | Existing | | + | Target Server | + | | + | +---------+ | + | | | | + | | Traefik | | ++---------------------+ | | | | +| Any Linux Computer | | +---------+ | +| | | ^ | +| +-------------+ | | | | +| | | | Setup Reverse Proxy | +----+------------------+ | +| | This +-----+------------------------+->| | | +| | Automatical | | for your existing | | Reverse Proxy Setting | | +| | System |<-+ | application | | eg. www.domain.com | | +| | | | | | | | | +| +-------------+ | | | +------+----------------+ | +| | | | | | +| .env | | v | +| | | +-------------+ | ++---------------------+ | | | | + | | Existing | | | | Application | | | | | | | +-------------+ | @@ -22,6 +28,9 @@ +----------------------------+ ``` - .env -- **parameters for your Application, Reverse Proxy and Target information** +- Assume your "Application" is already existing. +- If Traefik does not exist, will create it dynmaically, Otherwise, use exsiting one. + - Remark: one Target Server has one unique Traefik instance running -- container name as traefik. - All Application(s) must connect to docker network name **traefik-public** for container connection by expose port(s). ## Architecture diff --git a/auto-sys-deploy.sh b/auto-sys-deploy.sh index 2d6d0a4..986c03b 100755 --- a/auto-sys-deploy.sh +++ b/auto-sys-deploy.sh @@ -35,7 +35,6 @@ SSH_KEY_FILE_NAME="" SSH_KEY_PATH="" LOCAL_FOLDER="../out/" DEST_PATH="/" -#USE_DOCKER_VOLUME="false" DEBUG="false" TARGET_SERVICE_NAME="" TARGET_SERVICE_PORT="" @@ -844,12 +843,80 @@ create_traefik_container_on_target() { local container_exists container_exists=$(ssh_exec "docker ps -a --filter name=traefik --format '{{.Names}}' 2>/dev/null || true") - if [ -n "$container_exists" ] && [ "$container_exists" = "traefik" ]; then - log_info "Traefik container already exists on target server" - return 0 - fi + # Use fixed container name "traefik" regardless of instance name + local TRAEFIK_CONTAINER_NAME="traefik" - log_info "Creating Traefik container on target server..." + # Use fixed volume name "traefik_data" regardless of instance name + local TRAEFIK_VOLUME_NAME="traefik_data" + + if [ -n "$container_exists" ] && [ "$container_exists" = "$TRAEFIK_CONTAINER_NAME" ]; then + log_info "Traefik container '$TRAEFIK_CONTAINER_NAME' already exists on target server" + # Only update the config files in the volume, don't recreate the container + log_info "Updating configuration in existing Traefik container..." + + # Use specified Traefik version or default to v3.5.4 + local TRAEFIK_VER="${TRAEFIK_VER:-v3.5.4}" + local TRAEFIK_IMAGE="traefik:$TRAEFIK_VER" + + # Use specified Let's Encrypt email or default + local LETSENCRYPT_EMAIL="${LETSENCRYPT_EMAIL:-admin@yourdomain.com}" + + # Create a minimal dynamic configuration file for the dashboard and basic routing, plus HTTP to HTTPS redirect + local temp_config="/tmp/traefik-$$.yml" + cat > "$temp_config" << 'EOF_HEREDOC' +http: + routers: + api: + rule: "PathPrefix(`/api`)" + service: api@internal + dashboard: + rule: "PathPrefix(`/dashboard`)" + service: api@internal + http-catchall: + rule: "PathRegexp(`{any:.*}`)" + entryPoints: + - "web" + service: "noop@internal" + middlewares: + - "redirect-to-https" + middlewares: + api-headers: + headers: + customFrameOptionsValue: SAMEORIGIN + contentTypeNosniff: true + browserXssFilter: true + stsIncludeSubdomains: true + stsPreload: true + stsSeconds: 15552000 + redirect-to-https: + redirectScheme: + scheme: "https" + permanent: true +EOF_HEREDOC + + # Upload the configuration to target server + scp_upload "$temp_config" "/tmp/traefik.yml" + rm -f "$temp_config" + + # Copy the configuration file and create necessary directories in the volume with proper permissions + ssh_exec "docker run --rm -v $TRAEFIK_VOLUME_NAME:/etc/traefik -v /tmp:/tmp alpine:latest sh -c 'mkdir -p /etc/traefik/config /etc/traefik/acme && cp /tmp/traefik.yml /etc/traefik/config/traefik.yml && touch /etc/traefik/acme/acme.json && chmod 600 /etc/traefik/acme/acme.json'" + + log_info "Configuration updated in existing Traefik container" + + # Exit early since container already exists and configuration was updated + log_info "Traefik container '$TRAEFIK_CONTAINER_NAME' is running on target server using image: $TRAEFIK_IMAGE with volume: $TRAEFIK_VOLUME_NAME" + + # Wait a bit for the container to start/update + sleep 3 + + # Commands will be shown at the end of setup_traefik_only() + return 0 + else + log_info "Creating Traefik container '$TRAEFIK_CONTAINER_NAME' on target server..." + + # Create the Docker volume for persistent data using fixed name + ssh_exec "docker volume create $TRAEFIK_VOLUME_NAME" + fi # Use specified Traefik version or default to v3.5.4 local TRAEFIK_VER="${TRAEFIK_VER:-v3.5.4}" @@ -858,12 +925,6 @@ create_traefik_container_on_target() { # Use specified Let's Encrypt email or default local LETSENCRYPT_EMAIL="${LETSENCRYPT_EMAIL:-admin@yourdomain.com}" - # Create volume name using INSTANCE_NAME - local TRAEFIK_VOLUME_NAME="${THIS_INSTANCE}-traefik_data" - - # Create the Docker volume for persistent data - ssh_exec "docker volume create $TRAEFIK_VOLUME_NAME" - # Create a minimal dynamic configuration file for the dashboard and basic routing, plus HTTP to HTTPS redirect local temp_config="/tmp/traefik-$$.yml" cat > "$temp_config" << 'EOF_HEREDOC' @@ -927,7 +988,7 @@ $compose_version_field services: traefik: image: $TRAEFIK_IMAGE - container_name: traefik + container_name: $TRAEFIK_CONTAINER_NAME restart: unless-stopped command: - '--api.insecure=true' @@ -970,7 +1031,7 @@ EOF services: traefik: image: $TRAEFIK_IMAGE - container_name: traefik + container_name: $TRAEFIK_CONTAINER_NAME restart: unless-stopped command: - '--api.insecure=true' @@ -1037,29 +1098,12 @@ EOF # Start Traefik container using appropriate command ssh_exec "$compose_cmd -f /tmp/traefik-compose.yml up -d" - log_info "Traefik container created and started successfully on target server using image: $TRAEFIK_IMAGE with volume: $TRAEFIK_VOLUME_NAME" + log_info "Traefik container '$TRAEFIK_CONTAINER_NAME' is running on target server using image: $TRAEFIK_IMAGE with volume: $TRAEFIK_VOLUME_NAME" # Wait a bit for the container to start sleep 3 - # Show helpful commands to the user - log_info "" - log_info "================================" - log_info "Traefik setup completed! Some useful commands:" - log_info "" - log_info "View logs: docker logs --tail 50 traefik" - log_info "Execute in container: docker exec -it traefik /bin/sh" - log_info "Check status: docker ps --filter name=traefik" - log_info "View container details: docker inspect traefik" - log_info "View recent logs: docker logs --tail 10 traefik" - log_info "" - log_info "Traefik Dashboard: http://localhost:8080 (only accessible locally for security)" - log_info "Application should now be accessible via: https://$DOMAIN_NAME" - log_info "" - log_info "Totally Remove (Pay Attention):" - log_info " docker rm -f traefik" - log_info " docker volume rm $TRAEFIK_VOLUME_NAME" - log_info "================================" + # Commands will be shown at the end of setup_traefik_only() } # Function to upload files to target server via SCP (Traefik Mode) @@ -1193,24 +1237,34 @@ EOF local domain_base=$(echo "$DOMAIN_NAME" | cut -d'/' -f1) local config_file_name="app-service-${domain_base}-${TARGET_SERVICE_NAME//[^a-zA-Z0-9]/-}.yml" + # Use fixed volume name for Traefik configuration + local TRAEFIK_VOLUME_NAME="traefik_data" + # Check if a config file already exists for this domain and service combination local config_exists - config_exists=$(ssh_exec "docker run --rm -v ${THIS_INSTANCE}-traefik_data:/etc/traefik alpine:latest ls -la /etc/traefik/config/ 2>/dev/null | grep '$config_file_name' || true") + config_exists=$(ssh_exec "docker run --rm -v ${TRAEFIK_VOLUME_NAME}:/etc/traefik alpine:latest ls -la /etc/traefik/config/ 2>/dev/null | grep '$config_file_name' || true") if [ -n "$config_exists" ]; then log_warn "Configuration file $config_file_name already exists, it will be overwritten" fi # Copy the configuration file into the volume using a temporary container - ssh_exec "docker run --rm -v ${THIS_INSTANCE}-traefik_data:/etc/traefik -v /tmp:/tmp alpine:latest sh -c \"cp /tmp/app-service.yml /etc/traefik/config/$config_file_name\"" + ssh_exec "docker run --rm -v ${TRAEFIK_VOLUME_NAME}:/etc/traefik -v /tmp:/tmp alpine:latest sh -c \"cp /tmp/app-service.yml /etc/traefik/config/$config_file_name\"" log_info "Added configuration for service ${TARGET_SERVICE_NAME} on domain $domain_base to Traefik (file: $config_file_name)" # Connect the traefik container to the traefik-public network to ensure communication ssh_exec "docker network connect traefik-public traefik 2>/dev/null || true" - # Restart Traefik to apply the new configuration - ssh_exec "docker restart traefik" + # Check if restart is needed based on environment variable (default: false for dynamic loading) + if [ "${RESTART_TRAEFIK:-false}" = "true" ]; then + # Restart Traefik to apply the new configuration + ssh_exec "docker restart traefik" + log_info "Traefik restarted to apply new configuration" + else + log_info "Traefik dynamic configuration added (restart not performed, Traefik should auto-load the configuration)" + log_info "If needed, you can manually restart Traefik with: docker restart traefik (on target server)" + fi log_info "Traefik configured to route traffic to Application Service" @@ -1762,23 +1816,9 @@ setup_traefik_only() { log_info "Traefik-only proxy setup completed successfully!" log_info "Your service should now be accessible via: https://$DOMAIN_NAME" - log_info "" - log_info "================================" - log_info "Traefik is now configured to proxy your application. Some useful commands:" - log_info "" - log_info "View logs: docker logs --tail 50 traefik" - log_info "Execute in container: docker exec -it traefik /bin/sh" - log_info "Check status: docker ps --filter name=traefik" - log_info "View container details: docker inspect traefik" - log_info "View recent logs: docker logs --tail 10 traefik" - log_info "" - log_info "Traefik Dashboard: http://localhost:8080 (only accessible locally for security)" - log_info "Your application is accessible via: https://$DOMAIN_NAME" - log_info "" - log_info "Totally Remove (Pay Attention):" - log_info " docker rm -f traefik" - log_info " docker volume rm ${THIS_INSTANCE}-traefik_data" - log_info "================================" + + # Show helpful commands to the user using unified function + show_traefik_commands } # Setup rvs-prxy function (main function that decides FRP vs Traefik) @@ -2009,5 +2049,47 @@ prompt_domain_name() { echo "$domain_name" } +# Function to display post-execution command reference for Traefik +show_traefik_commands() { + local domain_name="${DOMAIN_NAME:-your-domain.com}" + + echo "" + echo "=============================================" + echo "Container Operation Commands (Traefik Instance)" + echo "" + echo "Configuration Note:" + echo " By default, Traefik does not restart after configuration (RESTART_TRAEFIK=false)" + echo " Traefik will dynamically load new configurations automatically." + echo " Set RESTART_TRAEFIK=true in .env to force restart after configuration." + echo "" + echo "Run Container locally:" + echo " # Use the stored docker-compose.yml from volume" + echo " # First try to copy with 1000:1000 ownership, fallback to default if chown fails" + echo " docker run -d --name traefik --restart=unless-stopped \\" + echo " -p 80:80 -p 443:443 -p 127.0.0.1:8080:8080 \\" + echo " -v /var/run/docker.sock:/var/run/docker.sock:ro \\" + echo " -v traefik_data:/etc/traefik traefik:latest" + echo "" + echo "Restart Container: docker restart traefik" + echo "------------------------------------------------------------" + echo "Container Accessing by ubuntu: docker exec -it traefik /bin/sh" + echo "Container Accessing by root: docker exec -it -u root traefik /bin/sh" + echo "------------------------------------------------------------" + echo "View the Logs: docker logs --tail 50 traefik" + echo "------------------------------------------------------------" + echo "Inspect: docker inspect traefik" + echo "------------------------------------------------------------" + echo "Remove Container: docker rm -f traefik" + echo "------------------------------------------------------------" + echo "View Traefik Dashboard: http://localhost:8080 (only accessible locally for security)" + echo "------------------------------------------------------------" + echo "Your application is accessible via: https://$domain_name" + echo "------------------------------------------------------------" + echo "Totally Remove (Pay Attention):" + echo " docker rm -f traefik" + echo " docker volume rm traefik_data" + echo "=============================================" +} + # Execute main function with arguments main "$@" \ No newline at end of file