unoverse 0.1.130 → 0.1.132
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/operator/lib/deploy.sh +44 -11
- package/package.json +1 -1
package/operator/lib/deploy.sh
CHANGED
|
@@ -41,8 +41,12 @@
|
|
|
41
41
|
# exists because the opposite mistake is what wiped this exact cluster's firewall once
|
|
42
42
|
# already: an authoritative write that assumed the whole list was ours to own.
|
|
43
43
|
_operator_db_access() {
|
|
44
|
-
|
|
45
|
-
cluster
|
|
44
|
+
# `$2` is the cluster, when the CALLER already knows it. The monorepo has no ground to
|
|
45
|
+
# read one from — it develops against a cluster named only in .env — so re-deriving it
|
|
46
|
+
# from terraform.tfvars here meant this returned 0 and did nothing in the one place the
|
|
47
|
+
# developer actually types `npm run dev`.
|
|
48
|
+
local cloud="$1" dir="$ROOT/infra/$cloud" cluster="${2:-}"
|
|
49
|
+
[ -n "$cluster" ] || cluster=$(grep -E '^existing_pg_cluster_name[[:space:]]*=' "$dir/terraform.tfvars" 2>/dev/null | sed -E 's/.*"([^"]+)".*/\1/')
|
|
46
50
|
[ -n "$cluster" ] || return 0
|
|
47
51
|
[ -n "${DIGITALOCEAN_TOKEN:-}" ] || return 0
|
|
48
52
|
mkdir -p "$ROOT/.unoverse"
|
|
@@ -103,13 +107,26 @@ NODE
|
|
|
103
107
|
# database.
|
|
104
108
|
cmd_db_allow() {
|
|
105
109
|
local cloud
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
# DIGITALOCEAN ONLY, and it is not an oversight. This joins a MANAGED DATABASE's
|
|
111
|
+
# trusted-source list through the DO API, and AWS has no equivalent to join: RDS
|
|
112
|
+
# reachability is a VPC security group, owned by Terraform and changed by `deploy`, not by
|
|
113
|
+
# a developer's laptop asking an API at runtime. Offering `db-allow aws` produced a
|
|
114
|
+
# ground-picker prompt for a cloud that would then have done nothing.
|
|
115
|
+
# A GROUND IS OPTIONAL HERE. This used to `return 1` the moment the picker found none,
|
|
116
|
+
# which made the .env fallback below unreachable in the monorepo — the one checkout that
|
|
117
|
+
# has no ground and the one the fallback was written for. Only ask the picker when there
|
|
118
|
+
# is something to pick, so an ambiguous two-ground universe still stops, while a
|
|
119
|
+
# groundless checkout proceeds to look the cluster up where it actually knows it.
|
|
120
|
+
cloud=""
|
|
121
|
+
if ls "$ROOT"/infra/*/terraform.tfvars >/dev/null 2>&1; then
|
|
122
|
+
SELF_CMD="unoverse db-allow" \
|
|
123
|
+
GROUNDS_ONLY="digitalocean" \
|
|
124
|
+
GROUNDS_ONLY_WHY="On AWS the database is reached through its VPC security group, which the ground owns — change it in infra/aws and run ${BOLD}unoverse deploy aws${NC}." \
|
|
125
|
+
cloud=$(_pick_ground "${1:-}") || return 1
|
|
126
|
+
fi
|
|
110
127
|
|
|
111
|
-
local cluster
|
|
112
|
-
cluster=$(grep -E '^existing_pg_cluster_name[[:space:]]*=' "$ROOT/infra/$cloud/terraform.tfvars" 2>/dev/null | sed -E 's/.*"([^"]+)".*/\1/')
|
|
128
|
+
local cluster=""
|
|
129
|
+
[ -n "$cloud" ] && cluster=$(grep -E '^existing_pg_cluster_name[[:space:]]*=' "$ROOT/infra/$cloud/terraform.tfvars" 2>/dev/null | sed -E 's/.*"([^"]+)".*/\1/')
|
|
113
130
|
|
|
114
131
|
# THE MONOREPO NEEDS THIS TOO, and it has no ground. The platform's own checkout is
|
|
115
132
|
# developed against a managed cluster named only in .env, so a ground-only lookup found
|
|
@@ -139,7 +156,9 @@ cmd_db_allow() {
|
|
|
139
156
|
fi
|
|
140
157
|
|
|
141
158
|
echo ""
|
|
142
|
-
|
|
159
|
+
# Hand the cluster over: we already resolved it, from a ground OR from .env, and the
|
|
160
|
+
# helper cannot re-derive the .env case (there is no tfvars to read).
|
|
161
|
+
_operator_db_access "$cloud" "$cluster"
|
|
143
162
|
echo ""
|
|
144
163
|
info "Run this again whenever you change network"
|
|
145
164
|
echo ""
|
|
@@ -210,11 +229,23 @@ _pick_ground() {
|
|
|
210
229
|
*) fail "Unknown ground '$want'. Use ${BOLD}digitalocean${NC} or ${BOLD}aws${NC}" >&2; return 1 ;;
|
|
211
230
|
esac
|
|
212
231
|
|
|
232
|
+
# A command may not apply to every cloud. `GROUNDS_ONLY` names the ones it does, so a
|
|
233
|
+
# ground that cannot answer is never offered as a choice and never named in the
|
|
234
|
+
# "say which" prompt. Unset means all of them, which is every other caller.
|
|
213
235
|
local configured=()
|
|
214
236
|
for g in digitalocean aws; do
|
|
215
|
-
[ -f "$ROOT/infra/$g/terraform.tfvars" ]
|
|
237
|
+
[ -f "$ROOT/infra/$g/terraform.tfvars" ] || continue
|
|
238
|
+
if [ -n "${GROUNDS_ONLY:-}" ] && [[ " ${GROUNDS_ONLY} " != *" $g "* ]]; then continue; fi
|
|
239
|
+
configured+=("$g")
|
|
216
240
|
done
|
|
217
241
|
|
|
242
|
+
# Asked for a ground this command cannot serve: say so plainly rather than "no such
|
|
243
|
+
# ground here", which sends someone off to create one that would not have helped.
|
|
244
|
+
if [ -n "$want" ] && [ -n "${GROUNDS_ONLY:-}" ] && [[ " ${GROUNDS_ONLY} " != *" $want "* ]]; then
|
|
245
|
+
fail "${SELF_CMD:-This command} does not apply to $want. ${GROUNDS_ONLY_WHY:-}" >&2
|
|
246
|
+
return 1
|
|
247
|
+
fi
|
|
248
|
+
|
|
218
249
|
if [ -n "$want" ]; then
|
|
219
250
|
for g in "${configured[@]}"; do
|
|
220
251
|
[ "$g" = "$want" ] && { printf '%s' "$want"; return 0; }
|
|
@@ -229,7 +260,9 @@ _pick_ground() {
|
|
|
229
260
|
*)
|
|
230
261
|
# Two grounds and no name. Refuse rather than pick: this decides which cloud a
|
|
231
262
|
# destroy lands on.
|
|
232
|
-
|
|
263
|
+
# Names the grounds THIS command can actually serve, not both clouds unconditionally:
|
|
264
|
+
# offering a choice that would be refused is worse than not offering it.
|
|
265
|
+
fail "Two grounds are configured. Say which: ${BOLD}${SELF_CMD:-unoverse deploy} ${configured[0]}${NC} or ${BOLD}${SELF_CMD:-unoverse deploy} ${configured[1]}${NC}" >&2
|
|
233
266
|
return 1
|
|
234
267
|
;;
|
|
235
268
|
esac
|
package/package.json
CHANGED