# Build and Deployment Scripts This directory contains scripts for building and deploying the Sereact API application. ## Prerequisites - Docker installed and running - For deployment: access to a container registry (e.g., DockerHub, Google Container Registry) - For Cloud Run deployment: Google Cloud SDK (`gcloud`) installed and configured ## Scripts ### Build Script (`build.sh`) Builds the Docker image for the Sereact API. **Usage:** ```bash # Basic usage (builds with default settings) ./scripts/build.sh # Customize the image name IMAGE_NAME=my-custom-name ./scripts/build.sh # Customize the image tag IMAGE_TAG=v1.0.0 ./scripts/build.sh # Use a custom registry REGISTRY=gcr.io/my-project ./scripts/build.sh ``` **Environment Variables:** - `IMAGE_NAME`: Name for the Docker image (default: "sereact-api") - `IMAGE_TAG`: Tag for the Docker image (default: "latest") - `REGISTRY`: Container registry to use (default: empty, using DockerHub) ### Deploy Script (`deploy.sh`) Pushes the built Docker image to a container registry and optionally deploys to Google Cloud Run. **Usage:** ```bash # Push to registry only ./scripts/deploy.sh # Push to registry and deploy to Cloud Run DEPLOY_TO_CLOUD_RUN=true PROJECT_ID=my-project-id ./scripts/deploy.sh # Customize deployment settings DEPLOY_TO_CLOUD_RUN=true PROJECT_ID=my-project-id REGION=us-west1 SERVICE_NAME=my-api ./scripts/deploy.sh ``` **Environment Variables:** All variables from the build script, plus: - `PROJECT_ID`: Google Cloud project ID (required for Cloud Run deployment) - `REGION`: Google Cloud region (default: "us-central1") - `SERVICE_NAME`: Name for the Cloud Run service (default: "sereact-api") ### Cloud Run Deployment Script (`deploy-to-cloud-run.sh`) Deploys the application to Google Cloud Run using the service configuration file. **Usage:** ```bash # Deploy using existing service.yaml PROJECT_ID=my-project-id ./scripts/deploy-to-cloud-run.sh # Build, push, and deploy in one command PROJECT_ID=my-project-id BUILD=true PUSH=true ./scripts/deploy-to-cloud-run.sh # Customize the deployment PROJECT_ID=my-project-id REGION=us-west1 IMAGE_TAG=v1.0.0 ./scripts/deploy-to-cloud-run.sh ``` **Environment Variables:** - `PROJECT_ID`: Google Cloud project ID (required) - `REGION`: Google Cloud region (default: "us-central1") - `SERVICE_CONFIG`: Path to the service configuration file (default: "deployment/cloud-run/service.yaml") - `IMAGE_NAME`: Name for the Docker image (default: "sereact-api") - `IMAGE_TAG`: Tag for the Docker image (default: "latest") - `REGISTRY`: Container registry to use (default: "gcr.io") - `BUILD`: Set to "true" to build the image before deployment (default: "false") - `PUSH`: Set to "true" to push the image before deployment (default: "false") ### Frontend Client Script (`client.sh`) Manages the SeReact frontend client development, building, and deployment. **Usage:** ```bash # Start development server ./scripts/client.sh dev # or ./scripts/client.sh serve # Build production files ./scripts/client.sh build # Deploy to static hosting DEPLOY_TARGET=netlify ./scripts/client.sh deploy # Clean build artifacts ./scripts/client.sh clean # Install dependencies ./scripts/client.sh install # Check code quality ./scripts/client.sh lint # Run tests ./scripts/client.sh test # Show help ./scripts/client.sh help ``` **Environment Variables:** - `PORT`: Development server port (default: 8080) - `HOST`: Development server host (default: localhost) - `DEPLOY_TARGET`: Deployment target - netlify, vercel, s3, github, or manual (default: manual) - `S3_BUCKET`: S3 bucket name (required for S3 deployment) **Features:** - **Development Server**: Starts a local HTTP server with CORS headers for frontend development - **Production Build**: Creates optimized production files in `dist/` directory - **Multiple Deployment Options**: Supports Netlify, Vercel, AWS S3, GitHub Pages, and manual deployment - **Code Quality**: Integrates with ESLint, Stylelint, and HTML Tidy (if installed) - **Dependency Management**: Handles Python virtual environment setup - **Clean Build**: Removes build artifacts and cache files **Deployment Targets:** - `netlify`: Deploy using Netlify CLI - `vercel`: Deploy using Vercel CLI - `s3`: Deploy to AWS S3 bucket (requires AWS CLI and S3_BUCKET env var) - `github`: Shows instructions for GitHub Pages deployment - `manual`: Shows manual deployment instructions ## Example Workflows ### Basic workflow: ```bash # Build and tag with version IMAGE_TAG=v1.0.0 ./scripts/build.sh # Deploy to Cloud Run DEPLOY_TO_CLOUD_RUN=true PROJECT_ID=my-project-id IMAGE_TAG=v1.0.0 ./scripts/deploy.sh ``` ### Using the Cloud Run config file: ```bash # Build and deploy in one step PROJECT_ID=my-project-id BUILD=true PUSH=true ./scripts/deploy-to-cloud-run.sh ``` ### Frontend Development Workflow: ```bash # Install dependencies ./scripts/client.sh install # Start development server ./scripts/client.sh dev # Build for production ./scripts/client.sh build # Deploy to Netlify DEPLOY_TARGET=netlify ./scripts/client.sh deploy ``` # Scripts Documentation This directory contains utility scripts for the SEREACT application. ## Database Seeding Scripts ### `seed_firestore.py` This script initializes and seeds a Google Cloud Firestore database with initial data for the SEREACT application. It creates teams, users, API keys, and sample image metadata. #### Requirements - Google Cloud project with Firestore enabled - Google Cloud credentials configured on your machine - Python 3.8+ - Required Python packages (listed in `requirements.txt`) #### Setup 1. Make sure you have the Google Cloud SDK installed and configured with access to your project: ```bash gcloud auth login gcloud config set project YOUR_PROJECT_ID ``` 2. If not using application default credentials, create a service account key file: ```bash gcloud iam service-accounts create sereact-app gcloud projects add-iam-policy-binding YOUR_PROJECT_ID --member="serviceAccount:sereact-app@YOUR_PROJECT_ID.iam.gserviceaccount.com" --role="roles/datastore.user" gcloud iam service-accounts keys create credentials.json --iam-account=sereact-app@YOUR_PROJECT_ID.iam.gserviceaccount.com ``` 3. Set environment variables: ```bash # Windows (CMD) set DATABASE_TYPE=firestore set GCS_CREDENTIALS_FILE=path/to/credentials.json # Windows (PowerShell) $env:DATABASE_TYPE="firestore" $env:GCS_CREDENTIALS_FILE="path/to/credentials.json" # Linux/macOS export DATABASE_TYPE=firestore export GCS_CREDENTIALS_FILE=path/to/credentials.json ``` #### Usage Run the seeding script from the project root directory: ```bash # Activate the Python virtual environment source venv/bin/activate # Linux/macOS venv\Scripts\activate # Windows # Run the script python scripts/seed_firestore.py ``` #### Generated Data The script will create the following data: 1. **Teams**: - Sereact Development - Marketing Team - Customer Support 2. **Users**: - Admin User (team: Sereact Development) - Developer User (team: Sereact Development) - Marketing User (team: Marketing Team) - Support User (team: Customer Support) 3. **API Keys**: - One API key per user (the keys will be output to the console, save them securely) 4. **Images**: - Sample image metadata (3 images, one for each team) #### Notes - The script logs the generated API keys to the console. Save these keys somewhere secure as they won't be displayed again. - If you need to re-run the script with existing data, use the `--force` flag to overwrite existing data. - This script only creates metadata entries for images - it does not upload actual files to Google Cloud Storage.