-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·163 lines (145 loc) · 4.73 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·163 lines (145 loc) · 4.73 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env bash
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
# -- output helpers ---------------------------------------------------------
RED=$'\033[0;31m'; GREEN=$'\033[0;32m'; YELLOW=$'\033[0;33m'; BLUE=$'\033[0;34m'; NC=$'\033[0m'
print_success() { printf '%s\n' "${GREEN}✓ $*${NC}"; }
print_error() { printf '%s\n' "${RED}✗ $*${NC}" >&2; }
print_warning() { printf '%s\n' "${YELLOW}! $*${NC}"; }
print_info() { printf '%s\n' "${BLUE}» $*${NC}"; }
# shellcheck disable=SC2086 # word-splitting the command prefix is intentional
WRANGLER="pnpm --filter @cosimi/api exec wrangler"
run_gates() {
print_info "Running standing gates…"
pnpm -r typecheck \
&& pnpm lint \
&& pnpm format:check \
&& pnpm -r --workspace-concurrency=1 test \
&& pnpm --filter @portf/web build \
&& pnpm --filter @portf/web test:ssg
print_success "Gates green."
}
confirm() {
local reply
read -rp "$1 [y/N] " reply
[[ "$reply" == "y" || "$reply" == "Y" ]]
}
deploy_portf_pages() {
run_gates
print_info "Building @portf/web…"
pnpm --filter @portf/web build
print_info "Deploying portf → Pages…"
# shellcheck disable=SC2086
$WRANGLER pages deploy ../portf/dist/client --project-name portf
print_success "portf Pages deployed."
}
deploy_web_pages() {
run_gates
print_info "Building @cosimi/web…"
pnpm --filter @cosimi/web build
print_info "Deploying web → Pages…"
# shellcheck disable=SC2086
$WRANGLER pages deploy ../web/dist --project-name cosimi-web
print_success "web Pages deployed."
}
deploy_portf_api() {
run_gates
print_info "Deploying portf-api Worker (env.portf)…"
(cd playgrounds/api && pnpm exec wrangler deploy -e portf)
print_success "portf-api deployed."
}
deploy_cosimi_api() {
run_gates
print_info "Deploying cosimi-api Worker (env.cosimi)…"
(cd playgrounds/api && pnpm exec wrangler deploy -e cosimi)
print_success "cosimi-api deployed."
}
deploy_all() {
run_gates
pnpm --filter @portf/web build
# shellcheck disable=SC2086
$WRANGLER pages deploy ../portf/dist/client --project-name portf
pnpm --filter @cosimi/web build
# shellcheck disable=SC2086
$WRANGLER pages deploy ../web/dist --project-name cosimi-web
(cd playgrounds/api && pnpm exec wrangler deploy -e portf && pnpm exec wrangler deploy -e cosimi)
print_success "Full deploy complete."
}
run_migrations() {
local target db_url
local -a targets
printf 'Migrate which DB? [1] portf [2] cosimi [3] both: '
read -r target
case "$target" in
1) targets=("portf") ;;
2) targets=("cosimi") ;;
3) targets=("portf" "cosimi") ;;
*) print_error "Invalid choice."; return 1 ;;
esac
for t in "${targets[@]}"; do
print_info "Paste the Neon DIRECT (non-pooled) URL for the ${t} DB (input hidden):"
read -rsp " ${t} DATABASE_URL: " db_url; printf '\n'
if [[ -z "$db_url" ]]; then print_error "Empty URL — skipping ${t}."; continue; fi
print_info "Running migrations against ${t}…"
DATABASE_URL="$db_url" node_modules/.bin/tsx packages/db/src/migrate.ts up
print_success "Migrations applied to ${t}."
unset db_url
done
}
tail_logs() {
local choice
printf 'Tail which worker? [1] portf-api [2] cosimi-api: '
read -r choice
case "$choice" in
1) (cd playgrounds/api && pnpm exec wrangler tail -e portf) ;;
2) (cd playgrounds/api && pnpm exec wrangler tail -e cosimi) ;;
*) print_error "Invalid choice." ;;
esac
}
status() {
# shellcheck disable=SC2086
{ print_info "wrangler account:"; $WRANGLER whoami || true; }
# shellcheck disable=SC2086
{ print_info "Pages projects:"; $WRANGLER pages project list || true; }
print_info "portf /healthz:"; curl -fsS https://8bu.dev/api/healthz || print_warning "portf health unreachable"
printf '\n'
print_info "cosimi /healthz:"; curl -fsS https://cosimi.8bu.dev/api/healthz || print_warning "cosimi health unreachable"
printf '\n'
}
menu() {
cat <<'MENU'
cosimi deploy - Cloudflare + Neon (manual)
2) Deploy portf → Pages (8bu.dev)
3) Deploy web → Pages (cosimi.8bu.dev)
4) Deploy portf-api → Worker (env.portf)
5) Deploy cosimi-api → Worker (env.cosimi)
6) Deploy ALL (gates → 2,3,4,5)
7) Run Neon migrations
8) Tail logs
9) Status
10) Run standing gates only
0) Exit
MENU
printf 'Choose: '
}
main() {
local choice
while true; do
menu
read -r choice
case "$choice" in
2) deploy_portf_pages ;;
3) deploy_web_pages ;;
4) deploy_portf_api ;;
5) deploy_cosimi_api ;;
6) confirm "Deploy EVERYTHING to production?" && deploy_all ;;
7) run_migrations ;;
8) tail_logs ;;
9) status ;;
10) run_gates ;;
0) print_info "Bye."; exit 0 ;;
*) print_error "Invalid choice." ;;
esac
done
}
main "$@"