-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_balena.sh
executable file
·56 lines (46 loc) · 1.69 KB
/
deploy_balena.sh
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
#!/bin/bash
# This script deploys a k3s cluster to a Balena fleet
#
# The script will:
# - Copy the appropriate docker-compose file based on CPU/GPU selection
# - Push the configuration to the specified Balena fleet
# - Clean up temporary files on exit
#
# This is necessary because
# a) If we don't have a GPU, we don't want to deploy the `gpu` container (which will fail and is a dependency of `server`)
# b) Balena will ALWAYS build the `docker-compose.yml` file in the root directory (not configurable)
# c) Balena doesn't support docker-compose overrides or profiles, so we can't use a single file neatly
#
# The script takes two arguments:
# 1. fleet_name: The name of the Balena fleet to deploy to
# 2. cpu|gpu: Whether to deploy with CPU-only or GPU support
#
# Examples:
# ./deploy_balena.sh my-fleet cpu # Deploy to a fleet of CPU-only devices
# ./deploy_balena.sh my-fleet gpu # Deploy to a fleet of GPU devices w/ NVIDIA drivers and GPU operator
if [ "$#" -lt 2 ]; then
echo "Usage: $0 <fleet_name> <cpu|gpu>"
exit 1
fi
cd "$(dirname "$0")"
FLEET_NAME=$1
FLAVOR=$(echo "$2" | tr '[:upper:]' '[:lower:]')
if [ "$FLAVOR" != "cpu" ] && [ "$FLAVOR" != "gpu" ]; then
echo "Error: Second argument must be 'cpu' or 'gpu'"
exit 1
fi
# Copy the appropriate compose file
if [ "$FLAVOR" == "cpu" ]; then
cp deploy/balena-k3s/resources/docker-compose-cpu.yml docker-compose.yml
else
cp deploy/balena-k3s/resources/docker-compose-gpu.yml docker-compose.yml
fi
cleanup() {
echo "Cleaning up..."
rm -f docker-compose.yml
}
trap cleanup EXIT
# Push to balena
echo "Pushing to fleet: $FLEET_NAME with $FLAVOR configuration..."
balena push "$FLEET_NAME"
echo "Deployment complete!"