From 636e194ea601b6686a89368a0bf2b5683d8534b3 Mon Sep 17 00:00:00 2001 From: Moritz Graf Date: Fri, 2 Jan 2026 22:28:54 +0100 Subject: [PATCH] chore: improve local development experience with setup scripts --- .gitignore | 4 +++ README.md | 19 ++++++++++++ package.json | 3 +- scripts/setup-local-env.sh | 60 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100755 scripts/setup-local-env.sh diff --git a/.gitignore b/.gitignore index 5878922..af29224 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,10 @@ node_modules dist dist-ssr +# Local Environment +.env +.env.local + # Terraform .terraform/ *.tfstate diff --git a/README.md b/README.md index f7d78c6..0dde5d3 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/package.json b/package.json index eea572a..e968676 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "type": "module", "scripts": { "dev": "vite", + "setup:env": "./scripts/setup-local-env.sh", "build": "vite build", "preview": "vite preview" }, @@ -22,4 +23,4 @@ "vite-plugin-pwa": "^1.2.0", "vue-tsc": "^1.8.8" } -} +} \ No newline at end of file diff --git a/scripts/setup-local-env.sh b/scripts/setup-local-env.sh new file mode 100755 index 0000000..64c111f --- /dev/null +++ b/scripts/setup-local-env.sh @@ -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" <