init
This commit is contained in:
173
ship.sh
Executable file
173
ship.sh
Executable file
@@ -0,0 +1,173 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Paragliding Build & Deploy Script
|
||||
REGISTRY="harbor.scottyah.com"
|
||||
NAMESPACE="scottyah"
|
||||
K8S_NAMESPACE="paragliding"
|
||||
|
||||
API_IMAGE="${REGISTRY}/${NAMESPACE}/paragliding-api"
|
||||
WEB_IMAGE="${REGISTRY}/${NAMESPACE}/paragliding-web"
|
||||
|
||||
# Parse flags
|
||||
BUILD_ONLY=false
|
||||
DEPLOY_ONLY=false
|
||||
API_ONLY=false
|
||||
WEB_ONLY=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--build-only)
|
||||
BUILD_ONLY=true
|
||||
shift
|
||||
;;
|
||||
--deploy-only)
|
||||
DEPLOY_ONLY=true
|
||||
shift
|
||||
;;
|
||||
--api-only)
|
||||
API_ONLY=true
|
||||
shift
|
||||
;;
|
||||
--web-only)
|
||||
WEB_ONLY=true
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
echo "Usage: ./ship.sh [OPTIONS]"
|
||||
echo ""
|
||||
echo "Build and deploy Paragliding to Kubernetes"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --build-only Only build and push Docker images"
|
||||
echo " --deploy-only Only deploy to Kubernetes (skip build)"
|
||||
echo " --api-only Only build/deploy the API"
|
||||
echo " --web-only Only build/deploy the web frontend"
|
||||
echo " -h, --help Show this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " ./ship.sh # Build and deploy everything"
|
||||
echo " ./ship.sh --build-only # Only build images"
|
||||
echo " ./ship.sh --api-only # Only build and deploy API"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
echo "Use --help for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
|
||||
|
||||
# Detect container runtime
|
||||
if command -v docker &> /dev/null; then
|
||||
CONTAINER_CMD="docker"
|
||||
elif command -v podman &> /dev/null; then
|
||||
CONTAINER_CMD="podman"
|
||||
else
|
||||
echo "❌ Error: Neither docker nor podman found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# BUILD PHASE
|
||||
if [ "$DEPLOY_ONLY" = false ]; then
|
||||
echo "🪂 Building Paragliding Docker images..."
|
||||
echo "Registry: ${REGISTRY}"
|
||||
echo "Timestamp: ${TIMESTAMP}"
|
||||
echo "Using: ${CONTAINER_CMD}"
|
||||
echo ""
|
||||
|
||||
# Build API
|
||||
if [ "$WEB_ONLY" = false ]; then
|
||||
echo "📦 Building API image..."
|
||||
${CONTAINER_CMD} build \
|
||||
--network=host \
|
||||
-t "${API_IMAGE}:${TIMESTAMP}" \
|
||||
-t "${API_IMAGE}:latest" \
|
||||
./backend
|
||||
|
||||
echo "🚀 Pushing API images..."
|
||||
${CONTAINER_CMD} push "${API_IMAGE}:${TIMESTAMP}"
|
||||
${CONTAINER_CMD} push "${API_IMAGE}:latest"
|
||||
echo "✅ API image pushed!"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Build Web
|
||||
if [ "$API_ONLY" = false ]; then
|
||||
echo "📦 Building Web image..."
|
||||
${CONTAINER_CMD} build \
|
||||
--network=host \
|
||||
-t "${WEB_IMAGE}:${TIMESTAMP}" \
|
||||
-t "${WEB_IMAGE}:latest" \
|
||||
--target runner \
|
||||
./frontend
|
||||
|
||||
echo "🚀 Pushing Web images..."
|
||||
${CONTAINER_CMD} push "${WEB_IMAGE}:${TIMESTAMP}"
|
||||
${CONTAINER_CMD} push "${WEB_IMAGE}:latest"
|
||||
echo "✅ Web image pushed!"
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
|
||||
# DEPLOY PHASE
|
||||
if [ "$BUILD_ONLY" = false ]; then
|
||||
echo "🪂 Deploying Paragliding to Kubernetes..."
|
||||
echo ""
|
||||
|
||||
# Create namespace if it doesn't exist
|
||||
echo "Ensuring namespace exists..."
|
||||
kubectl create namespace ${K8S_NAMESPACE} --dry-run=client -o yaml | kubectl apply -f -
|
||||
|
||||
# Apply Kubernetes configuration
|
||||
echo "Applying Kubernetes configuration..."
|
||||
kubectl apply -f k8s.yaml
|
||||
|
||||
echo ""
|
||||
echo "Waiting for namespace to be ready..."
|
||||
kubectl wait --for=condition=Ready --timeout=10s namespace/${K8S_NAMESPACE} 2>/dev/null || true
|
||||
|
||||
# Restart deployments
|
||||
if [ "$WEB_ONLY" = false ]; then
|
||||
echo "Restarting API deployment..."
|
||||
kubectl rollout restart deployment/paragliding-api -n ${K8S_NAMESPACE}
|
||||
fi
|
||||
|
||||
if [ "$API_ONLY" = false ]; then
|
||||
echo "Restarting Web deployment..."
|
||||
kubectl rollout restart deployment/paragliding-web -n ${K8S_NAMESPACE}
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Waiting for rollouts to complete..."
|
||||
if [ "$WEB_ONLY" = false ]; then
|
||||
kubectl rollout status deployment/paragliding-api -n ${K8S_NAMESPACE} --timeout=300s
|
||||
fi
|
||||
if [ "$API_ONLY" = false ]; then
|
||||
kubectl rollout status deployment/paragliding-web -n ${K8S_NAMESPACE} --timeout=300s
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "✅ Deployment complete!"
|
||||
echo ""
|
||||
echo "📊 Deployment status:"
|
||||
kubectl get pods -n ${K8S_NAMESPACE}
|
||||
echo ""
|
||||
kubectl get svc -n ${K8S_NAMESPACE}
|
||||
echo ""
|
||||
kubectl get ingress -n ${K8S_NAMESPACE}
|
||||
echo ""
|
||||
echo "🌍 Your site should be available at: https://paragliding.scottyah.com"
|
||||
echo ""
|
||||
echo "To view logs:"
|
||||
echo " kubectl logs -f deployment/paragliding-api -n ${K8S_NAMESPACE}"
|
||||
echo " kubectl logs -f deployment/paragliding-web -n ${K8S_NAMESPACE}"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
if [ "$BUILD_ONLY" = false ] && [ "$DEPLOY_ONLY" = false ]; then
|
||||
echo "✨ Build and deployment complete!"
|
||||
fi
|
||||
Reference in New Issue
Block a user