generateDeployScript method

Future<void> generateDeployScript()

Generate deployment script

Implementation

Future<void> generateDeployScript() async {
  if (!config.createServer) return;
  if (config.firebaseProjectId == null) {
    warn('Firebase project ID not set, skipping deploy script');
    return;
  }

  info('Generating deploy script...');

  final String content =
      '''
#!/bin/bash
# Deployment script for ${config.serverPackageName}

set -e

PROJECT_ID="${config.firebaseProjectId}"
REGION="us-central1"
SERVICE_NAME="${config.serverPackageName.replaceAll('_', '-')}"
IMAGE_NAME="gcr.io/\$PROJECT_ID/\$SERVICE_NAME"

echo "Building Docker image..."
docker build --platform linux/amd64 -t \$IMAGE_NAME .

echo "Pushing to Container Registry..."
docker push \$IMAGE_NAME

echo "Deploying to Cloud Run..."
gcloud run deploy \$SERVICE_NAME \\
  --image \$IMAGE_NAME \\
  --platform managed \\
  --region \$REGION \\
  --project \$PROJECT_ID \\
  --allow-unauthenticated \\
  --port 8080 \\
  --memory 512Mi \\
  --cpu 1 \\
  --min-instances 0 \\
  --max-instances 10

echo "Deployment complete!"
echo "Service URL: https://\$SERVICE_NAME-\$PROJECT_ID.\$REGION.run.app"
''';

  final File file3 = File(p.join(serverPath, 'script_deploy.sh'));
  await file3.writeAsString(content);

  // Make executable
  await _runner.run('chmod', <String>['+x', file3.path]);

  success('Generated: ${config.serverPackageName}/script_deploy.sh');
}