chore: improve local development experience with setup scripts
This commit is contained in:
parent
a0a39b55d9
commit
636e194ea6
|
|
@ -11,6 +11,10 @@ node_modules
|
||||||
dist
|
dist
|
||||||
dist-ssr
|
dist-ssr
|
||||||
|
|
||||||
|
# Local Environment
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
|
||||||
# Terraform
|
# Terraform
|
||||||
.terraform/
|
.terraform/
|
||||||
*.tfstate
|
*.tfstate
|
||||||
|
|
|
||||||
19
README.md
19
README.md
|
|
@ -34,6 +34,25 @@ We use Terraform to manage Firebase Authentication and Firestore. To set this up
|
||||||
gcloud auth login
|
gcloud auth login
|
||||||
gcloud auth application-default 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
|
### 2. Infrastructure Deployment
|
||||||
Navigate to the `terraform` directory and apply the configuration:
|
Navigate to the `terraform` directory and apply the configuration:
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
"setup:env": "./scripts/setup-local-env.sh",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
|
|
@ -22,4 +23,4 @@
|
||||||
"vite-plugin-pwa": "^1.2.0",
|
"vite-plugin-pwa": "^1.2.0",
|
||||||
"vue-tsc": "^1.8.8"
|
"vue-tsc": "^1.8.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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"
|
||||||
Loading…
Reference in New Issue