build-and-deploy.sh raw
1 #!/bin/bash
2 # Build and deploy ORLY relay binaries
3 #
4 # IMPORTANT: relay.orly.dev is amd64 (x86_64), NOT arm64.
5 # This script builds the UNIFIED binary (./cmd/orly) which includes
6 # launcher, db, acl, and relay subcommands.
7 #
8 # For the recommended single-command upgrade flow, use:
9 # ./scripts/upgrade.sh
10 #
11 # This script is retained for deploying to multiple hosts or custom targets.
12 #
13 # Usage:
14 # ./scripts/build-and-deploy.sh [relay.orly.dev|new.orly.dev|both] [--restart]
15
16 set -e
17
18 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
19 PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
20 BUILD_DIR="$PROJECT_DIR/build-amd64"
21
22 # Colors
23 GREEN='\033[0;32m'
24 YELLOW='\033[1;33m'
25 NC='\033[0m'
26
27 log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
28 log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
29
30 # Parse arguments
31 TARGET="${1:-relay.orly.dev}"
32 RESTART_FLAG=""
33 if [[ "$2" == "--restart" ]] || [[ "$1" == "--restart" ]]; then
34 RESTART_FLAG="--restart"
35 fi
36
37 # Read version
38 VERSION=$(cat "$PROJECT_DIR/pkg/version/version" | tr -d '[:space:]')
39 log_info "Version: $VERSION"
40
41 # Build for amd64 (relay.orly.dev is x86_64)
42 log_info "Building amd64 unified binary..."
43 cd "$PROJECT_DIR"
44 mkdir -p "$BUILD_DIR"
45
46 export CGO_ENABLED=0
47 export GOOS=linux
48 export GOARCH=amd64
49
50 # Build web UI if bun is available
51 if command -v bun &>/dev/null && [[ -d "app/web" ]]; then
52 log_info "Building web UI..."
53 (cd app/web && bun install --silent && bun run build)
54 fi
55
56 # Build unified binary (includes launcher, db, acl subcommands)
57 log_info "Building orly (unified binary with subcommands)..."
58 go build -ldflags "-s -w" -o "$BUILD_DIR/orly" ./cmd/orly
59
60 log_info "Build complete. Binary in $BUILD_DIR"
61 ls -la "$BUILD_DIR"
62
63 # Deploy function
64 deploy_to() {
65 local host="$1"
66 log_info "Deploying to $host..."
67 "$SCRIPT_DIR/deploy-orly.sh" --host "$host" --local-path "$BUILD_DIR" $RESTART_FLAG
68 }
69
70 # Deploy based on target
71 case "$TARGET" in
72 both)
73 deploy_to "relay.orly.dev"
74 deploy_to "new.orly.dev"
75 ;;
76 relay.orly.dev|new.orly.dev)
77 deploy_to "$TARGET"
78 ;;
79 --restart)
80 # --restart was first arg, deploy to default
81 deploy_to "relay.orly.dev"
82 ;;
83 *)
84 log_warn "Unknown target: $TARGET. Using relay.orly.dev"
85 deploy_to "relay.orly.dev"
86 ;;
87 esac
88
89 log_info "Done! Version $VERSION deployed."
90