chore: improve local development experience with setup scripts

This commit is contained in:
Moritz Graf 2026-01-02 22:28:54 +01:00
parent a0a39b55d9
commit 636e194ea6
4 changed files with 85 additions and 1 deletions

4
.gitignore vendored
View File

@ -11,6 +11,10 @@ node_modules
dist
dist-ssr
# Local Environment
.env
.env.local
# Terraform
.terraform/
*.tfstate

View File

@ -34,6 +34,25 @@ We use Terraform to manage Firebase Authentication and Firestore. To set this up
gcloud auth login
gcloud auth application-default login
```
4. **Verify**: Log in to the application. You should see the member banner.
## 🛠 Local Development Requirements
This project uses **Firebase** for authentication. To run the app locally, you need the environment variables (API keys) that are normally injected during deployment.
### 1. Generate Local Environment Config
We typically manage infrastructure via Terraform. Use the included helper script to fetch the configuration from your active Terraform state and create a local `.env` file:
```bash
npm run setup:env
```
*Prerequisites: You must have `terraform` and `jq` installed, and `terraform apply` must have been run at least once.*
### 2. Start Dev Server
```bash
npm run dev
```
### 2. Infrastructure Deployment
Navigate to the `terraform` directory and apply the configuration:

View File

@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"setup:env": "./scripts/setup-local-env.sh",
"build": "vite build",
"preview": "vite preview"
},

60
scripts/setup-local-env.sh Executable file
View File

@ -0,0 +1,60 @@
#!/bin/bash
# setup-local-env.sh
# Fetches Firebase configuration from Terraform outputs and creates a local .env file.
# Check if terraform is installed
if ! command -v terraform &> /dev/null; then
echo "❌ Error: terraform is not installed or not in PATH."
exit 1
fi
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "❌ Error: jq is not installed. Please install jq to parse JSON output."
exit 1
fi
TERRAFORM_DIR="terraform"
ENV_FILE=".env"
echo "🔍 Fetching Firebase configuration from Terraform..."
if [ ! -d "$TERRAFORM_DIR" ]; then
echo "❌ Error: Terraform directory '$TERRAFORM_DIR' not found."
exit 1
fi
cd "$TERRAFORM_DIR" || exit
# Check if Terraform is initialized
if [ ! -d ".terraform" ]; then
echo "⚠️ Terraform not initialized. Initializing..."
terraform init
fi
# Fetch output in JSON format
TF_OUT=$(terraform output -json firebase_config 2>/dev/null)
cd ..
if [ -z "$TF_OUT" ]; then
echo "❌ Error: Could not fetch 'firebase_config' from Terraform output."
echo " Ensure 'terraform apply' has been run successfully."
exit 1
fi
echo "📝 Writing to $ENV_FILE..."
# Parse JSON and write to .env
# We use a heredoc to write the file content
cat > "$ENV_FILE" <<EOF
VITE_FIREBASE_API_KEY=$(echo $TF_OUT | jq -r .apiKey)
VITE_FIREBASE_AUTH_DOMAIN=$(echo $TF_OUT | jq -r .authDomain)
VITE_FIREBASE_PROJECT_ID=$(echo $TF_OUT | jq -r .projectId)
VITE_FIREBASE_STORAGE_BUCKET=$(echo $TF_OUT | jq -r .storageBucket)
VITE_FIREBASE_MESSAGING_SENDER_ID=$(echo $TF_OUT | jq -r .messagingSenderId)
VITE_FIREBASE_APP_ID=$(echo $TF_OUT | jq -r .appId)
EOF
echo "✅ Success! .env file created."
cat "$ENV_FILE"