mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 14:41:28 -07:00
add game config configuration
This commit is contained in:
@@ -1,28 +1,22 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
. "$(git rev-parse --show-toplevel)/packages/tools/src/sh/env.sh"
|
||||
|
||||
# Extract name and version from package.json using jq
|
||||
NAME=$(jq -r '.name' package.json)
|
||||
VERSION=$(get-version)
|
||||
|
||||
# Everything an operator supplies — domain, resource ids, tuning knobs — comes from the
|
||||
# single gitignored .env at the repo root (in CI, from exported secrets, which win over the
|
||||
# file). See .env.example.
|
||||
recflare_load_env
|
||||
|
||||
# Resolve the base domain (and this worker's subdomain), then deploy onto the
|
||||
# custom domain via `--domain`. This keeps the real domain out of versioned files
|
||||
# — committed wrangler.jsonc has no routes, and the base domain is passed as the
|
||||
# DOMAIN var at runtime.
|
||||
#
|
||||
# The domain comes from the RECFLARE_DOMAIN env var. For local dev that's set in a
|
||||
# gitignored .env at the repo root; in CI it's an exported secret. An already-set
|
||||
# RECFLARE_DOMAIN wins and skips the file. Per-app subdomain overrides come from
|
||||
# RECFLARE_SUBDOMAINS (a JSON object, e.g. {"playersettings":"settings"}).
|
||||
if [ -z "${RECFLARE_DOMAIN:-}" ]; then
|
||||
ENV_FILE="$(git rev-parse --show-toplevel)/.env"
|
||||
if [ -f "$ENV_FILE" ]; then
|
||||
set -a
|
||||
. "$ENV_FILE"
|
||||
set +a
|
||||
fi
|
||||
fi
|
||||
|
||||
# DOMAIN var at runtime. Per-app subdomain overrides come from RECFLARE_SUBDOMAINS
|
||||
# (a JSON object, e.g. {"playersettings":"settings"}).
|
||||
if [ -z "${RECFLARE_DOMAIN:-}" ]; then
|
||||
echo "error: RECFLARE_DOMAIN is not set — export it or add it to .env (see .env.example)" >&2
|
||||
exit 1
|
||||
@@ -129,6 +123,12 @@ if [ "$CONFIG" = "wrangler.jsonc" ] && { [ -n "$NEEDS_D1" ] || [ -n "$NEEDS_KV"
|
||||
fi
|
||||
fi
|
||||
|
||||
# The operator's tuning knobs, injected the same way as the resource ids above: each lives
|
||||
# in the .env as RECFLARE_<VAR> and rides along as a `--var`. See recflare_vars in
|
||||
# packages/tools/src/sh/env.sh. run-wrangler-dev passes the same flags, so one .env tunes
|
||||
# both a deploy and a local dev server.
|
||||
EXTRA_VARS=$(recflare_vars)
|
||||
|
||||
# Vite-built configs set no_bundle (vite already bundled and minified), which is
|
||||
# incompatible with --minify. Only pass --minify when wrangler does the bundling.
|
||||
MINIFY="--minify"
|
||||
@@ -136,11 +136,14 @@ MINIFY="--minify"
|
||||
|
||||
# Deploy with wrangler using the extracted values as binding variables
|
||||
echo "Deploying worker $NAME version $VERSION to $HOST"
|
||||
# $EXTRA_VARS is intentionally unquoted — it's a flag list to word-split, and every
|
||||
# value in it is an integer, so there's nothing to split on inside a value.
|
||||
wrangler deploy \
|
||||
--config "$CONFIG" \
|
||||
--var NAME:"$NAME" \
|
||||
--var SENTRY_RELEASE:"$VERSION" \
|
||||
--var DOMAIN:"$DOMAIN" \
|
||||
$EXTRA_VARS \
|
||||
--domain "$HOST" \
|
||||
$MINIFY \
|
||||
"$@"
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
. "$(git rev-parse --show-toplevel)/packages/tools/src/sh/env.sh"
|
||||
|
||||
NAME=$(jq -r '.name' package.json)
|
||||
|
||||
# Tuning knobs come from the same gitignored root .env a deploy reads (RECFLARE_<VAR>, see
|
||||
# .env.example), so a knob is configured in exactly one place whether you're running locally
|
||||
# or shipping. Unset knobs fall back to the worker's own default constants, same as a deploy.
|
||||
#
|
||||
# Passed as `--var` rather than left to wrangler's own .env loading: wrangler only reads a
|
||||
# .env sitting next to the worker's wrangler.jsonc, which would mean a second file per app.
|
||||
recflare_load_env
|
||||
EXTRA_VARS=$(recflare_vars)
|
||||
|
||||
# Give each worker a stable, unique dev port so `turbo dev` can run them all in
|
||||
# parallel without colliding on wrangler's default 8787 (and its 9229 inspector
|
||||
# port). The offset is the worker's alphabetical position among its siblings, so
|
||||
@@ -16,8 +27,10 @@ OFFSET=$(
|
||||
PORT=$((8787 + OFFSET - 1))
|
||||
INSPECTOR_PORT=$((9229 + OFFSET - 1))
|
||||
|
||||
# $EXTRA_VARS is intentionally unquoted — it's a flag list to word-split on.
|
||||
exec wrangler dev \
|
||||
--var NAME:"$NAME" \
|
||||
$EXTRA_VARS \
|
||||
--port "$PORT" \
|
||||
--inspector-port "$INSPECTOR_PORT" \
|
||||
"$@"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
. "$(git rev-parse --show-toplevel)/packages/tools/src/sh/env.sh"
|
||||
|
||||
# Apply this worker's D1 migrations. Run from a worker directory (e.g. via
|
||||
# `bun turbo -F rooms migrate`). Defaults to --remote; pass --local to target the
|
||||
# dev SQLite db. Extra args pass through to `wrangler d1 migrations apply`.
|
||||
@@ -41,16 +43,8 @@ if [ "$LOCAL" -eq 1 ]; then
|
||||
exec wrangler d1 migrations apply "$DB_NAME" "$@"
|
||||
fi
|
||||
|
||||
# Load RECFLARE_D1 from the gitignored root .env if not already set (mirrors
|
||||
# run-wrangler-deploy's handling of RECFLARE_DOMAIN). An already-set value wins.
|
||||
if [ -z "${RECFLARE_D1:-}" ]; then
|
||||
ENV_FILE="$(git rev-parse --show-toplevel)/.env"
|
||||
if [ -f "$ENV_FILE" ]; then
|
||||
set -a
|
||||
. "$ENV_FILE"
|
||||
set +a
|
||||
fi
|
||||
fi
|
||||
# RECFLARE_D1 comes from the gitignored root .env, or from CI secrets, which win over it.
|
||||
recflare_load_env
|
||||
|
||||
DB_ID=${RECFLARE_D1:-}
|
||||
if [ -z "$DB_ID" ]; then
|
||||
|
||||
Reference in New Issue
Block a user