Skip to content

Commit 0bfbc48

Browse files
committed
add scripts to quickly manually upgrade the auto upgrader
1 parent f50f24b commit 0bfbc48

10 files changed

Lines changed: 319 additions & 13 deletions

.github/scripts/on_release_deleted.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ for FTAG in dev stable latest; do
6666
latest) TARGET="$LATEST_TAG" ;;
6767
esac
6868

69+
if [[ -z "$TARGET" ]]; then
70+
echo "⚠️ No tag found for $FTAG — skipping"
71+
continue
72+
fi
73+
74+
TARGET="${TARGET#v}"
6975
if [[ -n "$TARGET" ]]; then
7076
echo "🏷️ Re-tagging $IMAGE:$FTAG$IMAGE:$TARGET"
7177
docker buildx imagetools create \

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
- [How It Works](#how-it-works)
3030
- [Quick Start](#quick-start)
3131
- [Quick Stop](#quick-stop)
32+
- [Quick Upgrade](#quick-upgrade)
3233
- [Installation](#installation)
3334
- [Run as Process](#run-as-process)
3435
- [Run as Service](#run-as-service)
3536
- [Run as Container](#run-as-container)
37+
- [Upgrade](#upgrade)
3638
- [Uninstallation](#uninstallation)
3739
- [Remove Process](#remove-process)
3840
- [Remove Service](#remove-service)
@@ -150,6 +152,16 @@ Use `-h` to see the options
150152

151153
<br />
152154

155+
# 🔄 Quick Upgrade <a id="quick-upgrade"></a>
156+
157+
To upgrade the Auto Upgrade when a new release has been deployed, you can run
158+
159+
```bash
160+
./scripts/auto_upgrader/auto_upgrader_upgrade.sh
161+
```
162+
163+
<br />
164+
153165
# 🛠️ Installation <a id="installation"></a>
154166

155167
You can install the Auto Upgrader in one of three ways:
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Help function
6+
show_help() {
7+
echo "Usage: $0 [--execution=process|container|service]"
8+
echo
9+
echo "Options:"
10+
echo " --execution Specify the execution method (default: service)"
11+
echo " --help Show this help message"
12+
exit 0
13+
}
14+
15+
OPTIONS="e:h"
16+
LONGOPTIONS="execution:,help:"
17+
18+
# Parse the options and their arguments
19+
params="$(getopt -o $OPTIONS -l $LONGOPTIONS: --name "$0" -- "$@")"
20+
21+
# Check for getopt errors
22+
if [ $? -ne 0 ]; then
23+
exit 1
24+
fi
25+
26+
METHOD=service
27+
28+
# Parse arguments
29+
while [ "$#" -gt 0 ]; do
30+
case "$1" in
31+
-e |--execution)
32+
METHOD="$2"
33+
shift 2
34+
;;
35+
-h | --help)
36+
show_help
37+
exit 0
38+
;;
39+
*)
40+
echo "Unrecognized option '$1'"
41+
exit 1
42+
;;
43+
esac
44+
done
45+
46+
# Parse arguments
47+
while [ "$#" -gt 0 ]; do
48+
case "$1" in
49+
-e |--execution)
50+
METHOD="$2"
51+
shift 2
52+
;;
53+
-h | --help)
54+
show_help
55+
exit 0
56+
;;
57+
*)
58+
echo "Unrecognized option '$1'"
59+
exit 1
60+
;;
61+
esac
62+
done
63+
64+
# 🧠 Function: Setup for process mode
65+
setup_process() {
66+
echo "⚙️ Setting up for 'process' mode..."
67+
68+
# Upgrade the auto upgrader as process
69+
./subvortex/auto_upgrader/deployment/proecss/auto_upgrader_process_upgrade.sh
70+
71+
# Add any other logic specific to process mode here
72+
echo "✅ Process started."
73+
}
74+
75+
# 🐳 Function: Setup for container mode
76+
setup_container() {
77+
echo "🐳 Setting up for 'container' mode..."
78+
79+
# Start the auto upgrader as service
80+
./subvortex/auto_upgrader/deployment/container/auto_upgrader_container_upgrade.sh
81+
82+
# Add any other container-specific logic here
83+
echo "✅ Container started."
84+
}
85+
86+
# 🧩 Function: Setup for service mode
87+
setup_service() {
88+
echo "🧩 Setting up for 'service' mode..."
89+
90+
# Start the auto upgrader as service
91+
./subvortex/auto_upgrader/deployment/service/auto_upgrader_service_upgrade.sh
92+
93+
# Add logic for systemd, service checks, etc. if needed
94+
echo "✅ Service started."
95+
}
96+
97+
# 🚀 Function: Dispatch based on method
98+
run_setup() {
99+
case "$METHOD" in
100+
process)
101+
setup_process
102+
;;
103+
container)
104+
setup_container
105+
;;
106+
service)
107+
setup_service
108+
;;
109+
*)
110+
echo "❌ Unknown SUBVORTEX_EXECUTION_METHOD: '$METHOD'"
111+
exit 1
112+
;;
113+
esac
114+
}
115+
116+
# 🔥 Execute
117+
run_setup
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Determine script directory dynamically to ensure everything runs in ./scripts/api/
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
cd "$SCRIPT_DIR/../.."
8+
9+
# Load environment variables
10+
export $(grep -v '^#' .env | xargs)
11+
12+
# Check which command is available
13+
if command -v docker &> /dev/null && docker compose version &> /dev/null; then
14+
DOCKER_CMD="docker compose"
15+
elif command -v docker-compose &> /dev/null; then
16+
DOCKER_CMD="docker-compose"
17+
else
18+
echo "❌ Neither 'docker compose' nor 'docker-compose' is installed. Please install Docker Compose."
19+
exit 1
20+
fi
21+
22+
# Install watchtower
23+
./../../scripts/watchtower/watchtower_start.sh
24+
25+
echo "📥 Pulling latest image for $SERVICE_NAME..."
26+
docker compose pull "$SERVICE_NAME"
27+
28+
echo "🔄 Recreating container with updated image..."
29+
$DOCKER_CMD -f ../../docker-compose.yml up auto_upgrader -d --no-deps --force-recreate
30+
31+
echo "✅ Auto Upgrader upgraded successfully"

subvortex/auto_upgrader/deployment/process/auto_upgrader_process_start.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set -e
44

5+
SERVICE_NAME=subvortex-auto-upgrader
6+
57
# Determine script directory dynamically to ensure everything runs in ./scripts/api/
68
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
79
cd "$SCRIPT_DIR/../.."
@@ -36,7 +38,7 @@ done < <(env)
3638

3739
# Start with PM2
3840
pm2 start src/main.py \
39-
--name subvortex-auto-upgrader \
41+
--name $SERVICE_NAME \
4042
--interpreter python3 -- \
4143
"${ARGS[@]}"
4244

subvortex/auto_upgrader/deployment/process/auto_upgrader_process_stop.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
set -e
44

5+
SERVICE_NAME=subvortex-auto-upgrader
6+
57
# Determine script directory dynamically to ensure everything runs in ./scripts/api/
68
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
79
cd "$SCRIPT_DIR/../.."
810

911
# Start with PM2
10-
pm2 stop --name subvortex-auto-upgrader
12+
pm2 stop --name $SERVICE_NAME
1113

1214
echo "✅ Auto Upgrader stopped successfully"

subvortex/auto_upgrader/deployment/process/auto_upgrader_process_teardown.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
set -e
44

5-
SERVICE_NAME=auto-upgrader
6-
PACKAGE_NAME="subvortex-auto-upgrader"
5+
SERVICE_NAME=subvortex-auto-upgrader
76

87
# Determine script directory dynamically to ensure everything runs in ./scripts/api/
98
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -29,11 +28,11 @@ if [[ -d "venv" ]]; then
2928
echo "Activating virtual environment to uninstall dependencies..."
3029
source "venv/bin/activate"
3130

32-
if pip list | grep -q "$PACKAGE_NAME"; then
33-
echo "Uninstalling editable package: $PACKAGE_NAME..."
34-
pip uninstall -y "$PACKAGE_NAME"
31+
if pip list | grep -q "$SERVICE_NAME"; then
32+
echo "Uninstalling editable package: $SERVICE_NAME..."
33+
pip uninstall -y "$SERVICE_NAME"
3534
else
36-
echo "Editable package $PACKAGE_NAME not found. Skipping."
35+
echo "Editable package $SERVICE_NAME not found. Skipping."
3736
fi
3837

3938
# Uninstall dependencies
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
SERVICE_NAME=subvortex-auto-upgrader
6+
7+
# Determine script directory dynamically to ensure everything runs in ./scripts/api/
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
cd "$SCRIPT_DIR/../.."
10+
11+
# Check for uncommitted changes
12+
if ! git diff --quiet || ! git diff --cached --quiet; then
13+
echo "📦 Stashing local changes..."
14+
git stash push -u -m "Auto stash before pull"
15+
fi
16+
17+
# Check if branch is tracking a remote
18+
BRANCH=$(git rev-parse --abbrev-ref HEAD)
19+
UPSTREAM=$(git rev-parse --abbrev-ref "$BRANCH@{upstream}" 2>/dev/null || true)
20+
21+
if [[ -z "$UPSTREAM" ]]; then
22+
echo "❌ Branch '$BRANCH' is not tracking any remote branch. Cannot pull safely."
23+
exit 1
24+
fi
25+
26+
# Pull latest changes from upstream
27+
echo "🔄 Pulling latest changes from $UPSTREAM..."
28+
git pull --ff-only
29+
30+
# Install python if not already done
31+
if ! command -v python3 &> /dev/null; then
32+
echo "Python3 not found. Installing..."
33+
bash "../../python/python_setup.sh"
34+
fi
35+
36+
# Create virtual environment
37+
python3 -m venv venv
38+
39+
# Activate virtual environment
40+
source venv/bin/activate
41+
42+
# Install dependencies
43+
if [[ -f "requirements.txt" ]]; then
44+
pip install -r requirements.txt
45+
else
46+
echo "⚠️ requirements.txt not found. Skipping dependency installation."
47+
fi
48+
49+
# Load environment variables
50+
export $(grep -v '^#' .env | xargs)
51+
52+
# Install dependencies specific to the observer
53+
pip install ".[$SUBVORTEX_EXECUTION_ROLE]"
54+
55+
# Install SubVortex in Editable Mode
56+
pip install -e ../../
57+
58+
if pm2 list | grep -qw "$SERVICE_NAME"; then
59+
echo "🔄 Restarting PM2 service: $SERVICE_NAME"
60+
pm2 restart "$SERVICE_NAME"
61+
else
62+
./deployment/process/auto_upgrader_process.start.sh
63+
fi
64+
65+
echo "✅ Auto Upgrader upgraded successfully"

subvortex/auto_upgrader/deployment/service/auto_upgrader_service_teardown.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
set -e
44

55
SERVICE_NAME=subvortex-auto-upgrader
6-
PACKAGE_NAME=auto-upgrader
76

87
# Determine script directory dynamically to ensure everything runs in ./scripts/api/
98
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -40,11 +39,11 @@ if [[ -d "venv" ]]; then
4039
echo "Activating virtual environment to uninstall dependencies..."
4140
source "venv/bin/activate"
4241

43-
if pip list | grep -q "$PACKAGE_NAME"; then
44-
echo "Uninstalling editable package: $PACKAGE_NAME..."
45-
pip uninstall -y "$PACKAGE_NAME"
42+
if pip list | grep -q "$SERVICE_NAME"; then
43+
echo "Uninstalling editable package: $SERVICE_NAME..."
44+
pip uninstall -y "$SERVICE_NAME"
4645
else
47-
echo "Editable package $PACKAGE_NAME not found. Skipping."
46+
echo "Editable package $SERVICE_NAME not found. Skipping."
4847
fi
4948

5049
# Uninstall dependencies

0 commit comments

Comments
 (0)