diff --git a/deployment/cloud-run/service.yaml b/deployment/cloud-run/service.yaml index e561cc7..fa3dd32 100644 --- a/deployment/cloud-run/service.yaml +++ b/deployment/cloud-run/service.yaml @@ -6,7 +6,7 @@ spec: template: spec: containers: - - image: gcr.io/your-project/sereact:latest + - image: gcr.io/gen-lang-client-0424120530/sereact-api:latest ports: - containerPort: 8000 resources: diff --git a/deployment/cloudbuild.yaml b/deployment/cloudbuild.yaml index d957ac0..d6a7d5e 100644 --- a/deployment/cloudbuild.yaml +++ b/deployment/cloudbuild.yaml @@ -1,19 +1,19 @@ steps: # Build the container image - name: 'gcr.io/cloud-builders/docker' - args: ['build', '-t', 'gcr.io/$PROJECT_ID/sereact:$COMMIT_SHA', '.'] + args: ['build', '-t', 'gcr.io/$PROJECT_ID/sereact-api:$COMMIT_SHA', '.'] # Push the container image to Container Registry - name: 'gcr.io/cloud-builders/docker' - args: ['push', 'gcr.io/$PROJECT_ID/sereact:$COMMIT_SHA'] + args: ['push', 'gcr.io/$PROJECT_ID/sereact-api:$COMMIT_SHA'] # Tag the image as latest - name: 'gcr.io/cloud-builders/docker' - args: ['tag', 'gcr.io/$PROJECT_ID/sereact:$COMMIT_SHA', 'gcr.io/$PROJECT_ID/sereact:latest'] + args: ['tag', 'gcr.io/$PROJECT_ID/sereact-api:$COMMIT_SHA', 'gcr.io/$PROJECT_ID/sereact-api:latest'] # Push the latest tag - name: 'gcr.io/cloud-builders/docker' - args: ['push', 'gcr.io/$PROJECT_ID/sereact:latest'] + args: ['push', 'gcr.io/$PROJECT_ID/sereact-api:latest'] # Deploy to Cloud Run - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk' @@ -22,7 +22,7 @@ steps: - 'run' - 'deploy' - 'sereact' - - '--image=gcr.io/$PROJECT_ID/sereact:$COMMIT_SHA' + - '--image=gcr.io/$PROJECT_ID/sereact-api:$COMMIT_SHA' - '--region=us-central1' - '--platform=managed' - '--allow-unauthenticated' @@ -40,8 +40,8 @@ steps: # Store images in Container Registry images: - - 'gcr.io/$PROJECT_ID/sereact:$COMMIT_SHA' - - 'gcr.io/$PROJECT_ID/sereact:latest' + - 'gcr.io/$PROJECT_ID/sereact-api:$COMMIT_SHA' + - 'gcr.io/$PROJECT_ID/sereact-api:latest' # Substitution variables to be set in the Cloud Build trigger substitutions: diff --git a/deployment/deploy.sh b/deployment/deploy.sh index 5ded0cc..51b3a49 100644 --- a/deployment/deploy.sh +++ b/deployment/deploy.sh @@ -3,7 +3,7 @@ set -e # Configuration PROJECT_ID=$(gcloud config get-value project) -IMAGE_NAME="sereact" +IMAGE_NAME="sereact-api" REGION="us-central1" SERVICE_NAME="sereact" @@ -103,7 +103,7 @@ if [ "$BUILD" = true ]; then LATEST_IMAGE_NAME="gcr.io/$PROJECT_ID/$IMAGE_NAME:latest" echo "Building image: $FULL_IMAGE_NAME" - docker build -t "$FULL_IMAGE_NAME" -t "$LATEST_IMAGE_NAME" . + docker build -t "$FULL_IMAGE_NAME" -t "$LATEST_IMAGE_NAME" -f Dockerfile . echo "Pushing images to Container Registry..." docker push "$FULL_IMAGE_NAME" @@ -122,7 +122,17 @@ if [ "$DEPLOY" = true ]; then # Check if we have an existing service.yaml to use if [ -f "$(dirname "$0")/cloud-run/service.yaml" ]; then echo "Deploying using service.yaml configuration..." - gcloud run services replace "$(dirname "$0")/cloud-run/service.yaml" --region="$REGION" + # Update image in service.yaml before deploying + YAML_FILE="$(dirname "$0")/cloud-run/service.yaml" + # Create a temporary file for sed operation + TMP_FILE=$(mktemp) + # Replace the image line in the YAML file + sed "s|image: gcr.io/[^/]*/[^:]*:.*|image: $LATEST_IMAGE_NAME|" "$YAML_FILE" > "$TMP_FILE" + # Replace the original file + cat "$TMP_FILE" > "$YAML_FILE" + rm "$TMP_FILE" + # Deploy with the updated YAML + gcloud run services replace "$YAML_FILE" --region="$REGION" else echo "Deploying directly..." gcloud run deploy "$SERVICE_NAME" \ diff --git a/deployment/terraform/main.tf b/deployment/terraform/main.tf index 1ec8dc9..5748175 100644 --- a/deployment/terraform/main.tf +++ b/deployment/terraform/main.tf @@ -39,7 +39,7 @@ resource "google_firestore_database" "database" { } # Container Registry - no explicit resource needed, just enable the API -# You'll push images to gcr.io/${var.project_id}/sereact +# You'll push images to gcr.io/${var.project_id}/sereact-api # Cloud Run service resource "google_cloud_run_service" "sereact" { @@ -49,18 +49,17 @@ resource "google_cloud_run_service" "sereact" { template { spec { containers { - # Using a public placeholder image that exists to avoid deployment failure - # You'll need to update this later with your actual image - image = "gcr.io/google-samples/hello-app:1.0" + # Use our optimized image + image = "gcr.io/${var.project_id}/sereact-api:latest" ports { - container_port = 8080 + container_port = 8000 } resources { limits = { cpu = "1" - memory = "512Mi" + memory = "1Gi" } } diff --git a/scripts/build.sh b/scripts/build.sh index bbb4a89..58321dc 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -4,9 +4,10 @@ set -e # Set defaults IMAGE_NAME=${IMAGE_NAME:-"sereact-api"} IMAGE_TAG=${IMAGE_TAG:-"latest"} +PROJECT_ID=${PROJECT_ID:-"gen-lang-client-0424120530"} # Allow custom registry (defaults to DockerHub) -REGISTRY=${REGISTRY:-""} +REGISTRY=${REGISTRY:-"gcr.io/${PROJECT_ID}"} REGISTRY_PREFIX="" if [ -n "$REGISTRY" ]; then REGISTRY_PREFIX="${REGISTRY}/" diff --git a/scripts/deploy-to-cloud-run.sh b/scripts/deploy-to-cloud-run.sh deleted file mode 100644 index 75a9956..0000000 --- a/scripts/deploy-to-cloud-run.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash -set -e - -# Default values -PROJECT_ID=${PROJECT_ID:-""} -REGION=${REGION:-"us-central1"} -SERVICE_CONFIG=${SERVICE_CONFIG:-"deployment/cloud-run/service.yaml"} -IMAGE_NAME=${IMAGE_NAME:-"sereact-api"} -IMAGE_TAG=${IMAGE_TAG:-"latest"} -REGISTRY=${REGISTRY:-"gcr.io"} - -# Validate required parameters -if [ -z "$PROJECT_ID" ]; then - echo "Error: PROJECT_ID environment variable is required" - echo "Usage: PROJECT_ID=your-project-id ./scripts/deploy-to-cloud-run.sh" - exit 1 -fi - -# Full image reference -FULL_IMAGE_NAME="${REGISTRY}/${PROJECT_ID}/${IMAGE_NAME}:${IMAGE_TAG}" - -# Check if service config exists -if [ ! -f "$SERVICE_CONFIG" ]; then - echo "Error: Service configuration file not found at $SERVICE_CONFIG" - exit 1 -fi - -# Build the image if BUILD=true -if [ "${BUILD:-false}" = "true" ]; then - echo "Building Docker image: ${FULL_IMAGE_NAME}" - docker build -t "${FULL_IMAGE_NAME}" -f Dockerfile . - echo "Build completed successfully" -fi - -# Push the image if PUSH=true -if [ "${PUSH:-false}" = "true" ]; then - echo "Pushing image to registry: ${FULL_IMAGE_NAME}" - docker push "${FULL_IMAGE_NAME}" - echo "Image pushed successfully" -fi - -# Update the image in the service configuration -echo "Updating image reference in service configuration..." -TMP_CONFIG=$(mktemp) -sed "s|image: .*|image: ${FULL_IMAGE_NAME}|g" "$SERVICE_CONFIG" > "$TMP_CONFIG" - -echo "Deploying to Cloud Run using configuration..." -gcloud run services replace "$TMP_CONFIG" \ - --project="$PROJECT_ID" \ - --region="$REGION" \ - --platform=managed - -rm "$TMP_CONFIG" - -echo "Deployment completed successfully" -echo "Service URL: $(gcloud run services describe sereact --region=${REGION} --project=${PROJECT_ID} --format='value(status.url)')" -echo "To view logs: gcloud logging read 'resource.type=cloud_run_revision AND resource.labels.service_name=sereact' --project=$PROJECT_ID --limit=10" \ No newline at end of file diff --git a/scripts/deploy.sh b/scripts/deploy.sh deleted file mode 100644 index fffacc5..0000000 --- a/scripts/deploy.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -set -e - -# Source the build environment to reuse variables -source "$(dirname "$0")/build.sh" - -# Push the Docker image to the registry -echo "Pushing image: ${FULL_IMAGE_NAME} to registry..." -docker push "${FULL_IMAGE_NAME}" -echo "Image pushed successfully" - -# Check if we need to deploy to Cloud Run -DEPLOY_TO_CLOUD_RUN=${DEPLOY_TO_CLOUD_RUN:-false} - -if [ "$DEPLOY_TO_CLOUD_RUN" = true ]; then - echo "Deploying to Cloud Run..." - - # Cloud Run settings - PROJECT_ID=${PROJECT_ID:-""} - REGION=${REGION:-"us-central1"} - SERVICE_NAME=${SERVICE_NAME:-"sereact-api"} - - if [ -z "$PROJECT_ID" ]; then - echo "Error: PROJECT_ID environment variable is required for Cloud Run deployment" - exit 1 - fi - - # Deploy to Cloud Run - gcloud run deploy "${SERVICE_NAME}" \ - --image="${FULL_IMAGE_NAME}" \ - --platform=managed \ - --region="${REGION}" \ - --project="${PROJECT_ID}" \ - --allow-unauthenticated \ - --port=8000 - - echo "Deployment to Cloud Run completed" - echo "Service URL: $(gcloud run services describe ${SERVICE_NAME} --region=${REGION} --project=${PROJECT_ID} --format='value(status.url)')" -else - echo "" - echo "To deploy to Cloud Run:" - echo "DEPLOY_TO_CLOUD_RUN=true PROJECT_ID=your-project-id ./scripts/deploy.sh" -fi \ No newline at end of file diff --git a/scripts/push.sh b/scripts/push.sh new file mode 100644 index 0000000..512693f --- /dev/null +++ b/scripts/push.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +# Source the build environment to reuse variables +source "$(dirname "$0")/build.sh" + +# Push the Docker image to the registry +echo "Pushing image: ${FULL_IMAGE_NAME} to registry..." +docker push "${FULL_IMAGE_NAME}" +echo "Image pushed successfully" + +echo "" +echo "Image pushed to: ${FULL_IMAGE_NAME}" +echo "" +echo "To deploy to Cloud Run:" +echo "./scripts/deploy.sh" \ No newline at end of file