Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Optional change installation directory #2710

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/Actions/Server/StartSentinel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public function handle(Server $server, bool $restart = false, ?string $latestVer
$token = data_get($server, 'settings.sentinel_token');
$endpoint = data_get($server, 'settings.sentinel_custom_url');
$debug = data_get($server, 'settings.is_sentinel_debug_enabled');
$mountDir = '/data/coolify/sentinel';
$base_path = config('coolify.base_config_path');
$mountDir = "$base_path/sentinel";
$image = "ghcr.io/coollabsio/sentinel:$version";
if (! $endpoint) {
throw new \Exception('You should set FQDN in Instance Settings.');
Expand Down
6 changes: 4 additions & 2 deletions app/Actions/Server/UpdateCoolify.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ private function update()

instant_remote_process(["docker pull -q ghcr.io/coollabsio/coolify:{$this->latestVersion}"], $this->server, false);

$base_path = config('coolify.base_config_path');

remote_process([
'curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o /data/coolify/source/upgrade.sh',
"bash /data/coolify/source/upgrade.sh $this->latestVersion",
"curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o {$base_path}/source/upgrade.sh",
"bash {$base_path}/source/upgrade.sh $this->latestVersion",
], $this->server);
}
}
2 changes: 1 addition & 1 deletion bootstrap/helpers/shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

function base_configuration_dir(): string
{
return '/data/coolify';
return config('coolify.base_config_path') ?? '/data/coolify';
}
function application_configuration_dir(): string
{
Expand Down
10 changes: 5 additions & 5 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ services:
container_name: coolify-testing-host
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- dev_coolify_data:/data/coolify
- dev_backups_data:/data/coolify/backups
- dev_postgres_data:/data/coolify/_volumes/database
- dev_redis_data:/data/coolify/_volumes/redis
- dev_minio_data:/data/coolify/_volumes/minio
- dev_coolify_data:${BASE_CONFIG_PATH:-/data/coolify}
- dev_backups_data:${BASE_CONFIG_PATH:-/data/coolify}/backups
- dev_postgres_data:${BASE_CONFIG_PATH:-/data/coolify}/_volumes/database
- dev_redis_data:${BASE_CONFIG_PATH:-/data/coolify}/_volumes/redis
- dev_minio_data:${BASE_CONFIG_PATH:-/data/coolify}/_volumes/minio
networks:
- coolify
mailpit:
Expand Down
16 changes: 8 additions & 8 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ services:
image: "ghcr.io/coollabsio/coolify:${LATEST_IMAGE:-latest}"
volumes:
- type: bind
source: /data/coolify/source/.env
source: ${BASE_CONFIG_PATH:-/data/coolify}/source/.env
target: /var/www/html/.env
read_only: true
- /data/coolify/ssh:/var/www/html/storage/app/ssh
- /data/coolify/applications:/var/www/html/storage/app/applications
- /data/coolify/databases:/var/www/html/storage/app/databases
- /data/coolify/services:/var/www/html/storage/app/services
- /data/coolify/backups:/var/www/html/storage/app/backups
- /data/coolify/webhooks-during-maintenance:/var/www/html/storage/app/webhooks-during-maintenance
- ${BASE_CONFIG_PATH:-/data/coolify}/ssh:/var/www/html/storage/app/ssh
- ${BASE_CONFIG_PATH:-/data/coolify}/applications:/var/www/html/storage/app/applications
- ${BASE_CONFIG_PATH:-/data/coolify}/databases:/var/www/html/storage/app/databases
- ${BASE_CONFIG_PATH:-/data/coolify}/services:/var/www/html/storage/app/services
- ${BASE_CONFIG_PATH:-/data/coolify}/backups:/var/www/html/storage/app/backups
- ${BASE_CONFIG_PATH:-/data/coolify}/webhooks-during-maintenance:/var/www/html/storage/app/webhooks-during-maintenance
environment:
- APP_ENV=production
- APP_NAME
Expand Down Expand Up @@ -98,7 +98,7 @@ services:
- "${SOKETI_PORT:-6001}:6001"
- "6002:6002"
volumes:
- /data/coolify/ssh:/var/www/html/storage/app/ssh
- ${BASE_CONFIG_PATH:-/data/coolify}/ssh:/var/www/html/storage/app/ssh
environment:
APP_NAME: "${APP_NAME:-Coolify}"
SOKETI_DEBUG: "${SOKETI_DEBUG:-false}"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
container_name: coolify-testing-host
volumes:
- //var/run/docker.sock://var/run/docker.sock
- ./:/data/coolify
- ./:${BASE_CONFIG_PATH:-/data/coolify}
coolify:
image: "ghcr.io/coollabsio/coolify:latest"
pull_policy: always
Expand Down
16 changes: 8 additions & 8 deletions other/nightly/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ services:
image: "ghcr.io/coollabsio/coolify:${LATEST_IMAGE:-latest}"
volumes:
- type: bind
source: /data/coolify/source/.env
source: ${BASE_CONFIG_PATH:-/data/coolify}/source/.env
target: /var/www/html/.env
read_only: true
- /data/coolify/ssh:/var/www/html/storage/app/ssh
- /data/coolify/applications:/var/www/html/storage/app/applications
- /data/coolify/databases:/var/www/html/storage/app/databases
- /data/coolify/services:/var/www/html/storage/app/services
- /data/coolify/backups:/var/www/html/storage/app/backups
- /data/coolify/webhooks-during-maintenance:/var/www/html/storage/app/webhooks-during-maintenance
- ${BASE_CONFIG_PATH:-/data/coolify}/ssh:/var/www/html/storage/app/ssh
- ${BASE_CONFIG_PATH:-/data/coolify}/applications:/var/www/html/storage/app/applications
- ${BASE_CONFIG_PATH:-/data/coolify}/databases:/var/www/html/storage/app/databases
- ${BASE_CONFIG_PATH:-/data/coolify}/services:/var/www/html/storage/app/services
- ${BASE_CONFIG_PATH:-/data/coolify}/backups:/var/www/html/storage/app/backups
- ${BASE_CONFIG_PATH:-/data/coolify}/webhooks-during-maintenance:/var/www/html/storage/app/webhooks-during-maintenance
environment:
- APP_ENV=production
- APP_NAME
Expand Down Expand Up @@ -98,7 +98,7 @@ services:
- "${SOKETI_PORT:-6001}:6001"
- "6002:6002"
volumes:
- /data/coolify/ssh:/var/www/html/storage/app/ssh
- ${BASE_CONFIG_PATH:-/data/coolify}/ssh:/var/www/html/storage/app/ssh
environment:
APP_NAME: "${APP_NAME:-Coolify}"
SOKETI_DEBUG: "${SOKETI_DEBUG:-false}"
Expand Down
2 changes: 1 addition & 1 deletion other/nightly/docker-compose.windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
container_name: coolify-testing-host
volumes:
- //var/run/docker.sock://var/run/docker.sock
- ./:/data/coolify
- ./:${BASE_CONFIG_PATH:-/data/coolify}
coolify:
image: "ghcr.io/coollabsio/coolify:latest"
pull_policy: always
Expand Down
176 changes: 109 additions & 67 deletions other/nightly/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,42 @@ if [ "$WARNING_SPACE" = true ]; then
sleep 5
fi

mkdir -p /data/coolify/{source,ssh,applications,databases,backups,services,proxy,webhooks-during-maintenance,sentinel}
mkdir -p /data/coolify/ssh/{keys,mux}
mkdir -p /data/coolify/proxy/dynamic
# Set BASE_CONFIG_PATH to change the installation directory like so:
# curl -fsSL https://cdn.coollabs.io/coolify/install.sh | BASE_CONFIG_PATH=/custom/path/to/coolify sudo -E bash
# useful for immutable OSes like openSUSE MicroOS, Fedora Silverblue, etc...
# priority = .env file > BASE_CONFIG_PATH cli variable > default data/coolify
if [ -f ./.env ]; then
BASE_CONFIG_PATH=$(grep -w "BASE_CONFIG_PATH" ./.env | cut -d "=" -f 2 | tr -d '"') || true
fi
BASE_CONFIG_PATH=${BASE_CONFIG_PATH:-"/data/coolify"}

# Set MANUAL_DEPENDENCIES to allow installation on unsupported platforms
# and skip automatic dependencies installation
MANUAL_DEPENDENCIES=${MANUAL_DEPENDENCIES:-false}

# Early check to see if we can write to install path
if [ ! -w "$BASE_CONFIG_PATH" ]; then
echo "-----------------------"
echo "Error on Installation:"
echo "Directory to install Coolify is not writable. Please check your permissions and try again."
echo "-----------------------"
exit 1
fi

if [ "$MANUAL_DEPENDENCIES" = "true" ]; then
echo "Warning: Manual dependencies mode enabled."
echo "Warning: Skipping OS check and automatic dependencies installation."
echo "Warning: Ensure all required dependencies are installed manually."
fi

chown -R 9999:root /data/coolify
chmod -R 700 /data/coolify
mkdir -p "$BASE_CONFIG_PATH"/{source,ssh,applications,databases,backups,services,proxy,webhooks-during-maintenance,sentinel}
mkdir -p "$BASE_CONFIG_PATH"/ssh/{keys,mux}
mkdir -p "$BASE_CONFIG_PATH"/proxy/dynamic

INSTALLATION_LOG_WITH_DATE="/data/coolify/source/installation-${DATE}.log"
chown -R 9999:root "$BASE_CONFIG_PATH"
chmod -R 700 "$BASE_CONFIG_PATH"

INSTALLATION_LOG_WITH_DATE="$BASE_CONFIG_PATH/source/installation-${DATE}.log"

exec > >(tee -a $INSTALLATION_LOG_WITH_DATE) 2>&1

Expand All @@ -76,7 +104,7 @@ getAJoke() {
fi
}
OS_TYPE=$(grep -w "ID" /etc/os-release | cut -d "=" -f 2 | tr -d '"')
ENV_FILE="/data/coolify/source/.env"
ENV_FILE="$BASE_CONFIG_PATH/source/.env"

# Check if the OS is manjaro, if so, change it to arch
if [ "$OS_TYPE" = "manjaro" ] || [ "$OS_TYPE" = "manjaro-arm" ]; then
Expand Down Expand Up @@ -132,13 +160,16 @@ if [ -z "$LATEST_REALTIME_VERSION" ]; then
fi


case "$OS_TYPE" in
arch | ubuntu | debian | raspbian | centos | fedora | rhel | ol | rocky | sles | opensuse-leap | opensuse-tumbleweed | almalinux | amzn | alpine) ;;
*)
echo "This script only supports Debian, Redhat, Arch Linux, Alpine Linux, or SLES based operating systems for now."
exit
;;
esac
if [ "$MANUAL_DEPENDENCIES" = "false" ]; then
case "$OS_TYPE" in
arch | ubuntu | debian | raspbian | centos | fedora | rhel | ol | rocky | sles | opensuse-leap | opensuse-tumbleweed | almalinux | amzn | alpine) ;;
*)
echo "This script only supports Debian, Redhat, Arch Linux, Alpine Linux, or SLES based operating systems for now."
echo "If you still want to install Coolify, please do it manually, read the documentation: https://coolify.io/docs/installation"
exit
;;
esac
fi

# Overwrite LATEST_VERSION if user pass a version number
if [ "$1" != "" ]; then
Expand All @@ -155,44 +186,47 @@ echo "| Docker | $DOCKER_VERSION"
echo "| Coolify | $LATEST_VERSION"
echo "| Helper | $LATEST_HELPER_VERSION"
echo "| Realtime | $LATEST_REALTIME_VERSION"
echo "| Installation Path | $BASE_CONFIG_PATH"
echo -e "---------------------------------------------\n"
echo -e "1. Installing required packages (curl, wget, git, jq, openssl). "

case "$OS_TYPE" in
arch)
pacman -Sy --noconfirm --needed curl wget git jq openssl >/dev/null || true
;;
alpine)
sed -i '/^#.*\/community/s/^#//' /etc/apk/repositories
apk update >/dev/null
apk add curl wget git jq openssl >/dev/null
;;
ubuntu | debian | raspbian)
apt-get update -y >/dev/null
apt-get install -y curl wget git jq openssl >/dev/null
;;
centos | fedora | rhel | ol | rocky | almalinux | amzn)
if [ "$OS_TYPE" = "amzn" ]; then
dnf install -y wget git jq openssl >/dev/null
else
if ! command -v dnf >/dev/null; then
yum install -y dnf >/dev/null
fi
if ! command -v curl >/dev/null; then
dnf install -y curl >/dev/null
if [ "$MANUAL_DEPENDENCIES" = "false" ]; then
case "$OS_TYPE" in
arch)
pacman -Sy --noconfirm --needed curl wget git jq openssl >/dev/null || true
;;
alpine)
sed -i '/^#.*\/community/s/^#//' /etc/apk/repositories
apk update >/dev/null
apk add curl wget git jq openssl >/dev/null
;;
ubuntu | debian | raspbian)
apt-get update -y >/dev/null
apt-get install -y curl wget git jq openssl >/dev/null
;;
centos | fedora | rhel | ol | rocky | almalinux | amzn)
if [ "$OS_TYPE" = "amzn" ]; then
dnf install -y wget git jq openssl >/dev/null
else
if ! command -v dnf >/dev/null; then
yum install -y dnf >/dev/null
fi
if ! command -v curl >/dev/null; then
dnf install -y curl >/dev/null
fi
dnf install -y wget git jq openssl >/dev/null
fi
dnf install -y wget git jq openssl >/dev/null
fi
;;
sles | opensuse-leap | opensuse-tumbleweed)
zypper refresh >/dev/null
zypper install -y curl wget git jq openssl >/dev/null
;;
*)
echo "This script only supports Debian, Redhat, Arch Linux, or SLES based operating systems for now."
exit
;;
esac
;;
sles | opensuse-leap | opensuse-tumbleweed)
zypper refresh >/dev/null
zypper install -y curl wget git jq openssl >/dev/null
;;
*)
echo "This script only supports Debian, Redhat, Arch Linux, or SLES based operating systems for now."
exit
;;
esac
fi


echo -e "2. Check OpenSSH server configuration. "
Expand Down Expand Up @@ -449,10 +483,10 @@ else
fi

echo -e "5. Download required files from CDN. "
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/.env.production -o /data/coolify/source/.env.production
curl -fsSL $CDN/upgrade.sh -o /data/coolify/source/upgrade.sh
curl -fsSL $CDN/docker-compose.yml -o "$BASE_CONFIG_PATH"/source/docker-compose.yml
curl -fsSL $CDN/docker-compose.prod.yml -o "$BASE_CONFIG_PATH"/source/docker-compose.prod.yml
curl -fsSL $CDN/.env.production -o "$BASE_CONFIG_PATH"/source/.env.production
curl -fsSL $CDN/upgrade.sh -o "$BASE_CONFIG_PATH"/source/upgrade.sh

echo -e "6. Make backup of .env to .env-$DATE"

Expand All @@ -462,7 +496,7 @@ if [ -f $ENV_FILE ]; then
else
echo " - File does not exist: $ENV_FILE"
echo " - Copying .env.production to .env-$DATE"
cp /data/coolify/source/.env.production $ENV_FILE-$DATE
cp "$BASE_CONFIG_PATH"/source/.env.production "$ENV_FILE-$DATE"
# Generate a secure APP_ID and APP_KEY
sed -i "s|^APP_ID=.*|APP_ID=$(openssl rand -hex 16)|" "$ENV_FILE-$DATE"
sed -i "s|^APP_KEY=.*|APP_KEY=base64:$(openssl rand -base64 32)|" "$ENV_FILE-$DATE"
Expand All @@ -483,15 +517,23 @@ fi

# Merge .env and .env.production. New values will be added to .env
echo -e "7. Propagating .env with new values - if necessary."
awk -F '=' '!seen[$1]++' "$ENV_FILE-$DATE" /data/coolify/source/.env.production > $ENV_FILE
awk -F '=' '!seen[$1]++' "$ENV_FILE-$DATE" "$BASE_CONFIG_PATH"/source/.env.production > "$ENV_FILE"

if [ "$AUTOUPDATE" = "false" ]; then
if ! grep -q "AUTOUPDATE=" /data/coolify/source/.env; then
echo "AUTOUPDATE=false" >>/data/coolify/source/.env
if ! grep -q "AUTOUPDATE=" "$BASE_CONFIG_PATH"/source/.env; then
echo "AUTOUPDATE=false" >>"$BASE_CONFIG_PATH"/source/.env
else
sed -i "s|AUTOUPDATE=.*|AUTOUPDATE=false|g" /data/coolify/source/.env
sed -i "s|AUTOUPDATE=.*|AUTOUPDATE=false|g" "$BASE_CONFIG_PATH"/source/.env
fi
fi

# Merge BASE_CONFIG_PATH to .env file
if ! grep -q "BASE_CONFIG_PATH=" "$BASE_CONFIG_PATH"/source/.env; then
echo "BASE_CONFIG_PATH=$BASE_CONFIG_PATH" >>"$BASE_CONFIG_PATH"/source/.env
else
sed -i "s|BASE_CONFIG_PATH=.*|BASE_CONFIG_PATH=$BASE_CONFIG_PATH|g" "$BASE_CONFIG_PATH"/source/.env
fi

echo -e "8. Checking for SSH key for localhost access."
if [ ! -f ~/.ssh/authorized_keys ]; then
mkdir -p ~/.ssh
Expand All @@ -506,24 +548,24 @@ set -e

if [ "$IS_COOLIFY_VOLUME_EXISTS" -eq 0 ]; then
echo " - Generating SSH key."
ssh-keygen -t ed25519 -a 100 -f /data/coolify/ssh/keys/[email protected] -q -N "" -C coolify
chown 9999 /data/coolify/ssh/keys/[email protected]
ssh-keygen -t ed25519 -a 100 -f "$BASE_CONFIG_PATH"/ssh/keys/[email protected] -q -N "" -C coolify
chown 9999 "$BASE_CONFIG_PATH"/ssh/keys/[email protected]
sed -i "/coolify/d" ~/.ssh/authorized_keys
cat /data/coolify/ssh/keys/[email protected] >> ~/.ssh/authorized_keys
rm -f /data/coolify/ssh/keys/[email protected]
cat "$BASE_CONFIG_PATH"/ssh/keys/[email protected] >> ~/.ssh/authorized_keys
rm -f "$BASE_CONFIG_PATH"/ssh/keys/[email protected]
fi

chown -R 9999:root /data/coolify
chmod -R 700 /data/coolify
chown -R 9999:root "$BASE_CONFIG_PATH"
chmod -R 700 "$BASE_CONFIG_PATH"

echo -e "9. Installing Coolify ($LATEST_VERSION)"
echo -e " - It could take a while based on your server's performance, network speed, stars, etc."
echo -e " - Please wait."
getAJoke

bash /data/coolify/source/upgrade.sh "${LATEST_VERSION:-latest}" "${LATEST_HELPER_VERSION:-latest}"
bash "$BASE_CONFIG_PATH"/source/upgrade.sh "${LATEST_VERSION:-latest}" "${LATEST_HELPER_VERSION:-latest}"
echo " - Coolify installed successfully."
rm -f $ENV_FILE-$DATE
rm -f "$ENV_FILE-$DATE"

echo " - Waiting for 20 seconds for Coolify (database migrations) to be ready."
getAJoke
Expand Down Expand Up @@ -553,5 +595,5 @@ if [ -n "$PRIVATE_IPS" ]; then
fi
done
fi
echo -e "\nWARNING: It is highly recommended to backup your Environment variables file (/data/coolify/source/.env) to a safe location, outside of this server (e.g. into a Password Manager).\n"
cp /data/coolify/source/.env /data/coolify/source/.env.backup
echo -e "\nWARNING: It is highly recommended to backup your Environment variables file ($BASE_CONFIG_PATH/source/.env) to a safe location, outside of this server (e.g. into a Password Manager).\n"
cp "$BASE_CONFIG_PATH"/source/.env "$BASE_CONFIG_PATH"/source/.env.backup
Loading