2025-05-24 06:21:38 +02:00
..
cp
2025-05-24 06:21:38 +02:00
cp
2025-05-24 06:21:38 +02:00
cp
2025-05-23 23:06:32 +02:00
cp
2025-05-23 23:06:32 +02:00
cp
2025-05-23 22:42:22 +02:00
cp
2025-05-24 06:21:38 +02:00
2025-05-24 05:35:18 +02:00

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:

# 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:

# 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:

# 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")

Example Workflows

Basic workflow:

# 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:

# Build and deploy in one step
PROJECT_ID=my-project-id BUILD=true PUSH=true ./scripts/deploy-to-cloud-run.sh

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:

    gcloud auth login
    gcloud config set project YOUR_PROJECT_ID
    
  2. If not using application default credentials, create a service account key file:

    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:

    # 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:

# 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.