mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
feat(server-transfer): run instance migration as a background job (#12180)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4553454f89
commit
7c14c0098e
+23
-3
@@ -24,12 +24,17 @@
|
||||
#
|
||||
# Env: COOLIFY_DEV_SERVER_BACKEND=auto|lima|testing-host, COOLIFY_DEV_KVM_PROFILE=<profile>
|
||||
#
|
||||
# Side by side: COOLIFY_DEV_INSTANCE=<name> COOLIFY_DEV_SIDE_BY_SIDE=1 starts a second instance of
|
||||
# this checkout without stopping the other ones (for example a transfer target, see
|
||||
# scripts/transfer-test). It gets its own SSH key folder; the instance remembers the mode.
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
ROOT="$(pwd -P)"
|
||||
|
||||
COMPOSE_FILE="docker-compose.dev-multi.yml"
|
||||
SIDE_BY_SIDE_COMPOSE_FILE="docker-compose.dev-side-by-side.yml"
|
||||
GIT_COMMON_DIR="$(git rev-parse --path-format=absolute --git-common-dir)"
|
||||
# Shared by all worktrees, so slots, APP_KEYs, and data survive worktree removal.
|
||||
ENV_DIR="$(dirname "$GIT_COMMON_DIR")/.dev-instances"
|
||||
@@ -38,7 +43,7 @@ QEMU_STORAGE="${DEVELOPMENT_QEMU_STORAGE_PATH:-/var/lib/libvirt/images/coolify-d
|
||||
LEGACY_CONTAINERS=(coolify coolify-db coolify-redis coolify-vite coolify-mail coolify-minio coolify-minio-init coolify-testing-host)
|
||||
|
||||
usage() {
|
||||
sed -n '2,26p' "$0" | sed 's/^# \?//'
|
||||
sed -n '2,30p' "$0" | sed 's/^# \?//'
|
||||
}
|
||||
|
||||
normalize_name() {
|
||||
@@ -66,6 +71,7 @@ current_instance() {
|
||||
project_name() { echo "coolify-dev-$1"; }
|
||||
env_file() { echo "$ENV_DIR/$1.env"; }
|
||||
env_value() { grep -E "^$2=" "$(env_file "$1")" | cut -d= -f2-; }
|
||||
is_side_by_side() { [[ -f "$(env_file "$1")" ]] && grep -qxF 'DEV_SIDE_BY_SIDE=1' "$(env_file "$1")"; }
|
||||
|
||||
# Lowest free slot (1..254), stable per instance name. It selects the port block
|
||||
# and the libvirt network (10.221.<slot>.0/24) of the instance.
|
||||
@@ -135,6 +141,11 @@ ensure_env() {
|
||||
fi
|
||||
printf '%s\n' "$existing_key" >"$ENV_DIR/$name.appkey"
|
||||
|
||||
local side_by_side="${COOLIFY_DEV_SIDE_BY_SIDE:-}"
|
||||
if [[ -z "$side_by_side" ]] && is_side_by_side "$name"; then
|
||||
side_by_side=1
|
||||
fi
|
||||
|
||||
cat >"$env_file" <<EOF
|
||||
# Generated by scripts/dev for instance ${name} — do not commit
|
||||
COMPOSE_PROJECT_NAME=$(project_name "$name")
|
||||
@@ -158,6 +169,9 @@ PUSHER_APP_ID=coolify-${name}
|
||||
PUSHER_APP_KEY=coolify-${name}
|
||||
PUSHER_APP_SECRET=coolify-${name}
|
||||
EOF
|
||||
if [[ "$side_by_side" == 1 ]]; then
|
||||
echo 'DEV_SIDE_BY_SIDE=1' >>"$env_file"
|
||||
fi
|
||||
}
|
||||
|
||||
# compose <name> <args...>: .env of the checkout first, generated instance env wins.
|
||||
@@ -168,7 +182,11 @@ compose() {
|
||||
if [[ -f .env ]]; then
|
||||
env_files+=(--env-file .env)
|
||||
fi
|
||||
docker compose -p "$(project_name "$name")" -f "$COMPOSE_FILE" \
|
||||
local -a compose_files=(-f "$COMPOSE_FILE")
|
||||
if is_side_by_side "$name"; then
|
||||
compose_files+=(-f "$SIDE_BY_SIDE_COMPOSE_FILE")
|
||||
fi
|
||||
docker compose -p "$(project_name "$name")" "${compose_files[@]}" \
|
||||
"${env_files[@]}" --env-file "$(env_file "$name")" "${profiles[@]}" "$@"
|
||||
}
|
||||
|
||||
@@ -221,12 +239,14 @@ wait_for_coolify() {
|
||||
|
||||
# Only one instance of a checkout runs at a time: they share its ports (main checkout)
|
||||
# and its public/hot Vite file. The legacy fixed-name stack also holds the main ports.
|
||||
# Side-by-side instances have their own ports and run next to the others on purpose.
|
||||
stop_other_checkout_instances() {
|
||||
local file other
|
||||
is_side_by_side "$instance" && return 0
|
||||
for file in "$ENV_DIR"/*.env; do
|
||||
[[ -f "$file" ]] || continue
|
||||
other="$(basename "$file" .env)"
|
||||
if [[ "$other" != "$instance" ]] && grep -qxF "DEV_CHECKOUT=$ROOT" "$file" &&
|
||||
if [[ "$other" != "$instance" ]] && ! is_side_by_side "$other" && grep -qxF "DEV_CHECKOUT=$ROOT" "$file" &&
|
||||
[[ -n "$(docker ps -q --filter "label=com.docker.compose.project=$(project_name "$other")")" ]]; then
|
||||
echo "Stopping instance ${other} (same checkout)"
|
||||
docker compose -p "$(project_name "$other")" stop
|
||||
|
||||
Reference in New Issue
Block a user