-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapply_routing_patch.sh
More file actions
executable file
·85 lines (65 loc) · 2.16 KB
/
apply_routing_patch.sh
File metadata and controls
executable file
·85 lines (65 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
set -euo pipefail
FORK_URL="${FORK_URL:-https://github.com/Iisyourdad/coolify.git}"
UPSTREAM_URL="${UPSTREAM_URL:-https://github.com/coollabsio/coolify.git}"
BRANCH="${BRANCH:-fix/remote-server-forwarding}"
BASE_REF="${BASE_REF:-upstream/next}"
CONTAINER="${CONTAINER:-coolify}"
DEST_DIR="${DEST_DIR:-/var/www/html}"
WORKDIR="$(mktemp -d "${TMPDIR:-/tmp}/apply-routing-patch.XXXXXX")"
REPO_DIR="$WORKDIR/repo"
FILES_DIR="$WORKDIR/files"
cleanup() {
rm -rf "$WORKDIR"
}
trap cleanup EXIT
echo "==> Using temporary workspace: $WORKDIR"
echo "==> Fork URL: $FORK_URL"
echo "==> Upstream: $UPSTREAM_URL"
echo "==> Branch: $BRANCH"
echo "==> Base ref: $BASE_REF"
echo "==> Container: $CONTAINER"
echo "==> Dest dir: $DEST_DIR"
echo
docker inspect "$CONTAINER" >/dev/null 2>&1 || {
echo "Container not found: $CONTAINER"
exit 1
}
echo "==> Cloning fork into temp dir"
git clone --quiet "$FORK_URL" "$REPO_DIR"
cd "$REPO_DIR"
echo "==> Adding upstream"
git remote add upstream "$UPSTREAM_URL" 2>/dev/null || true
echo "==> Fetching latest refs"
git fetch --prune origin
git fetch --prune upstream
echo "==> Checking out latest branch"
git checkout -B "$BRANCH" "origin/$BRANCH"
echo "==> Finding changed files"
CHANGED_FILES="$(git diff --name-only "$BASE_REF...$BRANCH")"
if [ -z "$CHANGED_FILES" ]; then
echo "No changed files found for $BASE_REF...$BRANCH"
exit 1
fi
printf '%s\n' "$CHANGED_FILES"
echo
echo "==> Preparing changed files in temp dir"
mkdir -p "$FILES_DIR"
printf '%s\n' "$CHANGED_FILES" | while read -r f; do
[ -n "$f" ] || continue
[ -f "$f" ] || continue
mkdir -p "$FILES_DIR/$(dirname "$f")"
cp --parents "$f" "$FILES_DIR/"
done
echo "==> Applying files into container"
find "$FILES_DIR" -type f | while read -r local_file; do
rel_path="${local_file#$FILES_DIR/}"
container_file="$DEST_DIR/$rel_path"
container_parent="$(dirname "$container_file")"
echo "==> Processing $rel_path"
docker exec "$CONTAINER" sh -lc "mkdir -p '$container_parent' && rm -f '$container_file'"
docker cp "$local_file" "$CONTAINER:$container_file"
done
echo
echo "==> Done"
echo "Only the script remains. Temporary files were cleaned up."