#!/bin/bash set -e # Resume Site Deployment Script # This script helps deploy the resume site to Kubernetes via Flux CD echo "=== Resume Site Deployment ===" echo "" # Configuration GITEA_URL="${GITEA_URL:-http://192.168.1.49:13001}" GITEA_USER="${GITEA_USER:-}" GITEA_TOKEN="${GITEA_TOKEN:-}" HARBOR_URL="images.caffeinetux.com" HARBOR_USER="${HARBOR_USER:-}" HARBOR_PASSWORD="${HARBOR_PASSWORD:-}" REPO_NAME="resume-site" # Function to check prerequisites check_prereqs() { echo "Checking prerequisites..." if ! command -v kubectl &> /dev/null; then echo "Error: kubectl not found" exit 1 fi if ! command -v git &> /dev/null; then echo "Error: git not found" exit 1 fi echo "✓ Prerequisites met" } # Function to create Gitea repository create_gitea_repo() { if [ -z "$GITEA_USER" ] || [ -z "$GITEA_TOKEN" ]; then echo "Please set GITEA_USER and GITEA_TOKEN environment variables" echo "Or create the repository manually at: $GITEA_URL" return 1 fi echo "Creating Gitea repository..." curl -X POST "$GITEA_URL/api/v1/user/repos" \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d "{ \"name\": \"$REPO_NAME\", \"description\": \"Nicholas Haven Resume Site\", \"private\": false, \"auto_init\": false }" || echo "Repository might already exist" echo "✓ Repository created/verified" } # Function to push to Gitea push_to_gitea() { echo "Pushing code to Gitea..." # Determine the git remote URL if [ -n "$GITEA_USER" ]; then GIT_URL="$GITEA_URL/$GITEA_USER/$REPO_NAME.git" else echo "Please enter your Gitea username:" read GITEA_USER GIT_URL="$GITEA_URL/$GITEA_USER/$REPO_NAME.git" fi # Check if main branch exists, if not rename master to main if git branch | grep -q "master"; then git branch -M main fi # Add remote git remote remove origin 2>/dev/null || true git remote add origin "$GIT_URL" # Push git push -u origin main echo "✓ Code pushed to Gitea" } # Function to build and push Docker image build_and_push() { if ! command -v docker &> /dev/null; then echo "⚠ Docker not found. Skipping image build." echo "Please build and push the image manually:" echo "" echo " docker login $HARBOR_URL" echo " docker build -t $HARBOR_URL/production/resume-site:latest ." echo " docker push $HARBOR_URL/production/resume-site:latest" echo "" return 0 fi echo "Building Docker image..." docker build -t "$HARBOR_URL/production/$REPO_NAME:latest" . if [ -n "$HARBOR_USER" ] && [ -n "$HARBOR_PASSWORD" ]; then echo "Logging into Harbor..." echo "$HARBOR_PASSWORD" | docker login "$HARBOR_URL" -u "$HARBOR_USER" --password-stdin else echo "Logging into Harbor (interactive)..." docker login "$HARBOR_URL" fi echo "Pushing image to Harbor..." docker push "$HARBOR_URL/production/$REPO_NAME:latest" echo "✓ Image pushed to Harbor" } # Function to update Flux manifests update_flux_manifests() { echo "Updating Flux manifests..." if [ -z "$GITEA_USER" ]; then echo "Please enter your Gitea username:" read GITEA_USER fi # Update GitRepository URL sed -i "s|url: .*|url: $GITEA_URL/$GITEA_USER/$REPO_NAME.git|" flux/gitrepository.yaml echo "✓ Flux manifests updated" } # Function to apply Flux manifests apply_flux() { echo "Applying Flux manifests to cluster..." kubectl apply -k flux/ echo "✓ Flux manifests applied" echo "" echo "Checking deployment status..." sleep 5 kubectl get gitrepository -n flux-system resume-site kubectl get helmrelease -n default resume-site } # Main deployment flow main() { check_prereqs echo "" echo "Choose deployment option:" echo "1. Full deployment (create repo, push code, build image, apply flux)" echo "2. Create Gitea repo and push code only" echo "3. Build and push Docker image only" echo "4. Apply Flux manifests only" echo "5. Manual setup instructions" echo "" read -p "Enter option (1-5): " option case $option in 1) create_gitea_repo update_flux_manifests push_to_gitea build_and_push apply_flux ;; 2) create_gitea_repo update_flux_manifests push_to_gitea ;; 3) build_and_push ;; 4) apply_flux ;; 5) show_manual_instructions ;; *) echo "Invalid option" exit 1 ;; esac echo "" echo "=== Deployment Complete ===" echo "" echo "Your resume site should be available at:" echo " https://resume.caffeinetux.com" echo "" echo "Monitor the deployment:" echo " kubectl get pods -n default -l app.kubernetes.io/name=resume-site" echo " kubectl logs -n default -l app.kubernetes.io/name=resume-site" } # Function to show manual instructions show_manual_instructions() { cat <<'EOF' === Manual Deployment Instructions === 1. Create Gitea Repository: - Go to http://192.168.1.49:13001 - Create a new repository named "resume-site" 2. Update Flux GitRepository manifest: - Edit flux/gitrepository.yaml - Replace the URL with: http://192.168.1.49:13001/YOUR_USERNAME/resume-site.git 3. Push code to Gitea: git branch -M main git remote add origin http://192.168.1.49:13001/YOUR_USERNAME/resume-site.git git push -u origin main 4. Build and push Docker image: docker login images.caffeinetux.com docker build -t images.caffeinetux.com/production/resume-site:latest . docker push images.caffeinetux.com/production/resume-site:latest 5. Apply Flux manifests: kubectl apply -k flux/ 6. Verify deployment: kubectl get gitrepository -n flux-system resume-site kubectl get helmrelease -n default resume-site kubectl get pods -n default -l app.kubernetes.io/name=resume-site 7. Access your site: https://resume.caffeinetux.com EOF } # Run main if script is executed if [ "${BASH_SOURCE[0]}" == "${0}" ]; then main "$@" fi