forgejo-config/deploy.sh

61 lines
1.9 KiB
Bash
Executable file

#!/bin/bash
set -e
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${YELLOW}Starting deployment of GCP Data Engineering VM with Forgejo...${NC}"
# Check if terraform is installed
if ! command -v terraform &> /dev/null; then
echo -e "${RED}Terraform is not installed. Please install it first.${NC}"
exit 1
fi
# Check if ansible is installed
if ! command -v ansible &> /dev/null; then
echo -e "${RED}Ansible is not installed. Please install it first.${NC}"
exit 1
fi
# Check if terraform.tfvars exists
if [ ! -f terraform/terraform.tfvars ]; then
echo -e "${YELLOW}terraform.tfvars not found. Creating from example file...${NC}"
cp terraform/terraform.tfvars.example terraform/terraform.tfvars
echo -e "${RED}Please edit terraform/terraform.tfvars with your GCP project details before continuing.${NC}"
exit 1
fi
# Initialize Terraform
echo -e "${GREEN}Initializing Terraform...${NC}"
cd terraform
terraform init
# Apply Terraform configuration
echo -e "${GREEN}Applying Terraform configuration...${NC}"
terraform apply -auto-approve
# Get the VM IP address
VM_IP=$(terraform output -raw instance_ip)
echo -e "${GREEN}VM created with IP: ${VM_IP}${NC}"
cd ..
# Update Ansible inventory with VM IP
echo -e "${GREEN}Updating Ansible inventory with VM IP...${NC}"
sed -i "s/ansible_host: \"{{ vm_ip_address }}\"/ansible_host: \"${VM_IP}\"/g" ansible/inventory.yml
# Wait for VM to be ready
echo -e "${YELLOW}Waiting for VM to be ready (60 seconds)...${NC}"
sleep 60
# Run Ansible playbook
echo -e "${GREEN}Running Ansible playbook to configure Forgejo...${NC}"
cd ansible
ansible-playbook -i inventory.yml forgejo.yml
echo -e "${GREEN}Deployment completed successfully!${NC}"
echo -e "${YELLOW}Forgejo should be accessible at https://your-duckdns-subdomain.duckdns.org${NC}"
echo -e "${YELLOW}Please allow a few minutes for DNS propagation and SSL certificate setup.${NC}"