mirror of
https://github.com/tiennm99/coolify.git
synced 2026-04-17 17:21:04 +00:00
refactor(upgrade): improve upgrade script
- remove unused VERSION variable. - add backup functionality of the .env file on each run of the upgrade script. - skip .env backup when coming from the install script - add improved handling and more logging for updating environment-variable values. - remove not needed line
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
## Do not modify this file. You will lose the ability to autoupdate!
|
## Do not modify this file. You will lose the ability to autoupdate!
|
||||||
|
|
||||||
VERSION="15"
|
|
||||||
CDN="https://cdn.coollabs.io/coolify"
|
CDN="https://cdn.coollabs.io/coolify"
|
||||||
LATEST_IMAGE=${1:-latest}
|
LATEST_IMAGE=${1:-latest}
|
||||||
LATEST_HELPER_VERSION=${2:-latest}
|
LATEST_HELPER_VERSION=${2:-latest}
|
||||||
REGISTRY_URL=${3:-ghcr.io}
|
REGISTRY_URL=${3:-ghcr.io}
|
||||||
|
SKIP_BACKUP=${4:-false}
|
||||||
|
ENV_FILE="/data/coolify/source/.env"
|
||||||
|
|
||||||
DATE=$(date +%Y-%m-%d-%H-%M-%S)
|
DATE=$(date +%Y-%m-%d-%H-%M-%S)
|
||||||
LOGFILE="/data/coolify/source/upgrade-${DATE}.log"
|
LOGFILE="/data/coolify/source/upgrade-${DATE}.log"
|
||||||
@@ -14,20 +15,39 @@ curl -fsSL $CDN/docker-compose.yml -o /data/coolify/source/docker-compose.yml
|
|||||||
curl -fsSL $CDN/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml
|
curl -fsSL $CDN/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml
|
||||||
curl -fsSL $CDN/.env.production -o /data/coolify/source/.env.production
|
curl -fsSL $CDN/.env.production -o /data/coolify/source/.env.production
|
||||||
|
|
||||||
# Merge .env and .env.production. New values will be added to .env
|
# Backup existing .env file before making any changes
|
||||||
awk -F '=' '!seen[$1]++' /data/coolify/source/.env /data/coolify/source/.env.production >/data/coolify/source/.env.tmp && mv /data/coolify/source/.env.tmp /data/coolify/source/.env
|
if [ "$SKIP_BACKUP" != "true" ]; then
|
||||||
# Check if PUSHER_APP_ID or PUSHER_APP_KEY or PUSHER_APP_SECRET is empty in /data/coolify/source/.env
|
if [ -f "$ENV_FILE" ]; then
|
||||||
if grep -q "PUSHER_APP_ID=$" /data/coolify/source/.env; then
|
echo "Creating backup of existing .env file to .env-$DATE" >>$LOGFILE
|
||||||
sed -i "s|PUSHER_APP_ID=.*|PUSHER_APP_ID=$(openssl rand -hex 32)|g" /data/coolify/source/.env
|
cp $ENV_FILE $ENV_FILE-$DATE
|
||||||
|
else
|
||||||
|
echo "No existing .env file found to backup" >>$LOGFILE
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if grep -q "PUSHER_APP_KEY=$" /data/coolify/source/.env; then
|
echo "Merging .env.production values into .env" >>$LOGFILE
|
||||||
sed -i "s|PUSHER_APP_KEY=.*|PUSHER_APP_KEY=$(openssl rand -hex 32)|g" /data/coolify/source/.env
|
awk -F '=' '!seen[$1]++' $ENV_FILE /data/coolify/source/.env.production > $ENV_FILE.tmp && mv $ENV_FILE.tmp $ENV_FILE
|
||||||
fi
|
echo ".env file merged successfully" >>$LOGFILE
|
||||||
|
|
||||||
if grep -q "PUSHER_APP_SECRET=$" /data/coolify/source/.env; then
|
update_env_var() {
|
||||||
sed -i "s|PUSHER_APP_SECRET=.*|PUSHER_APP_SECRET=$(openssl rand -hex 32)|g" /data/coolify/source/.env
|
local key="$1"
|
||||||
fi
|
local value="$2"
|
||||||
|
|
||||||
|
# If variable "key=" exists but has no value, update the value of the existing line
|
||||||
|
if grep -q "^${key}=$" "$ENV_FILE"; then
|
||||||
|
sed -i "s|^${key}=$|${key}=${value}|" "$ENV_FILE"
|
||||||
|
echo " - Updated value of ${key} as the current value was empty" >>$LOGFILE
|
||||||
|
# If variable "key=" doesn't exist, append it to the file with value
|
||||||
|
elif ! grep -q "^${key}=" "$ENV_FILE"; then
|
||||||
|
printf '%s=%s\n' "$key" "$value" >>"$ENV_FILE"
|
||||||
|
echo " - Added ${key} with default value as the variable was missing" >>$LOGFILE
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Checking and updating environment variables if necessary..." >>$LOGFILE
|
||||||
|
update_env_var "PUSHER_APP_ID" "$(openssl rand -hex 32)"
|
||||||
|
update_env_var "PUSHER_APP_KEY" "$(openssl rand -hex 32)"
|
||||||
|
update_env_var "PUSHER_APP_SECRET" "$(openssl rand -hex 32)"
|
||||||
|
|
||||||
# Make sure coolify network exists
|
# Make sure coolify network exists
|
||||||
# It is created when starting Coolify with docker compose
|
# It is created when starting Coolify with docker compose
|
||||||
@@ -37,7 +57,6 @@ if ! docker network inspect coolify >/dev/null 2>&1; then
|
|||||||
docker network create --attachable coolify 2>/dev/null
|
docker network create --attachable coolify 2>/dev/null
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# docker network create --attachable --driver=overlay coolify-overlay 2>/dev/null
|
|
||||||
|
|
||||||
# Check if Docker config file exists
|
# Check if Docker config file exists
|
||||||
DOCKER_CONFIG_MOUNT=""
|
DOCKER_CONFIG_MOUNT=""
|
||||||
|
|||||||
Reference in New Issue
Block a user