cp
This commit is contained in:
parent
fe997f48d9
commit
68da24b20b
@ -20,14 +20,16 @@ fi
|
||||
function show_help {
|
||||
echo "Usage: $0 [options]"
|
||||
echo "Options:"
|
||||
echo " --provision Run Terraform to provision cloud resources"
|
||||
echo " --build Build and push Docker image"
|
||||
echo " --deploy Deploy to Cloud Run via Terraform"
|
||||
echo " --build Build and push Docker image before deploying (use with --deploy)"
|
||||
echo " --destroy Destroy cloud resources with Terraform"
|
||||
echo " --list List all Cloud Run services in the project"
|
||||
echo " --all Do all of the above (except destroy)"
|
||||
echo " --help Show this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 --deploy # Deploy with existing Docker image"
|
||||
echo " $0 --deploy --build # Build Docker image then deploy"
|
||||
echo ""
|
||||
echo "Additional scripts:"
|
||||
echo " ./deployment/cleanup-images.sh Clean up container images (not managed by Terraform)"
|
||||
exit 0
|
||||
@ -39,7 +41,6 @@ if [ $# -eq 0 ]; then
|
||||
fi
|
||||
|
||||
# Process arguments
|
||||
PROVISION=false
|
||||
BUILD=false
|
||||
DEPLOY=false
|
||||
DESTROY=false
|
||||
@ -47,10 +48,6 @@ LIST=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--provision)
|
||||
PROVISION=true
|
||||
shift
|
||||
;;
|
||||
--build)
|
||||
BUILD=true
|
||||
shift
|
||||
@ -67,12 +64,6 @@ while [[ $# -gt 0 ]]; do
|
||||
LIST=true
|
||||
shift
|
||||
;;
|
||||
--all)
|
||||
PROVISION=true
|
||||
BUILD=true
|
||||
DEPLOY=true
|
||||
shift
|
||||
;;
|
||||
--help)
|
||||
show_help
|
||||
;;
|
||||
@ -259,29 +250,11 @@ if [ "$DESTROY" = true ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Provision resources with Terraform
|
||||
if [ "$PROVISION" = true ]; then
|
||||
echo "Provisioning cloud resources with Terraform..."
|
||||
cd "$(dirname "$0")/terraform"
|
||||
# Deploy workflow
|
||||
if [ "$DEPLOY" = true ]; then
|
||||
echo "Starting deployment workflow..."
|
||||
|
||||
# Check if terraform.tfvars exists, if not copy from example
|
||||
if [ ! -f terraform.tfvars ]; then
|
||||
echo "Creating terraform.tfvars from example..."
|
||||
cp terraform.tfvars.example terraform.tfvars
|
||||
# Replace project ID in tfvars file
|
||||
sed -i "s/your-gcp-project-id/$PROJECT_ID/g" terraform.tfvars
|
||||
echo "Please review and edit terraform.tfvars with your desired values"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
terraform init
|
||||
terraform apply
|
||||
|
||||
cd - > /dev/null
|
||||
echo "Provisioning completed."
|
||||
fi
|
||||
|
||||
# Build and push Docker image
|
||||
# Step 1: Build and push Docker image if --build flag is provided
|
||||
if [ "$BUILD" = true ]; then
|
||||
echo "Building and pushing Docker image..."
|
||||
|
||||
@ -304,29 +277,33 @@ if [ "$BUILD" = true ]; then
|
||||
echo "Image built and pushed successfully."
|
||||
fi
|
||||
|
||||
# Deploy to Cloud Run
|
||||
if [ "$DEPLOY" = true ]; then
|
||||
# Step 2: Deploy to Cloud Run via Terraform
|
||||
echo "Deploying to Cloud Run via Terraform..."
|
||||
|
||||
# Ensure the latest image exists
|
||||
cd "$(dirname "$0")/terraform"
|
||||
|
||||
# Check if terraform.tfvars exists, if not copy from example
|
||||
if [ ! -f terraform.tfvars ]; then
|
||||
echo "Creating terraform.tfvars from example..."
|
||||
cp terraform.tfvars.example terraform.tfvars
|
||||
# Replace project ID in tfvars file
|
||||
sed -i "s/your-gcp-project-id/$PROJECT_ID/g" terraform.tfvars
|
||||
echo "Please review and edit terraform.tfvars with your desired values"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# If we're building, ensure the latest image exists before deploying
|
||||
if [ "$BUILD" = true ]; then
|
||||
LATEST_IMAGE_NAME="gcr.io/$PROJECT_ID/$IMAGE_NAME:latest"
|
||||
|
||||
# Check if image exists
|
||||
if ! docker manifest inspect "$LATEST_IMAGE_NAME" > /dev/null 2>&1; then
|
||||
echo "ERROR: Image $LATEST_IMAGE_NAME not found. Please run --build first."
|
||||
echo "ERROR: Image $LATEST_IMAGE_NAME not found after build. Something went wrong."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Deploy using Terraform
|
||||
cd "$(dirname "$0")/terraform"
|
||||
|
||||
# Check if terraform.tfvars exists
|
||||
if [ ! -f terraform.tfvars ]; then
|
||||
echo "ERROR: terraform.tfvars not found. Please run --provision first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Applying Terraform configuration to deploy Cloud Run service..."
|
||||
echo "Applying Terraform configuration..."
|
||||
terraform init
|
||||
terraform apply -auto-approve
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user