For the complete documentation index, see llms.txt. This page is also available as Markdown.

Enable auto-upgrades for existing Docker Delegates

Learn how to migrate existing Docker delegates to enable automatic upgrades using the Docker Delegate Upgrader script.

Harness now supports automatic upgrades for Docker delegates using the Docker Delegate Upgrader. If you have already running Docker delegates, you can use the script provided below to enable the upgrader for your delegates.

The following approach will only be applicable to Docker delegates that were brought up directly using the docker run command and not for the ones that were started using Docker Compose, Docker Swarm etc.

How It Works

This script performs the following actions:

  1. Identifies Harness delegates with the DELEGATE_NAME environment variable. If this environment variable is not set, upgrader will not be able to upgrade such delegates.

  2. Starts a lightweight upgrader container for each eligible delegate. The script will run one upgrader for every unique value of DELEGATE_NAME environment variable.

  3. Publishes the status of upgrade for every eligible Docker Delegate.

Once run, the upgrader enables periodic checks and automatic updates (if available) for each delegate.

Run the helper Script

Save the following script to a file. Let's say enable-upgrader.sh:

Script
#!/bin/bash

echo "πŸ” Scanning all running containers for Harness delegates with DELEGATE_NAME..."

running_containers=$(docker ps --filter "status=running" --format "{{.ID}}")

started_upgraders=()
patched_count=0

for container_id in $running_containers; do
  env_vars=$(docker inspect "$container_id" --format '{{range .Config.Env}}{{println .}}{{end}}')
  DELEGATE_NAME=$(echo "$env_vars" | grep '^DELEGATE_NAME=' | cut -d'=' -f2-)
  DELEGATE_TOKEN=$(echo "$env_vars" | grep '^DELEGATE_TOKEN=' | cut -d'=' -f2-)
  ACCOUNT_ID=$(echo "$env_vars" | grep '^ACCOUNT_ID=' | cut -d'=' -f2-)
  MANAGER_HOST_AND_PORT=$(echo "$env_vars" | grep '^MANAGER_HOST_AND_PORT=' | cut -d'=' -f2-)

  if [ -z "$DELEGATE_NAME" ]; then
    echo "🚫 Container $container_id skipped: no DELEGATE_NAME found."
    continue
  fi

  if [[ " ${started_upgraders[@]} " =~ " ${DELEGATE_NAME} " ]]; then
    echo "πŸ” Upgrader for DELEGATE_NAME='$DELEGATE_NAME' already handled. Skipping..."
    continue
  fi

  if docker ps --format '{{.Names}}' | grep -q "^${DELEGATE_NAME}-upgrader$"; then
    echo "⚠️ Upgrader container '${DELEGATE_NAME}-upgrader' already running. Skipping creation."
  else
    echo "πŸš€ Starting upgrader container for '$DELEGATE_NAME'..."
    docker run -d --cpus=0.1 --memory=100m \
      -v /var/run/docker.sock:/var/run/docker.sock \
      -e ACCOUNT_ID="$ACCOUNT_ID" \
      -e MANAGER_HOST_AND_PORT="$MANAGER_HOST_AND_PORT" \
      -e UPGRADER_WORKLOAD_NAME="$DELEGATE_NAME" \
      -e UPGRADER_TOKEN="$DELEGATE_TOKEN" \
      -e SCHEDULE="0 */1 * * *" \
      us-docker.pkg.dev/gar-prod-setup/harness-public/harness/upgrader:latest

    echo "βœ… Upgrader started for '$DELEGATE_NAME'"
    patched_count=$((patched_count + 1))
  fi

  started_upgraders+=("$DELEGATE_NAME")
done

echo "πŸŽ‰ Finished. Total new upgraders started: $patched_count"

Make the script executable and run it:

chmod +x enable-upgrader.sh
./enable-upgrader.sh

Example Output

Last updated

Was this helpful?