Skip to content

Commit

Permalink
feat: install-thunder.sh (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raezil authored Mar 1, 2025
1 parent 3dbc846 commit 7a2c241
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
66 changes: 66 additions & 0 deletions install-sh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Thunder CLI 🚀

A custom CLI tool to automate:
- **Generating gRPC and Prisma files** (`thunder generate`)
- **Deploying Kubernetes resources** (`thunder deploy`)

## Installation

### 1. Clone or Download the Repository
If you haven't already, navigate to your project directory where `generator.go` is located.

### 2. Run the Installation Script
Make sure you have **Go**, **Minikube**, and **kubectl** installed.

Run the following command:

```bash
chmod +x install-thunder.sh && ./install-thunder.sh
```

This script will:
- Compile `generator.go` into the `thunder-generate` binary.
- Move `thunder-generate` and the `thunder` CLI script to `/usr/local/bin/`.
- Make them globally accessible.

## Usage

### Generate gRPC & Prisma Files
```bash
thunder generate --proto yourfile.proto
```
or
```bash
thunder generate --prisma
```

### Deploy Kubernetes Resources
```bash
thunder deploy
```
This command will:
1. Start Minikube.
2. Apply PostgreSQL deployments and services.
3. Apply your app’s Kubernetes deployments and services.
4. Restart PgBouncer and your app deployment.
5. Forward port `8080` to access the application.

## Requirements
- **Go** (for building `thunder-generate`)
- **Minikube** (for Kubernetes)
- **kubectl** (to manage Kubernetes resources)
- **Prisma Client Go** (if using Prisma)
- **Protobuf Compiler (`protoc`)** (if using gRPC)

## Uninstallation
To remove the CLI:

```bash
sudo rm /usr/local/bin/thunder /usr/local/bin/thunder-generate
```

## Troubleshooting
- If `thunder` is not recognized, make sure `/usr/local/bin/` is in your `$PATH`:
```bash
export PATH=$PATH:/usr/local/bin
```
70 changes: 70 additions & 0 deletions install-thunder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

set -e # Exit immediately if a command exits with a non-zero status

# Build the thunder-generate binary
echo "⚙️ Building thunder-generate..."
go build -o thunder-generate generator.go

# Move thunder-generate to /usr/local/bin/
echo "🚀 Moving thunder-generate to /usr/local/bin/..."
sudo mv thunder-generate /usr/local/bin/

# Create the thunder command script
echo "🛠️ Creating thunder command script..."
cat << 'EOF' | sudo tee /usr/local/bin/thunder > /dev/null
#!/bin/bash
case "$1" in
generate)
shift
thunder-generate "$@"
;;
deploy)
echo "🚀 Starting Minikube..."
minikube start
# Change to Kubernetes manifests directory
cd k8s || { echo "❌ Directory k8s not found!"; exit 1; }
# Apply PostgreSQL resources
echo "📦 Deploying PostgreSQL..."
kubectl apply -f postgres-deployment.yaml
kubectl apply -f postgres-service.yaml
kubectl apply -f postgres-pvc.yaml
# Wait for PostgreSQL to be ready
echo "⏳ Waiting for PostgreSQL to be ready..."
kubectl wait --for=condition=ready pod -l app=postgres --timeout=60s
# Apply application deployments and services
echo "⚙️ Deploying Thunder API..."
kubectl apply -f app-deployment.yaml
kubectl apply -f app-service.yaml
kubectl apply -f app-loadbalancer.yaml
# Apply PgBouncer for database connection pooling
echo "🔄 Deploying PgBouncer..."
kubectl apply -f pgbouncer-all.yaml
# Restart necessary deployments
echo "🔄 Restarting PgBouncer and Thunder API deployments..."
kubectl rollout restart deployment pgbouncer
kubectl rollout restart deployment app-deployment
# Port forward the app service
echo "🔗 Forwarding port 8080 to app-service..."
kubectl port-forward service/app-service 8080:8080 &
;;
*)
echo "⚡ Usage: thunder [generate | deploy]"
exit 1
;;
esac
EOF

# Make thunder executable
echo "🔧 Making thunder command executable..."
sudo chmod +x /usr/local/bin/thunder

echo "✅ Installation complete! You can now use 'thunder generate' and 'thunder deploy'."

0 comments on commit 7a2c241

Please sign in to comment.