openvidu-deployment: Force minimum docker and docker-compose version.

master
cruizba 2025-06-02 17:47:46 +02:00
parent b8c0bb3283
commit 3107d504ce
6 changed files with 402 additions and 84 deletions

View File

@ -27,6 +27,25 @@ export LOKI_IMAGE="${LOKI_IMAGE:-docker.io/grafana/loki:3.5.1}"
export MIMIR_IMAGE="${MIMIR_IMAGE:-docker.io/bitnami/grafana-mimir:2.16.0}" export MIMIR_IMAGE="${MIMIR_IMAGE:-docker.io/bitnami/grafana-mimir:2.16.0}"
export GRAFANA_IMAGE="${GRAFANA_IMAGE:-docker.io/grafana/grafana:11.6.2}" export GRAFANA_IMAGE="${GRAFANA_IMAGE:-docker.io/grafana/grafana:11.6.2}"
# Function to compare two version strings
compare_versions() {
# Remove 'v' prefix if present
VERSION1=$(echo "$1" | sed 's/^v//')
VERSION2=$(echo "$2" | sed 's/^v//')
# Compare versions
if [ "$(printf '%s\n' "$VERSION1" "$VERSION2" | sort -V | head -n1)" = "$VERSION1" ]; then
if [ "$VERSION1" = "$VERSION2" ]; then
echo "equal"
else
echo "lower"
fi
else
echo "higher"
fi
}
wait_for_docker() { wait_for_docker() {
echo "Waiting for Docker to start..." echo "Waiting for Docker to start..."
@ -57,16 +76,52 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1 exit 1
fi fi
if ! command -v docker > /dev/null 2>&1 # Check Docker installation and version
then DOCKER_NEEDED=false
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh if ! command -v docker > /dev/null 2>&1; then
sh /tmp/get-docker.sh --version "${DOCKER_VERSION}" || { echo "Can't install Docker automatically. Install it manually and run this script again"; exit 1; } echo "Docker not found. Will install Docker version ${DOCKER_VERSION}."
DOCKER_NEEDED=true
else else
echo "Docker already installed. Check you have the latest version for best compatibility" CURRENT_DOCKER_VERSION=$(docker --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
VERSION_COMPARISON=$(compare_versions "$CURRENT_DOCKER_VERSION" "$DOCKER_VERSION")
if [ "$VERSION_COMPARISON" = "lower" ]; then
echo "Docker version $CURRENT_DOCKER_VERSION is older than required version $DOCKER_VERSION."
echo "Please update Docker to version $DOCKER_VERSION or later."
exit 1
else
echo "Docker version $CURRENT_DOCKER_VERSION is compatible with required version $DOCKER_VERSION."
fi
fi fi
if ! command -v docker-compose > /dev/null 2>&1 # Install Docker if needed
then if [ "$DOCKER_NEEDED" = true ]; then
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
sh /tmp/get-docker.sh --version "${DOCKER_VERSION}" || { echo "Can't install Docker automatically. Install it manually and run this script again"; exit 1; }
fi
# Check Docker Compose installation and version
DOCKER_COMPOSE_NEEDED=false
if ! command -v docker-compose > /dev/null 2>&1; then
echo "Docker Compose not found. Will install Docker Compose version ${DOCKER_COMPOSE_VERSION}."
DOCKER_COMPOSE_NEEDED=true
else
CURRENT_DC_VERSION=$(docker-compose --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
# Add 'v' prefix for proper comparison
CURRENT_DC_VERSION="v${CURRENT_DC_VERSION}"
VERSION_COMPARISON=$(compare_versions "$CURRENT_DC_VERSION" "$DOCKER_COMPOSE_VERSION")
if [ "$VERSION_COMPARISON" = "lower" ]; then
echo "Docker Compose version $CURRENT_DC_VERSION is older than required version $DOCKER_COMPOSE_VERSION."
echo "Will update Docker Compose to version $DOCKER_COMPOSE_VERSION."
DOCKER_COMPOSE_NEEDED=true
else
echo "Docker Compose version $CURRENT_DC_VERSION is compatible with required version $DOCKER_COMPOSE_VERSION."
fi
fi
# Install or update Docker Compose if needed
if [ "$DOCKER_COMPOSE_NEEDED" = true ]; then
TIME_LIMIT_SECONDS=20 TIME_LIMIT_SECONDS=20
START_TIME=$(awk 'BEGIN{srand(); print srand()}') START_TIME=$(awk 'BEGIN{srand(); print srand()}')
while true while true
@ -74,24 +129,24 @@ then
CURRENT_TIME=$(awk 'BEGIN{srand(); print srand()}') CURRENT_TIME=$(awk 'BEGIN{srand(); print srand()}')
if [ $((CURRENT_TIME-START_TIME)) -gt $TIME_LIMIT_SECONDS ]; then if [ $((CURRENT_TIME-START_TIME)) -gt $TIME_LIMIT_SECONDS ]; then
echo "Error downloading docker-compose. Could not download it in $TIME_LIMIT_SECONDS seconds" echo "Error downloading docker-compose. Could not download it in $TIME_LIMIT_SECONDS seconds"
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
exit 1 exit 1
fi fi
STATUS_RECEIVED=$(curl --retry 5 --retry-max-time 40 --write-out "%{http_code}\n" -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose) STATUS_RECEIVED=$(curl --retry 5 --retry-max-time 40 --write-out "%{http_code}\n" -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose)
CURL_EXIT_CODE=$? CURL_EXIT_CODE=$?
if [ $CURL_EXIT_CODE -ne 0 ]; then if [ $CURL_EXIT_CODE -ne 0 ]; then
echo "Error downloading docker-compose. curl failed with exit code $CURL_EXIT_CODE. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..." echo "Error downloading docker-compose. curl failed with exit code $CURL_EXIT_CODE. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..."
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
sleep 2 sleep 2
continue continue
fi fi
if [ "${STATUS_RECEIVED}" -ne "200" ]; then if [ "${STATUS_RECEIVED}" -ne "200" ]; then
echo "Error downloading docker-compose. Received HTTP status code $STATUS_RECEIVED. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..." echo "Error downloading docker-compose. Received HTTP status code $STATUS_RECEIVED. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..."
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
sleep 2 sleep 2
continue continue
fi fi
echo "Success downloading docker-compose" echo "Success downloading docker-compose version $DOCKER_COMPOSE_VERSION"
chmod 755 /usr/local/bin/docker-compose chmod 755 /usr/local/bin/docker-compose
break break
done done
@ -99,9 +154,7 @@ then
# Create a symbolic link to docker-compose in the Docker CLI plugins directory # Create a symbolic link to docker-compose in the Docker CLI plugins directory
# so docker compose can be used also # so docker compose can be used also
mkdir -p /usr/local/lib/docker/cli-plugins mkdir -p /usr/local/lib/docker/cli-plugins
ln -s /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose ln -sf /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose
else
echo "Docker Compose already installed. Check you have the latest version for best compatibility"
fi fi
# Restart Docker and wait for it to start # Restart Docker and wait for it to start

View File

@ -27,6 +27,25 @@ export LOKI_IMAGE="${LOKI_IMAGE:-docker.io/grafana/loki:3.5.1}"
export MIMIR_IMAGE="${MIMIR_IMAGE:-docker.io/bitnami/grafana-mimir:2.16.0}" export MIMIR_IMAGE="${MIMIR_IMAGE:-docker.io/bitnami/grafana-mimir:2.16.0}"
export GRAFANA_IMAGE="${GRAFANA_IMAGE:-docker.io/grafana/grafana:11.6.2}" export GRAFANA_IMAGE="${GRAFANA_IMAGE:-docker.io/grafana/grafana:11.6.2}"
# Function to compare two version strings
compare_versions() {
# Remove 'v' prefix if present
VERSION1=$(echo "$1" | sed 's/^v//')
VERSION2=$(echo "$2" | sed 's/^v//')
# Compare versions
if [ "$(printf '%s\n' "$VERSION1" "$VERSION2" | sort -V | head -n1)" = "$VERSION1" ]; then
if [ "$VERSION1" = "$VERSION2" ]; then
echo "equal"
else
echo "lower"
fi
else
echo "higher"
fi
}
wait_for_docker() { wait_for_docker() {
echo "Waiting for Docker to start..." echo "Waiting for Docker to start..."
@ -57,16 +76,52 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1 exit 1
fi fi
if ! command -v docker > /dev/null 2>&1 # Check Docker installation and version
then DOCKER_NEEDED=false
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh if ! command -v docker > /dev/null 2>&1; then
sh /tmp/get-docker.sh --version "${DOCKER_VERSION}" || { echo "Can't install Docker automatically. Install it manually and run this script again"; exit 1; } echo "Docker not found. Will install Docker version ${DOCKER_VERSION}."
DOCKER_NEEDED=true
else else
echo "Docker already installed. Check you have the latest version for best compatibility" CURRENT_DOCKER_VERSION=$(docker --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
VERSION_COMPARISON=$(compare_versions "$CURRENT_DOCKER_VERSION" "$DOCKER_VERSION")
if [ "$VERSION_COMPARISON" = "lower" ]; then
echo "Docker version $CURRENT_DOCKER_VERSION is older than required version $DOCKER_VERSION."
echo "Please update Docker to version $DOCKER_VERSION or later."
exit 1
else
echo "Docker version $CURRENT_DOCKER_VERSION is compatible with required version $DOCKER_VERSION."
fi
fi fi
if ! command -v docker-compose > /dev/null 2>&1 # Install Docker if needed
then if [ "$DOCKER_NEEDED" = true ]; then
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
sh /tmp/get-docker.sh --version "${DOCKER_VERSION}" || { echo "Can't install Docker automatically. Install it manually and run this script again"; exit 1; }
fi
# Check Docker Compose installation and version
DOCKER_COMPOSE_NEEDED=false
if ! command -v docker-compose > /dev/null 2>&1; then
echo "Docker Compose not found. Will install Docker Compose version ${DOCKER_COMPOSE_VERSION}."
DOCKER_COMPOSE_NEEDED=true
else
CURRENT_DC_VERSION=$(docker-compose --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
# Add 'v' prefix for proper comparison
CURRENT_DC_VERSION="v${CURRENT_DC_VERSION}"
VERSION_COMPARISON=$(compare_versions "$CURRENT_DC_VERSION" "$DOCKER_COMPOSE_VERSION")
if [ "$VERSION_COMPARISON" = "lower" ]; then
echo "Docker Compose version $CURRENT_DC_VERSION is older than required version $DOCKER_COMPOSE_VERSION."
echo "Will update Docker Compose to version $DOCKER_COMPOSE_VERSION."
DOCKER_COMPOSE_NEEDED=true
else
echo "Docker Compose version $CURRENT_DC_VERSION is compatible with required version $DOCKER_COMPOSE_VERSION."
fi
fi
# Install or update Docker Compose if needed
if [ "$DOCKER_COMPOSE_NEEDED" = true ]; then
TIME_LIMIT_SECONDS=20 TIME_LIMIT_SECONDS=20
START_TIME=$(awk 'BEGIN{srand(); print srand()}') START_TIME=$(awk 'BEGIN{srand(); print srand()}')
while true while true
@ -74,24 +129,24 @@ then
CURRENT_TIME=$(awk 'BEGIN{srand(); print srand()}') CURRENT_TIME=$(awk 'BEGIN{srand(); print srand()}')
if [ $((CURRENT_TIME-START_TIME)) -gt $TIME_LIMIT_SECONDS ]; then if [ $((CURRENT_TIME-START_TIME)) -gt $TIME_LIMIT_SECONDS ]; then
echo "Error downloading docker-compose. Could not download it in $TIME_LIMIT_SECONDS seconds" echo "Error downloading docker-compose. Could not download it in $TIME_LIMIT_SECONDS seconds"
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
exit 1 exit 1
fi fi
STATUS_RECEIVED=$(curl --retry 5 --retry-max-time 40 --write-out "%{http_code}\n" -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose) STATUS_RECEIVED=$(curl --retry 5 --retry-max-time 40 --write-out "%{http_code}\n" -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose)
CURL_EXIT_CODE=$? CURL_EXIT_CODE=$?
if [ $CURL_EXIT_CODE -ne 0 ]; then if [ $CURL_EXIT_CODE -ne 0 ]; then
echo "Error downloading docker-compose. curl failed with exit code $CURL_EXIT_CODE. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..." echo "Error downloading docker-compose. curl failed with exit code $CURL_EXIT_CODE. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..."
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
sleep 2 sleep 2
continue continue
fi fi
if [ "${STATUS_RECEIVED}" -ne "200" ]; then if [ "${STATUS_RECEIVED}" -ne "200" ]; then
echo "Error downloading docker-compose. Received HTTP status code $STATUS_RECEIVED. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..." echo "Error downloading docker-compose. Received HTTP status code $STATUS_RECEIVED. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..."
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
sleep 2 sleep 2
continue continue
fi fi
echo "Success downloading docker-compose" echo "Success downloading docker-compose version $DOCKER_COMPOSE_VERSION"
chmod 755 /usr/local/bin/docker-compose chmod 755 /usr/local/bin/docker-compose
break break
done done
@ -99,9 +154,7 @@ then
# Create a symbolic link to docker-compose in the Docker CLI plugins directory # Create a symbolic link to docker-compose in the Docker CLI plugins directory
# so docker compose can be used also # so docker compose can be used also
mkdir -p /usr/local/lib/docker/cli-plugins mkdir -p /usr/local/lib/docker/cli-plugins
ln -s /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose ln -sf /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose
else
echo "Docker Compose already installed. Check you have the latest version for best compatibility"
fi fi
# Restart Docker and wait for it to start # Restart Docker and wait for it to start

View File

@ -27,6 +27,25 @@ export LOKI_IMAGE="${LOKI_IMAGE:-docker.io/grafana/loki:3.5.1}"
export MIMIR_IMAGE="${MIMIR_IMAGE:-docker.io/bitnami/grafana-mimir:2.16.0}" export MIMIR_IMAGE="${MIMIR_IMAGE:-docker.io/bitnami/grafana-mimir:2.16.0}"
export GRAFANA_IMAGE="${GRAFANA_IMAGE:-docker.io/grafana/grafana:11.6.2}" export GRAFANA_IMAGE="${GRAFANA_IMAGE:-docker.io/grafana/grafana:11.6.2}"
# Function to compare two version strings
compare_versions() {
# Remove 'v' prefix if present
VERSION1=$(echo "$1" | sed 's/^v//')
VERSION2=$(echo "$2" | sed 's/^v//')
# Compare versions
if [ "$(printf '%s\n' "$VERSION1" "$VERSION2" | sort -V | head -n1)" = "$VERSION1" ]; then
if [ "$VERSION1" = "$VERSION2" ]; then
echo "equal"
else
echo "lower"
fi
else
echo "higher"
fi
}
wait_for_docker() { wait_for_docker() {
echo "Waiting for Docker to start..." echo "Waiting for Docker to start..."
@ -57,16 +76,52 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1 exit 1
fi fi
if ! command -v docker > /dev/null 2>&1 # Check Docker installation and version
then DOCKER_NEEDED=false
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh if ! command -v docker > /dev/null 2>&1; then
sh /tmp/get-docker.sh --version "${DOCKER_VERSION}" || { echo "Can't install Docker automatically. Install it manually and run this script again"; exit 1; } echo "Docker not found. Will install Docker version ${DOCKER_VERSION}."
DOCKER_NEEDED=true
else else
echo "Docker already installed. Check you have the latest version for best compatibility" CURRENT_DOCKER_VERSION=$(docker --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
VERSION_COMPARISON=$(compare_versions "$CURRENT_DOCKER_VERSION" "$DOCKER_VERSION")
if [ "$VERSION_COMPARISON" = "lower" ]; then
echo "Docker version $CURRENT_DOCKER_VERSION is older than required version $DOCKER_VERSION."
echo "Please update Docker to version $DOCKER_VERSION or later."
exit 1
else
echo "Docker version $CURRENT_DOCKER_VERSION is compatible with required version $DOCKER_VERSION."
fi
fi fi
if ! command -v docker-compose > /dev/null 2>&1 # Install Docker if needed
then if [ "$DOCKER_NEEDED" = true ]; then
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
sh /tmp/get-docker.sh --version "${DOCKER_VERSION}" || { echo "Can't install Docker automatically. Install it manually and run this script again"; exit 1; }
fi
# Check Docker Compose installation and version
DOCKER_COMPOSE_NEEDED=false
if ! command -v docker-compose > /dev/null 2>&1; then
echo "Docker Compose not found. Will install Docker Compose version ${DOCKER_COMPOSE_VERSION}."
DOCKER_COMPOSE_NEEDED=true
else
CURRENT_DC_VERSION=$(docker-compose --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
# Add 'v' prefix for proper comparison
CURRENT_DC_VERSION="v${CURRENT_DC_VERSION}"
VERSION_COMPARISON=$(compare_versions "$CURRENT_DC_VERSION" "$DOCKER_COMPOSE_VERSION")
if [ "$VERSION_COMPARISON" = "lower" ]; then
echo "Docker Compose version $CURRENT_DC_VERSION is older than required version $DOCKER_COMPOSE_VERSION."
echo "Will update Docker Compose to version $DOCKER_COMPOSE_VERSION."
DOCKER_COMPOSE_NEEDED=true
else
echo "Docker Compose version $CURRENT_DC_VERSION is compatible with required version $DOCKER_COMPOSE_VERSION."
fi
fi
# Install or update Docker Compose if needed
if [ "$DOCKER_COMPOSE_NEEDED" = true ]; then
TIME_LIMIT_SECONDS=20 TIME_LIMIT_SECONDS=20
START_TIME=$(awk 'BEGIN{srand(); print srand()}') START_TIME=$(awk 'BEGIN{srand(); print srand()}')
while true while true
@ -74,24 +129,24 @@ then
CURRENT_TIME=$(awk 'BEGIN{srand(); print srand()}') CURRENT_TIME=$(awk 'BEGIN{srand(); print srand()}')
if [ $((CURRENT_TIME-START_TIME)) -gt $TIME_LIMIT_SECONDS ]; then if [ $((CURRENT_TIME-START_TIME)) -gt $TIME_LIMIT_SECONDS ]; then
echo "Error downloading docker-compose. Could not download it in $TIME_LIMIT_SECONDS seconds" echo "Error downloading docker-compose. Could not download it in $TIME_LIMIT_SECONDS seconds"
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
exit 1 exit 1
fi fi
STATUS_RECEIVED=$(curl --retry 5 --retry-max-time 40 --write-out "%{http_code}\n" -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose) STATUS_RECEIVED=$(curl --retry 5 --retry-max-time 40 --write-out "%{http_code}\n" -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose)
CURL_EXIT_CODE=$? CURL_EXIT_CODE=$?
if [ $CURL_EXIT_CODE -ne 0 ]; then if [ $CURL_EXIT_CODE -ne 0 ]; then
echo "Error downloading docker-compose. curl failed with exit code $CURL_EXIT_CODE. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..." echo "Error downloading docker-compose. curl failed with exit code $CURL_EXIT_CODE. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..."
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
sleep 2 sleep 2
continue continue
fi fi
if [ "${STATUS_RECEIVED}" -ne "200" ]; then if [ "${STATUS_RECEIVED}" -ne "200" ]; then
echo "Error downloading docker-compose. Received HTTP status code $STATUS_RECEIVED. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..." echo "Error downloading docker-compose. Received HTTP status code $STATUS_RECEIVED. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..."
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
sleep 2 sleep 2
continue continue
fi fi
echo "Success downloading docker-compose" echo "Success downloading docker-compose version $DOCKER_COMPOSE_VERSION"
chmod 755 /usr/local/bin/docker-compose chmod 755 /usr/local/bin/docker-compose
break break
done done
@ -99,9 +154,7 @@ then
# Create a symbolic link to docker-compose in the Docker CLI plugins directory # Create a symbolic link to docker-compose in the Docker CLI plugins directory
# so docker compose can be used also # so docker compose can be used also
mkdir -p /usr/local/lib/docker/cli-plugins mkdir -p /usr/local/lib/docker/cli-plugins
ln -s /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose ln -sf /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose
else
echo "Docker Compose already installed. Check you have the latest version for best compatibility"
fi fi
# Restart Docker and wait for it to start # Restart Docker and wait for it to start

View File

@ -27,6 +27,25 @@ export LOKI_IMAGE="${LOKI_IMAGE:-docker.io/grafana/loki:3.5.1}"
export MIMIR_IMAGE="${MIMIR_IMAGE:-docker.io/bitnami/grafana-mimir:2.16.0}" export MIMIR_IMAGE="${MIMIR_IMAGE:-docker.io/bitnami/grafana-mimir:2.16.0}"
export GRAFANA_IMAGE="${GRAFANA_IMAGE:-docker.io/grafana/grafana:11.6.2}" export GRAFANA_IMAGE="${GRAFANA_IMAGE:-docker.io/grafana/grafana:11.6.2}"
# Function to compare two version strings
compare_versions() {
# Remove 'v' prefix if present
VERSION1=$(echo "$1" | sed 's/^v//')
VERSION2=$(echo "$2" | sed 's/^v//')
# Compare versions
if [ "$(printf '%s\n' "$VERSION1" "$VERSION2" | sort -V | head -n1)" = "$VERSION1" ]; then
if [ "$VERSION1" = "$VERSION2" ]; then
echo "equal"
else
echo "lower"
fi
else
echo "higher"
fi
}
wait_for_docker() { wait_for_docker() {
echo "Waiting for Docker to start..." echo "Waiting for Docker to start..."
@ -57,16 +76,52 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1 exit 1
fi fi
if ! command -v docker > /dev/null 2>&1 # Check Docker installation and version
then DOCKER_NEEDED=false
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh if ! command -v docker > /dev/null 2>&1; then
sh /tmp/get-docker.sh --version "${DOCKER_VERSION}" || { echo "Can't install Docker automatically. Install it manually and run this script again"; exit 1; } echo "Docker not found. Will install Docker version ${DOCKER_VERSION}."
DOCKER_NEEDED=true
else else
echo "Docker already installed. Check you have the latest version for best compatibility" CURRENT_DOCKER_VERSION=$(docker --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
VERSION_COMPARISON=$(compare_versions "$CURRENT_DOCKER_VERSION" "$DOCKER_VERSION")
if [ "$VERSION_COMPARISON" = "lower" ]; then
echo "Docker version $CURRENT_DOCKER_VERSION is older than required version $DOCKER_VERSION."
echo "Please update Docker to version $DOCKER_VERSION or later."
exit 1
else
echo "Docker version $CURRENT_DOCKER_VERSION is compatible with required version $DOCKER_VERSION."
fi
fi fi
if ! command -v docker-compose > /dev/null 2>&1 # Install Docker if needed
then if [ "$DOCKER_NEEDED" = true ]; then
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
sh /tmp/get-docker.sh --version "${DOCKER_VERSION}" || { echo "Can't install Docker automatically. Install it manually and run this script again"; exit 1; }
fi
# Check Docker Compose installation and version
DOCKER_COMPOSE_NEEDED=false
if ! command -v docker-compose > /dev/null 2>&1; then
echo "Docker Compose not found. Will install Docker Compose version ${DOCKER_COMPOSE_VERSION}."
DOCKER_COMPOSE_NEEDED=true
else
CURRENT_DC_VERSION=$(docker-compose --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
# Add 'v' prefix for proper comparison
CURRENT_DC_VERSION="v${CURRENT_DC_VERSION}"
VERSION_COMPARISON=$(compare_versions "$CURRENT_DC_VERSION" "$DOCKER_COMPOSE_VERSION")
if [ "$VERSION_COMPARISON" = "lower" ]; then
echo "Docker Compose version $CURRENT_DC_VERSION is older than required version $DOCKER_COMPOSE_VERSION."
echo "Will update Docker Compose to version $DOCKER_COMPOSE_VERSION."
DOCKER_COMPOSE_NEEDED=true
else
echo "Docker Compose version $CURRENT_DC_VERSION is compatible with required version $DOCKER_COMPOSE_VERSION."
fi
fi
# Install or update Docker Compose if needed
if [ "$DOCKER_COMPOSE_NEEDED" = true ]; then
TIME_LIMIT_SECONDS=20 TIME_LIMIT_SECONDS=20
START_TIME=$(awk 'BEGIN{srand(); print srand()}') START_TIME=$(awk 'BEGIN{srand(); print srand()}')
while true while true
@ -74,24 +129,24 @@ then
CURRENT_TIME=$(awk 'BEGIN{srand(); print srand()}') CURRENT_TIME=$(awk 'BEGIN{srand(); print srand()}')
if [ $((CURRENT_TIME-START_TIME)) -gt $TIME_LIMIT_SECONDS ]; then if [ $((CURRENT_TIME-START_TIME)) -gt $TIME_LIMIT_SECONDS ]; then
echo "Error downloading docker-compose. Could not download it in $TIME_LIMIT_SECONDS seconds" echo "Error downloading docker-compose. Could not download it in $TIME_LIMIT_SECONDS seconds"
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
exit 1 exit 1
fi fi
STATUS_RECEIVED=$(curl --retry 5 --retry-max-time 40 --write-out "%{http_code}\n" -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose) STATUS_RECEIVED=$(curl --retry 5 --retry-max-time 40 --write-out "%{http_code}\n" -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose)
CURL_EXIT_CODE=$? CURL_EXIT_CODE=$?
if [ $CURL_EXIT_CODE -ne 0 ]; then if [ $CURL_EXIT_CODE -ne 0 ]; then
echo "Error downloading docker-compose. curl failed with exit code $CURL_EXIT_CODE. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..." echo "Error downloading docker-compose. curl failed with exit code $CURL_EXIT_CODE. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..."
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
sleep 2 sleep 2
continue continue
fi fi
if [ "${STATUS_RECEIVED}" -ne "200" ]; then if [ "${STATUS_RECEIVED}" -ne "200" ]; then
echo "Error downloading docker-compose. Received HTTP status code $STATUS_RECEIVED. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..." echo "Error downloading docker-compose. Received HTTP status code $STATUS_RECEIVED. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..."
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
sleep 2 sleep 2
continue continue
fi fi
echo "Success downloading docker-compose" echo "Success downloading docker-compose version $DOCKER_COMPOSE_VERSION"
chmod 755 /usr/local/bin/docker-compose chmod 755 /usr/local/bin/docker-compose
break break
done done
@ -99,9 +154,7 @@ then
# Create a symbolic link to docker-compose in the Docker CLI plugins directory # Create a symbolic link to docker-compose in the Docker CLI plugins directory
# so docker compose can be used also # so docker compose can be used also
mkdir -p /usr/local/lib/docker/cli-plugins mkdir -p /usr/local/lib/docker/cli-plugins
ln -s /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose ln -sf /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose
else
echo "Docker Compose already installed. Check you have the latest version for best compatibility"
fi fi
# Restart Docker and wait for it to start # Restart Docker and wait for it to start

View File

@ -27,6 +27,25 @@ export LOKI_IMAGE="${LOKI_IMAGE:-docker.io/grafana/loki:3.5.1}"
export MIMIR_IMAGE="${MIMIR_IMAGE:-docker.io/bitnami/grafana-mimir:2.16.0}" export MIMIR_IMAGE="${MIMIR_IMAGE:-docker.io/bitnami/grafana-mimir:2.16.0}"
export GRAFANA_IMAGE="${GRAFANA_IMAGE:-docker.io/grafana/grafana:11.6.2}" export GRAFANA_IMAGE="${GRAFANA_IMAGE:-docker.io/grafana/grafana:11.6.2}"
# Function to compare two version strings
compare_versions() {
# Remove 'v' prefix if present
VERSION1=$(echo "$1" | sed 's/^v//')
VERSION2=$(echo "$2" | sed 's/^v//')
# Compare versions
if [ "$(printf '%s\n' "$VERSION1" "$VERSION2" | sort -V | head -n1)" = "$VERSION1" ]; then
if [ "$VERSION1" = "$VERSION2" ]; then
echo "equal"
else
echo "lower"
fi
else
echo "higher"
fi
}
wait_for_docker() { wait_for_docker() {
echo "Waiting for Docker to start..." echo "Waiting for Docker to start..."
@ -57,16 +76,52 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1 exit 1
fi fi
if ! command -v docker > /dev/null 2>&1 # Check Docker installation and version
then DOCKER_NEEDED=false
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh if ! command -v docker > /dev/null 2>&1; then
sh /tmp/get-docker.sh --version "${DOCKER_VERSION}" || { echo "Can't install Docker automatically. Install it manually and run this script again"; exit 1; } echo "Docker not found. Will install Docker version ${DOCKER_VERSION}."
DOCKER_NEEDED=true
else else
echo "Docker already installed. Check you have the latest version for best compatibility" CURRENT_DOCKER_VERSION=$(docker --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
VERSION_COMPARISON=$(compare_versions "$CURRENT_DOCKER_VERSION" "$DOCKER_VERSION")
if [ "$VERSION_COMPARISON" = "lower" ]; then
echo "Docker version $CURRENT_DOCKER_VERSION is older than required version $DOCKER_VERSION."
echo "Please update Docker to version $DOCKER_VERSION or later."
exit 1
else
echo "Docker version $CURRENT_DOCKER_VERSION is compatible with required version $DOCKER_VERSION."
fi
fi fi
if ! command -v docker-compose > /dev/null 2>&1 # Install Docker if needed
then if [ "$DOCKER_NEEDED" = true ]; then
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
sh /tmp/get-docker.sh --version "${DOCKER_VERSION}" || { echo "Can't install Docker automatically. Install it manually and run this script again"; exit 1; }
fi
# Check Docker Compose installation and version
DOCKER_COMPOSE_NEEDED=false
if ! command -v docker-compose > /dev/null 2>&1; then
echo "Docker Compose not found. Will install Docker Compose version ${DOCKER_COMPOSE_VERSION}."
DOCKER_COMPOSE_NEEDED=true
else
CURRENT_DC_VERSION=$(docker-compose --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
# Add 'v' prefix for proper comparison
CURRENT_DC_VERSION="v${CURRENT_DC_VERSION}"
VERSION_COMPARISON=$(compare_versions "$CURRENT_DC_VERSION" "$DOCKER_COMPOSE_VERSION")
if [ "$VERSION_COMPARISON" = "lower" ]; then
echo "Docker Compose version $CURRENT_DC_VERSION is older than required version $DOCKER_COMPOSE_VERSION."
echo "Will update Docker Compose to version $DOCKER_COMPOSE_VERSION."
DOCKER_COMPOSE_NEEDED=true
else
echo "Docker Compose version $CURRENT_DC_VERSION is compatible with required version $DOCKER_COMPOSE_VERSION."
fi
fi
# Install or update Docker Compose if needed
if [ "$DOCKER_COMPOSE_NEEDED" = true ]; then
TIME_LIMIT_SECONDS=20 TIME_LIMIT_SECONDS=20
START_TIME=$(awk 'BEGIN{srand(); print srand()}') START_TIME=$(awk 'BEGIN{srand(); print srand()}')
while true while true
@ -74,24 +129,24 @@ then
CURRENT_TIME=$(awk 'BEGIN{srand(); print srand()}') CURRENT_TIME=$(awk 'BEGIN{srand(); print srand()}')
if [ $((CURRENT_TIME-START_TIME)) -gt $TIME_LIMIT_SECONDS ]; then if [ $((CURRENT_TIME-START_TIME)) -gt $TIME_LIMIT_SECONDS ]; then
echo "Error downloading docker-compose. Could not download it in $TIME_LIMIT_SECONDS seconds" echo "Error downloading docker-compose. Could not download it in $TIME_LIMIT_SECONDS seconds"
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
exit 1 exit 1
fi fi
STATUS_RECEIVED=$(curl --retry 5 --retry-max-time 40 --write-out "%{http_code}\n" -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose) STATUS_RECEIVED=$(curl --retry 5 --retry-max-time 40 --write-out "%{http_code}\n" -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose)
CURL_EXIT_CODE=$? CURL_EXIT_CODE=$?
if [ $CURL_EXIT_CODE -ne 0 ]; then if [ $CURL_EXIT_CODE -ne 0 ]; then
echo "Error downloading docker-compose. curl failed with exit code $CURL_EXIT_CODE. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..." echo "Error downloading docker-compose. curl failed with exit code $CURL_EXIT_CODE. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..."
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
sleep 2 sleep 2
continue continue
fi fi
if [ "${STATUS_RECEIVED}" -ne "200" ]; then if [ "${STATUS_RECEIVED}" -ne "200" ]; then
echo "Error downloading docker-compose. Received HTTP status code $STATUS_RECEIVED. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..." echo "Error downloading docker-compose. Received HTTP status code $STATUS_RECEIVED. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..."
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
sleep 2 sleep 2
continue continue
fi fi
echo "Success downloading docker-compose" echo "Success downloading docker-compose version $DOCKER_COMPOSE_VERSION"
chmod 755 /usr/local/bin/docker-compose chmod 755 /usr/local/bin/docker-compose
break break
done done
@ -99,9 +154,7 @@ then
# Create a symbolic link to docker-compose in the Docker CLI plugins directory # Create a symbolic link to docker-compose in the Docker CLI plugins directory
# so docker compose can be used also # so docker compose can be used also
mkdir -p /usr/local/lib/docker/cli-plugins mkdir -p /usr/local/lib/docker/cli-plugins
ln -s /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose ln -sf /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose
else
echo "Docker Compose already installed. Check you have the latest version for best compatibility"
fi fi
# Restart Docker and wait for it to start # Restart Docker and wait for it to start

View File

@ -27,6 +27,25 @@ export LOKI_IMAGE="${LOKI_IMAGE:-docker.io/grafana/loki:3.5.1}"
export MIMIR_IMAGE="${MIMIR_IMAGE:-docker.io/bitnami/grafana-mimir:2.16.0}" export MIMIR_IMAGE="${MIMIR_IMAGE:-docker.io/bitnami/grafana-mimir:2.16.0}"
export GRAFANA_IMAGE="${GRAFANA_IMAGE:-docker.io/grafana/grafana:11.6.2}" export GRAFANA_IMAGE="${GRAFANA_IMAGE:-docker.io/grafana/grafana:11.6.2}"
# Function to compare two version strings
compare_versions() {
# Remove 'v' prefix if present
VERSION1=$(echo "$1" | sed 's/^v//')
VERSION2=$(echo "$2" | sed 's/^v//')
# Compare versions
if [ "$(printf '%s\n' "$VERSION1" "$VERSION2" | sort -V | head -n1)" = "$VERSION1" ]; then
if [ "$VERSION1" = "$VERSION2" ]; then
echo "equal"
else
echo "lower"
fi
else
echo "higher"
fi
}
wait_for_docker() { wait_for_docker() {
echo "Waiting for Docker to start..." echo "Waiting for Docker to start..."
@ -57,16 +76,52 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1 exit 1
fi fi
if ! command -v docker > /dev/null 2>&1 # Check Docker installation and version
then DOCKER_NEEDED=false
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh if ! command -v docker > /dev/null 2>&1; then
sh /tmp/get-docker.sh --version "${DOCKER_VERSION}" || { echo "Can't install Docker automatically. Install it manually and run this script again"; exit 1; } echo "Docker not found. Will install Docker version ${DOCKER_VERSION}."
DOCKER_NEEDED=true
else else
echo "Docker already installed. Check you have the latest version for best compatibility" CURRENT_DOCKER_VERSION=$(docker --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
VERSION_COMPARISON=$(compare_versions "$CURRENT_DOCKER_VERSION" "$DOCKER_VERSION")
if [ "$VERSION_COMPARISON" = "lower" ]; then
echo "Docker version $CURRENT_DOCKER_VERSION is older than required version $DOCKER_VERSION."
echo "Please update Docker to version $DOCKER_VERSION or later."
exit 1
else
echo "Docker version $CURRENT_DOCKER_VERSION is compatible with required version $DOCKER_VERSION."
fi
fi fi
if ! command -v docker-compose > /dev/null 2>&1 # Install Docker if needed
then if [ "$DOCKER_NEEDED" = true ]; then
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
sh /tmp/get-docker.sh --version "${DOCKER_VERSION}" || { echo "Can't install Docker automatically. Install it manually and run this script again"; exit 1; }
fi
# Check Docker Compose installation and version
DOCKER_COMPOSE_NEEDED=false
if ! command -v docker-compose > /dev/null 2>&1; then
echo "Docker Compose not found. Will install Docker Compose version ${DOCKER_COMPOSE_VERSION}."
DOCKER_COMPOSE_NEEDED=true
else
CURRENT_DC_VERSION=$(docker-compose --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
# Add 'v' prefix for proper comparison
CURRENT_DC_VERSION="v${CURRENT_DC_VERSION}"
VERSION_COMPARISON=$(compare_versions "$CURRENT_DC_VERSION" "$DOCKER_COMPOSE_VERSION")
if [ "$VERSION_COMPARISON" = "lower" ]; then
echo "Docker Compose version $CURRENT_DC_VERSION is older than required version $DOCKER_COMPOSE_VERSION."
echo "Will update Docker Compose to version $DOCKER_COMPOSE_VERSION."
DOCKER_COMPOSE_NEEDED=true
else
echo "Docker Compose version $CURRENT_DC_VERSION is compatible with required version $DOCKER_COMPOSE_VERSION."
fi
fi
# Install or update Docker Compose if needed
if [ "$DOCKER_COMPOSE_NEEDED" = true ]; then
TIME_LIMIT_SECONDS=20 TIME_LIMIT_SECONDS=20
START_TIME=$(awk 'BEGIN{srand(); print srand()}') START_TIME=$(awk 'BEGIN{srand(); print srand()}')
while true while true
@ -74,24 +129,24 @@ then
CURRENT_TIME=$(awk 'BEGIN{srand(); print srand()}') CURRENT_TIME=$(awk 'BEGIN{srand(); print srand()}')
if [ $((CURRENT_TIME-START_TIME)) -gt $TIME_LIMIT_SECONDS ]; then if [ $((CURRENT_TIME-START_TIME)) -gt $TIME_LIMIT_SECONDS ]; then
echo "Error downloading docker-compose. Could not download it in $TIME_LIMIT_SECONDS seconds" echo "Error downloading docker-compose. Could not download it in $TIME_LIMIT_SECONDS seconds"
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
exit 1 exit 1
fi fi
STATUS_RECEIVED=$(curl --retry 5 --retry-max-time 40 --write-out "%{http_code}\n" -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose) STATUS_RECEIVED=$(curl --retry 5 --retry-max-time 40 --write-out "%{http_code}\n" -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose)
CURL_EXIT_CODE=$? CURL_EXIT_CODE=$?
if [ $CURL_EXIT_CODE -ne 0 ]; then if [ $CURL_EXIT_CODE -ne 0 ]; then
echo "Error downloading docker-compose. curl failed with exit code $CURL_EXIT_CODE. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..." echo "Error downloading docker-compose. curl failed with exit code $CURL_EXIT_CODE. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..."
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
sleep 2 sleep 2
continue continue
fi fi
if [ "${STATUS_RECEIVED}" -ne "200" ]; then if [ "${STATUS_RECEIVED}" -ne "200" ]; then
echo "Error downloading docker-compose. Received HTTP status code $STATUS_RECEIVED. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..." echo "Error downloading docker-compose. Received HTTP status code $STATUS_RECEIVED. There are still $((TIME_LIMIT_SECONDS - (CURRENT_TIME - START_TIME))) seconds left to retry..."
rm -rf /usr/local/bin/docker-compose rm -f /usr/local/bin/docker-compose
sleep 2 sleep 2
continue continue
fi fi
echo "Success downloading docker-compose" echo "Success downloading docker-compose version $DOCKER_COMPOSE_VERSION"
chmod 755 /usr/local/bin/docker-compose chmod 755 /usr/local/bin/docker-compose
break break
done done
@ -99,9 +154,7 @@ then
# Create a symbolic link to docker-compose in the Docker CLI plugins directory # Create a symbolic link to docker-compose in the Docker CLI plugins directory
# so docker compose can be used also # so docker compose can be used also
mkdir -p /usr/local/lib/docker/cli-plugins mkdir -p /usr/local/lib/docker/cli-plugins
ln -s /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose ln -sf /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose
else
echo "Docker Compose already installed. Check you have the latest version for best compatibility"
fi fi
# Restart Docker and wait for it to start # Restart Docker and wait for it to start