mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:20:47 +00:00
275fd0dccc
## Description: This is a refactor to simplify config handling. Replaces the per-environment DevConfig/PreprodConfig/ProdConfig class hierarchy with two static classes: ClientEnv (browser main thread, reads from window.BOOTSTRAP_CONFIG) and ServerEnv (Node server, reads from process.env). The four config classes are deleted, the abstract DefaultServerConfig is gone, and DefaultConfig is renamed to Config. The values that flow server → client (gameEnv, numWorkers, turnstileSiteKey, jwtAudience, instanceId) used to be baked into the hardcoded per-env classes. They're now real env vars on the server, embedded into a single window.BOOTSTRAP_CONFIG object in index.html at request time (alongside the existing gitCommit/assetManifest/cdnBase globals, which moved into the same object), and read back by ClientEnv on the client. The dev defaults previously hidden inside DevServerConfig are now explicit in start:server-dev (NUM_WORKERS=2, TURNSTILE_SITE_KEY=1x..., JWT_AUDIENCE=localhost, etc.) and in vite.config.ts's html plugin inject.data. Production deploys plumb NUM_WORKERS and TURNSTILE_SITE_KEY through deploy.yml (GitHub vars) into the remote env file; JWT_AUDIENCE is derived from DOMAIN in deploy.sh. The dynamic /api/instance endpoint is gone — INSTANCE_ID rides along in BOOTSTRAP_CONFIG now. ServerEnv is the only thing server code touches; ClientEnv is browser-only. The two classes have intentional overlap (env, numWorkers, jwtIssuer, gameCreationRate, workerIndex, etc.) since they derive identical logic from different sources — there's a TODO in each to consolidate via a shared helper later. The game-logic Config no longer stores a ServerConfig/ClientEnv reference and its serverConfig() getter is gone; the one caller (MultiTabModal) now reads ClientEnv.env() directly. Worker init no longer carries server-config values since nothing in the worker actually reads them. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
163 lines
4.8 KiB
Bash
Executable File
163 lines
4.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# deploy.sh - Deploy application to Hetzner server
|
|
# This script:
|
|
# 1. Copies the update script to Hetzner server
|
|
# 2. Executes the update script on the Hetzner server
|
|
|
|
set -e # Exit immediately if a command exits with a non-zero status
|
|
|
|
# Function to print section headers
|
|
print_header() {
|
|
echo "======================================================"
|
|
echo "🚀 $1"
|
|
echo "======================================================"
|
|
}
|
|
|
|
# Check command line arguments
|
|
if [ $# -ne 4 ]; then
|
|
echo "Error: Please specify environment, host, version tag, and subdomain"
|
|
echo "Usage: $0 [prod|staging] [nbg1|staging|masters|falk2] [version_tag] [subdomain]"
|
|
exit 1
|
|
fi
|
|
|
|
# Validate first argument (environment)
|
|
if [ "$1" != "prod" ] && [ "$1" != "staging" ]; then
|
|
echo "Error: First argument must be either 'prod' or 'staging'"
|
|
echo "Usage: $0 [prod|staging] [nbg1|staging|masters|falk2] [version_tag] [subdomain]"
|
|
exit 1
|
|
fi
|
|
|
|
# Validate second argument (host)
|
|
if [ "$2" != "falk2" ] && [ "$2" != "nbg1" ] && [ "$2" != "staging" ] && [ "$2" != "masters" ]; then
|
|
echo "Error: Second argument must be either 'falk2', 'nbg1', 'staging', or 'masters'"
|
|
echo "Usage: $0 [prod|staging] [nbg1|staging|masters|falk2] [version_tag] [subdomain]"
|
|
exit 1
|
|
fi
|
|
|
|
ENV=$1
|
|
HOST=$2
|
|
VERSION_TAG=$3
|
|
SUBDOMAIN=$4
|
|
|
|
# Set subdomain - use the provided subdomain
|
|
echo "Using subdomain: $SUBDOMAIN"
|
|
|
|
# Load common environment variables first
|
|
if [ -f .env ]; then
|
|
echo "Loading common configuration from .env file..."
|
|
export $(grep -v '^#' .env | xargs)
|
|
fi
|
|
|
|
# Load environment-specific variables
|
|
if [ -f .env.$ENV ]; then
|
|
echo "Loading $ENV-specific configuration from .env.$ENV file..."
|
|
export $(grep -v '^#' .env.$ENV | xargs)
|
|
fi
|
|
|
|
# Check required environment variables for deployment
|
|
if [ -z "$GHCR_USERNAME" ] || [ -z "$GHCR_REPO" ]; then
|
|
echo "Error: GHCR_USERNAME or GHCR_REPO not defined in .env file or environment"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "$VERSION_TAG" == sha256:* ]]; then
|
|
GHCR_IMAGE="${GHCR_USERNAME}/${GHCR_REPO}@${VERSION_TAG}"
|
|
else
|
|
GHCR_IMAGE="${GHCR_USERNAME}/${GHCR_REPO}:${VERSION_TAG}"
|
|
fi
|
|
|
|
if [ -z "$DOMAIN" ]; then
|
|
echo "Error: DOMAIN not defined in .env file or environment"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$HOST" == "staging" ]; then
|
|
print_header "DEPLOYING TO STAGING HOST"
|
|
SERVER_HOST=$SERVER_HOST_STAGING
|
|
elif [ "$HOST" == "nbg1" ]; then
|
|
print_header "DEPLOYING TO NBG1 HOST"
|
|
SERVER_HOST=$SERVER_HOST_NBG1
|
|
elif [ "$HOST" == "masters" ]; then
|
|
print_header "DEPLOYING TO MASTERS HOST"
|
|
SERVER_HOST=$SERVER_HOST_MASTERS
|
|
elif [ "$HOST" == "falk2" ]; then
|
|
print_header "DEPLOYING TO FALK2 HOST"
|
|
SERVER_HOST=$SERVER_HOST_FALK2
|
|
fi
|
|
|
|
# Check required environment variables
|
|
if [ -z "$SERVER_HOST" ]; then
|
|
echo "Error: ${HOST} not defined in .env file or environment"
|
|
exit 1
|
|
fi
|
|
|
|
# Configuration
|
|
UPDATE_SCRIPT="./update.sh" # Path to your update script
|
|
REMOTE_USER="openfront"
|
|
REMOTE_UPDATE_PATH="/home/$REMOTE_USER"
|
|
REMOTE_UPDATE_SCRIPT="$REMOTE_UPDATE_PATH/update-openfront.sh" # Where to place the script on server
|
|
|
|
# Check if update script exists
|
|
if [ ! -f "$UPDATE_SCRIPT" ]; then
|
|
echo "Error: Update script $UPDATE_SCRIPT not found!"
|
|
exit 1
|
|
fi
|
|
|
|
# Display deployment information
|
|
print_header "DEPLOYMENT INFORMATION"
|
|
echo "Environment: ${ENV}"
|
|
echo "Host: ${HOST}"
|
|
echo "Subdomain: ${SUBDOMAIN}"
|
|
echo "Image: $GHCR_IMAGE"
|
|
echo "Target Server: $SERVER_HOST"
|
|
|
|
# Copy update script to Hetzner server
|
|
print_header "COPYING UPDATE SCRIPT TO SERVER"
|
|
echo "Target: $REMOTE_USER@$SERVER_HOST"
|
|
|
|
# Make sure the update script is executable
|
|
chmod +x $UPDATE_SCRIPT
|
|
|
|
# Copy the update script to the server
|
|
scp -i $SSH_KEY $UPDATE_SCRIPT $REMOTE_USER@$SERVER_HOST:$REMOTE_UPDATE_SCRIPT
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "❌ Failed to copy update script to server. Stopping deployment."
|
|
exit 1
|
|
fi
|
|
|
|
# Generate a random filename for the environment file to prevent conflicts
|
|
# when multiple deployments are happening at the same time.
|
|
ENV_FILE="${REMOTE_UPDATE_PATH}/${SUBDOMAIN}-${RANDOM}.env"
|
|
|
|
print_header "EXECUTING UPDATE SCRIPT ON SERVER"
|
|
|
|
ssh -i $SSH_KEY $REMOTE_USER@$SERVER_HOST "chmod +x $REMOTE_UPDATE_SCRIPT && \
|
|
cat > $ENV_FILE << 'EOL'
|
|
GAME_ENV=$ENV
|
|
ENV=$ENV
|
|
HOST=$HOST
|
|
GHCR_IMAGE=$GHCR_IMAGE
|
|
GHCR_TOKEN=$GHCR_TOKEN
|
|
API_KEY=$API_KEY
|
|
DOMAIN=$DOMAIN
|
|
SUBDOMAIN=$SUBDOMAIN
|
|
CDN_BASE=$CDN_BASE
|
|
NUM_WORKERS=$NUM_WORKERS
|
|
TURNSTILE_SITE_KEY=$TURNSTILE_SITE_KEY
|
|
OTEL_EXPORTER_OTLP_ENDPOINT=$OTEL_EXPORTER_OTLP_ENDPOINT
|
|
OTEL_AUTH_HEADER=$OTEL_AUTH_HEADER
|
|
EOL
|
|
chmod 600 $ENV_FILE && \
|
|
$REMOTE_UPDATE_SCRIPT $ENV_FILE"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "❌ Failed to execute update script on server."
|
|
exit 1
|
|
fi
|
|
|
|
print_header "DEPLOYMENT COMPLETED SUCCESSFULLY"
|
|
echo "✅ New version deployed to ${ENV} environment in ${HOST} with subdomain ${SUBDOMAIN}!"
|
|
echo "🌐 Check your server to verify the deployment."
|
|
echo "======================================================="
|