refactor: restructure

monorepo with apps/ and services/
  directories
This commit is contained in:
Wuesteon 2025-11-26 03:03:24 +01:00
parent 25824ed0ac
commit ff80aeec1f
4062 changed files with 2592 additions and 1278 deletions

View file

@ -0,0 +1,156 @@
#!/bin/bash
# Script to create secrets in Google Secret Manager
# Run this after setup-gcp.sh
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_prompt() {
echo -e "${BLUE}[INPUT]${NC} $1"
}
# Check if gcloud is installed
if ! command -v gcloud &> /dev/null; then
print_error "gcloud CLI is not installed. Please install it first."
exit 1
fi
# Get current project
PROJECT_ID=$(gcloud config get-value project)
if [ -z "$PROJECT_ID" ]; then
print_error "No GCP project set. Please run 'gcloud config set project YOUR_PROJECT_ID'"
exit 1
fi
print_info "Creating secrets for project: $PROJECT_ID"
echo ""
# Function to create or update a secret
create_secret() {
local SECRET_NAME=$1
local SECRET_VALUE=$2
# Check if secret exists
if gcloud secrets describe $SECRET_NAME &>/dev/null; then
print_warning "Secret $SECRET_NAME already exists. Updating..."
echo -n "$SECRET_VALUE" | gcloud secrets versions add $SECRET_NAME --data-file=-
else
print_info "Creating secret $SECRET_NAME..."
echo -n "$SECRET_VALUE" | gcloud secrets create $SECRET_NAME --data-file=-
fi
}
# Function to read secret value with optional default
read_secret_value() {
local PROMPT=$1
local DEFAULT=$2
local SECRET_VALUE
if [ -n "$DEFAULT" ]; then
echo -e "${BLUE}[INPUT]${NC} $PROMPT (default: $DEFAULT): " >&2
read -r SECRET_VALUE
SECRET_VALUE=${SECRET_VALUE:-$DEFAULT}
else
echo -e "${BLUE}[INPUT]${NC} $PROMPT: " >&2
read -r SECRET_VALUE
fi
echo "$SECRET_VALUE"
}
# Function to read secret value (hidden input)
read_secret_value_hidden() {
local PROMPT=$1
local SECRET_VALUE
echo -e "${BLUE}[INPUT]${NC} $PROMPT (input will be hidden): " >&2
read -rs SECRET_VALUE
echo "" >&2
echo "$SECRET_VALUE"
}
# Shared secrets
print_info "Configuring shared secrets..."
echo ""
MAERCHENZAUBER_GOOGLE_GENAI_API_KEY=$(read_secret_value_hidden "Enter Google GenAI API Key")
create_secret "MAERCHENZAUBER_GOOGLE_GENAI_API_KEY" "$MAERCHENZAUBER_GOOGLE_GENAI_API_KEY"
MAERCHENZAUBER_REPLICATE_API_KEY=$(read_secret_value_hidden "Enter Replicate API Token (optional)")
if [ -n "$MAERCHENZAUBER_REPLICATE_API_KEY" ]; then
create_secret "MAERCHENZAUBER_REPLICATE_API_KEY" "$MAERCHENZAUBER_REPLICATE_API_KEY"
fi
MAERCHENZAUBER_AZURE_OPENAI_KEY=$(read_secret_value_hidden "Enter Azure OpenAI Key")
create_secret "MAERCHENZAUBER_AZURE_OPENAI_KEY" "$MAERCHENZAUBER_AZURE_OPENAI_KEY"
MAERCHENZAUBER_AZURE_OPENAI_ENDPOINT=$(read_secret_value "Enter Azure OpenAI Endpoint" "https://storyteller-openai-swedencentral.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview")
create_secret "MAERCHENZAUBER_AZURE_OPENAI_ENDPOINT" "$MAERCHENZAUBER_AZURE_OPENAI_ENDPOINT"
SENTRY_DSN=$(read_secret_value "Enter Sentry DSN for backend (optional)")
if [ -n "$SENTRY_DSN" ]; then
create_secret "MAERCHENZAUBER_SENTRY_DSN_BACKEND" "$SENTRY_DSN"
fi
# Production secrets
echo ""
print_info "Configuring PRODUCTION secrets..."
DEFAULT_MANA_URL="https://mana-core-middleware-111768794939.europe-west3.run.app"
DEFAULT_APP_ID="8d2f5ddb-e251-4b3b-8802-84022a7ac77f"
echo ""
# Mana Service Configuration
MANA_SERVICE_URL=$(read_secret_value "Enter Mana Service URL" "$DEFAULT_MANA_URL")
create_secret "MANA_SERVICE_URL" "$MANA_SERVICE_URL"
APP_ID=$(read_secret_value "Enter App ID" "$DEFAULT_APP_ID")
create_secret "APP_ID" "$APP_ID"
# Supabase Configuration
echo ""
print_info "Supabase configuration:"
SUPABASE_URL=$(read_secret_value "Enter Supabase URL")
create_secret "MAERCHENZAUBER_SUPABASE_URL" "$SUPABASE_URL"
SUPABASE_ANON_KEY=$(read_secret_value_hidden "Enter Supabase Anon Key")
create_secret "MAERCHENZAUBER_SUPABASE_ANON_KEY" "$SUPABASE_ANON_KEY"
JWT_SECRET=$(read_secret_value_hidden "Enter JWT Secret")
create_secret "MAERCHENZAUBER_JWT_SECRET" "$JWT_SECRET"
# Frontend URL for CORS
echo ""
print_info "Configuring frontend URL for CORS..."
FRONTEND_URL=$(read_secret_value "Enter frontend URL" "https://your-app.com")
echo "FRONTEND_URL=$FRONTEND_URL" >> github-secrets.txt
echo ""
print_info "All secrets created successfully!"
echo ""
print_info "Additional GitHub secrets saved to github-secrets.txt"
print_info "Add these to your GitHub repository secrets along with the values from setup-gcp.sh"
echo ""
print_info "To verify secrets, run:"
echo "gcloud secrets list"

View file

@ -0,0 +1,53 @@
#!/bin/bash
echo "🚀 Starting Storyteller Development Environment for iOS"
echo "================================================"
# Check if running from project root
if [ ! -f "package.json" ]; then
echo "❌ Please run this script from the project root directory"
exit 1
fi
# Kill any existing processes on ports
echo "🧹 Cleaning up existing processes..."
lsof -ti:3002 | xargs kill -9 2>/dev/null
lsof -ti:8081 | xargs kill -9 2>/dev/null
# Start backend in background
echo "🔧 Starting backend server on port 3002..."
cd apps/backend
npm run dev &
BACKEND_PID=$!
cd ../..
# Wait for backend to start
echo "⏳ Waiting for backend to be ready..."
sleep 5
# Check if backend is running
if ! curl -s http://localhost:3002/health > /dev/null; then
echo "⚠️ Backend might not be ready yet, but continuing..."
fi
# Start mobile app for iOS
echo "📱 Starting iOS app with Expo..."
cd apps/mobile
# Clear Metro bundler cache
echo "🗑️ Clearing Metro bundler cache..."
npx expo start -c --ios &
MOBILE_PID=$!
echo ""
echo "✅ Development environment started!"
echo "=================================="
echo "📱 iOS app: Expo Dev Tools will open"
echo "🔧 Backend: http://localhost:3002"
echo "📚 API Docs: http://localhost:3002/api-docs"
echo ""
echo "Press Ctrl+C to stop all services"
# Wait for user interrupt
trap "echo '🛑 Stopping services...'; kill $BACKEND_PID $MOBILE_PID 2>/dev/null; exit" INT
wait

View file

@ -0,0 +1,185 @@
#!/bin/bash
# Google Cloud Setup Script for Storyteller Backend
# This script sets up the necessary GCP resources for deploying the backend to Cloud Run
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
PROJECT_ID=${1:-""}
REGION=${REGION:-"europe-west3"}
SERVICE_ACCOUNT_NAME="storyteller-backend"
GITHUB_SA_NAME="github-actions"
ARTIFACT_REPO_NAME="storyteller"
# Function to print colored output
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if gcloud is installed
if ! command -v gcloud &> /dev/null; then
print_error "gcloud CLI is not installed. Please install it first."
exit 1
fi
# Check if project ID is provided
if [ -z "$PROJECT_ID" ]; then
print_error "Please provide a GCP project ID as the first argument"
echo "Usage: ./setup-gcp.sh YOUR_PROJECT_ID"
exit 1
fi
print_info "Setting up GCP resources for project: $PROJECT_ID"
# Set the project
gcloud config set project $PROJECT_ID
# Enable required APIs
print_info "Enabling required APIs..."
gcloud services enable \
run.googleapis.com \
artifactregistry.googleapis.com \
cloudbuild.googleapis.com \
secretmanager.googleapis.com \
containerregistry.googleapis.com \
cloudresourcemanager.googleapis.com \
iam.googleapis.com \
iamcredentials.googleapis.com \
sts.googleapis.com \
aiplatform.googleapis.com
print_info "APIs enabled successfully"
# Create Artifact Registry repository
print_info "Creating Artifact Registry repository..."
if gcloud artifacts repositories describe $ARTIFACT_REPO_NAME --location=$REGION &>/dev/null; then
print_warning "Artifact Registry repository already exists"
else
gcloud artifacts repositories create $ARTIFACT_REPO_NAME \
--repository-format=docker \
--location=$REGION \
--description="Docker images for Storyteller backend"
print_info "Artifact Registry repository created"
fi
# Create service account for Cloud Run
print_info "Creating service account for Cloud Run..."
if gcloud iam service-accounts describe ${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com &>/dev/null; then
print_warning "Service account ${SERVICE_ACCOUNT_NAME} already exists"
else
gcloud iam service-accounts create $SERVICE_ACCOUNT_NAME \
--display-name="Storyteller Backend Service Account"
print_info "Service account created"
fi
# Grant necessary roles to the service account
print_info "Granting roles to service account..."
ROLES=(
"roles/secretmanager.secretAccessor"
"roles/aiplatform.user"
"roles/logging.logWriter"
"roles/monitoring.metricWriter"
"roles/cloudtrace.agent"
)
for ROLE in "${ROLES[@]}"; do
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" \
--role="$ROLE" \
--quiet
done
print_info "Roles granted successfully"
# Create service account for GitHub Actions
print_info "Creating service account for GitHub Actions..."
if gcloud iam service-accounts describe ${GITHUB_SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com &>/dev/null; then
print_warning "Service account ${GITHUB_SA_NAME} already exists"
else
gcloud iam service-accounts create $GITHUB_SA_NAME \
--display-name="GitHub Actions Service Account"
print_info "GitHub Actions service account created"
fi
# Grant necessary roles to GitHub Actions service account
print_info "Granting roles to GitHub Actions service account..."
GITHUB_ROLES=(
"roles/run.developer"
"roles/artifactregistry.writer"
"roles/iam.serviceAccountUser"
)
for ROLE in "${GITHUB_ROLES[@]}"; do
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:${GITHUB_SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" \
--role="$ROLE" \
--quiet
done
# Allow GitHub Actions to act as the Cloud Run service account
gcloud iam service-accounts add-iam-policy-binding \
${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com \
--member="serviceAccount:${GITHUB_SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" \
--role="roles/iam.serviceAccountUser" \
--quiet
print_info "GitHub Actions roles granted successfully"
# Create service account key for GitHub Actions
print_info "Creating service account key for GitHub Actions..."
KEY_FILE="github-actions-key.json"
# Check if key file already exists
if [ -f "$KEY_FILE" ]; then
print_warning "Service account key file already exists. Skipping key creation."
print_warning "If you need a new key, please delete $KEY_FILE first."
else
gcloud iam service-accounts keys create $KEY_FILE \
--iam-account=${GITHUB_SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com
print_info "Service account key created: $KEY_FILE"
fi
print_warning "IMPORTANT: Keep this service account key secure!"
print_warning "Add the contents of $KEY_FILE to GitHub Secrets as GCP_SA_KEY_PROD"
print_warning "Do not commit this file to version control!"
# Add the key file to .gitignore if it's not already there
if ! grep -q "$KEY_FILE" .gitignore 2>/dev/null; then
echo "$KEY_FILE" >> .gitignore
print_info "Added $KEY_FILE to .gitignore"
fi
# Note: Images are stored in Supabase Storage, not GCS
print_info "Note: This project uses Supabase Storage for images, not Google Cloud Storage"
# Output configuration for GitHub Secrets
print_info "Setup complete! Add these secrets to your GitHub repository:"
echo ""
echo "GitHub Secrets to add:"
echo "----------------------"
echo "GCP_PROJECT_ID=${PROJECT_ID}"
echo "GCP_SA_KEY_PROD=<contents of ${KEY_FILE}>"
echo "CLOUD_RUN_SERVICE_ACCOUNT=${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com"
echo ""
echo "Next steps:"
echo "1. Copy the contents of ${KEY_FILE} and add it as GCP_SA_KEY_PROD secret in GitHub"
echo "2. Run ./scripts/create-secrets.sh to create secrets in Secret Manager"
echo "3. Add the above values to your GitHub repository secrets"
echo "4. Update your frontend environment variables with the Cloud Run URL after first deployment"
echo ""
print_warning "Remember: Never commit ${KEY_FILE} to version control!"