Consolidates services into apps.
This commit is contained in:
@@ -1,140 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Default values
|
||||
SERVICE_NAME=""
|
||||
DRY_RUN=false
|
||||
|
||||
# Source environment variables from load-env.sh
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
if [ -f "$REPO_DIR/load-env.sh" ]; then
|
||||
source "$REPO_DIR/load-env.sh"
|
||||
fi
|
||||
|
||||
function show_help {
|
||||
echo "Usage: $0 SERVICE_NAME [options]"
|
||||
echo ""
|
||||
echo "Arguments:"
|
||||
echo " SERVICE_NAME Name of the service to deploy (directory name in services/)"
|
||||
echo ""
|
||||
echo "Optional arguments:"
|
||||
echo " --dry-run Preview the processed configuration without applying"
|
||||
echo " --help Show this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 example-app"
|
||||
echo " $0 blog --dry-run"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Legacy mode check for type-based commands
|
||||
if [[ "$1" == "--type" ]]; then
|
||||
echo "Warning: Using legacy mode (generate and deploy in one step)"
|
||||
echo "Consider using generate-service followed by deploy-service instead."
|
||||
echo "Continuing with legacy mode..."
|
||||
echo ""
|
||||
|
||||
# Capture all arguments
|
||||
ALL_ARGS="$@"
|
||||
|
||||
# Extract service name from arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
case $key in
|
||||
--name)
|
||||
SERVICE_NAME_LEGACY="$2"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Generate the service configuration first
|
||||
TMP_DIR=$(mktemp -d)
|
||||
TMP_FILE="$TMP_DIR/service.yaml"
|
||||
|
||||
$SCRIPT_DIR/generate-service $ALL_ARGS --output "$TMP_DIR"
|
||||
|
||||
# Now deploy it using the service name
|
||||
if [[ -n "$SERVICE_NAME_LEGACY" ]]; then
|
||||
exec $0 "$SERVICE_NAME_LEGACY"
|
||||
else
|
||||
echo "Error: Legacy mode requires --name parameter"
|
||||
exit 1
|
||||
fi
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# Parse command-line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
case $key in
|
||||
--dry-run)
|
||||
DRY_RUN=true
|
||||
shift
|
||||
;;
|
||||
--help)
|
||||
show_help
|
||||
;;
|
||||
-*)
|
||||
echo "Unknown option: $1"
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
# First non-option argument is the service name
|
||||
SERVICE_NAME="$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Validate service name
|
||||
if [[ -z "$SERVICE_NAME" ]]; then
|
||||
echo "Error: SERVICE_NAME must be provided"
|
||||
show_help
|
||||
fi
|
||||
|
||||
# Construct the service file path
|
||||
SERVICE_FILE="$REPO_DIR/services/$SERVICE_NAME/service.yaml"
|
||||
if [[ ! -f "$SERVICE_FILE" ]]; then
|
||||
echo "Error: Service file not found for $SERVICE_NAME at $SERVICE_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create temporary file for the processed manifest
|
||||
TEMP_FILE=$(mktemp)
|
||||
|
||||
# Ensure DOMAIN is exported for template substitution
|
||||
export DOMAIN="$DOMAIN"
|
||||
|
||||
# Process the service file with variable substitution
|
||||
echo "Processing service file: $SERVICE_FILE"
|
||||
cat "$SERVICE_FILE" | envsubst > "$TEMP_FILE"
|
||||
|
||||
# Handle dry run mode
|
||||
if [[ "$DRY_RUN" == "true" ]]; then
|
||||
cat "$TEMP_FILE"
|
||||
rm "$TEMP_FILE"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Extract namespace from the processed file (for creating it if needed)
|
||||
NAMESPACE=$(grep -o "namespace: [a-zA-Z0-9_-]\+" "$TEMP_FILE" | head -1 | cut -d' ' -f2)
|
||||
if [[ -n "$NAMESPACE" ]]; then
|
||||
# Create the namespace if it doesn't exist (using kubectl create which is idempotent with --dry-run=client)
|
||||
echo "Creating namespace $NAMESPACE if it doesn't exist..."
|
||||
kubectl create namespace "$NAMESPACE" --dry-run=client -o yaml | kubectl apply -f -
|
||||
# Copy certificates to the namespace
|
||||
copy-secret cert-manager:wildcard-internal-wild-cloud-tls $NAMESPACE
|
||||
copy-secret cert-manager:wildcard-wild-cloud-tls $NAMESPACE
|
||||
fi
|
||||
|
||||
# Apply the service
|
||||
echo "Applying service configuration..."
|
||||
kubectl apply -f "$TEMP_FILE"
|
||||
rm "$TEMP_FILE"
|
||||
|
||||
echo "✅ Service deployed successfully!"
|
@@ -1,186 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Source environment variables for defaults and domain settings
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
if [ -f "$SCRIPT_DIR/../load-env.sh" ]; then
|
||||
source "$SCRIPT_DIR/../load-env.sh"
|
||||
fi
|
||||
|
||||
# Default values
|
||||
SERVICE_TYPE=""
|
||||
SERVICE_NAME=""
|
||||
NAMESPACE=""
|
||||
IMAGE=""
|
||||
PORT=""
|
||||
SERVICE_DOMAIN=""
|
||||
OUTPUT_DIR=""
|
||||
|
||||
function show_help {
|
||||
echo "Usage: $0 --type [public|internal|database|microservice] --name SERVICE_NAME [options]"
|
||||
echo ""
|
||||
echo "Required arguments:"
|
||||
echo " --type TYPE Service type (public, internal, database, or microservice)"
|
||||
echo " --name NAME Service name"
|
||||
echo ""
|
||||
echo "Optional arguments:"
|
||||
echo " --namespace NAMESPACE Kubernetes namespace (defaults to service name)"
|
||||
echo " --image IMAGE Container image (defaults to nginx:latest for most types)"
|
||||
echo " --port PORT Container port (defaults to 80)"
|
||||
echo " --domain DOMAIN Custom domain (defaults to TYPE-specific domain)"
|
||||
echo " --output DIR Output directory (defaults to services/NAME)"
|
||||
echo " --help Show this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 --type public --name blog"
|
||||
echo " $0 --type internal --name admin --image my-admin:v1 --port 8080"
|
||||
echo " $0 --type database --name mysql --image mysql:8.0 --port 3306"
|
||||
echo " $0 --type microservice --name auth --image auth-service:v1 --port 9000"
|
||||
exit 1
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
case $key in
|
||||
--type)
|
||||
SERVICE_TYPE="$2"
|
||||
shift 2
|
||||
;;
|
||||
--name)
|
||||
SERVICE_NAME="$2"
|
||||
shift 2
|
||||
;;
|
||||
--namespace)
|
||||
NAMESPACE="$2"
|
||||
shift 2
|
||||
;;
|
||||
--image)
|
||||
IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
--port)
|
||||
PORT="$2"
|
||||
shift 2
|
||||
;;
|
||||
--domain)
|
||||
SERVICE_DOMAIN="$2"
|
||||
shift 2
|
||||
;;
|
||||
--output)
|
||||
OUTPUT_DIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
--help)
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
show_help
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Validate required parameters
|
||||
if [[ -z "$SERVICE_TYPE" ]]; then
|
||||
echo "Error: Service type is required"
|
||||
show_help
|
||||
fi
|
||||
|
||||
if [[ -z "$SERVICE_NAME" ]]; then
|
||||
echo "Error: Service name is required"
|
||||
show_help
|
||||
fi
|
||||
|
||||
# Validate service type
|
||||
if [[ "$SERVICE_TYPE" != "public" && "$SERVICE_TYPE" != "internal" && "$SERVICE_TYPE" != "database" && "$SERVICE_TYPE" != "microservice" ]]; then
|
||||
echo "Error: Invalid service type. Must be public, internal, database, or microservice."
|
||||
show_help
|
||||
fi
|
||||
|
||||
# Set defaults
|
||||
if [[ -z "$NAMESPACE" ]]; then
|
||||
NAMESPACE="$SERVICE_NAME"
|
||||
fi
|
||||
|
||||
if [[ -z "$IMAGE" ]]; then
|
||||
if [[ "$SERVICE_TYPE" == "database" ]]; then
|
||||
IMAGE="mariadb:10.6"
|
||||
else
|
||||
IMAGE="nginx:latest"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$PORT" ]]; then
|
||||
if [[ "$SERVICE_TYPE" == "database" ]]; then
|
||||
PORT="3306"
|
||||
else
|
||||
PORT="80"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$SERVICE_DOMAIN" ]]; then
|
||||
if [[ "$SERVICE_TYPE" == "public" ]]; then
|
||||
SERVICE_DOMAIN="\${SERVICE_NAME}.\${DOMAIN}"
|
||||
elif [[ "$SERVICE_TYPE" == "internal" ]]; then
|
||||
SERVICE_DOMAIN="\${SERVICE_NAME}.internal.\${DOMAIN}"
|
||||
elif [[ "$SERVICE_TYPE" == "microservice" ]]; then
|
||||
SERVICE_DOMAIN="\${SERVICE_NAME}.svc.\${DOMAIN}"
|
||||
else
|
||||
SERVICE_DOMAIN="\${SERVICE_NAME}.db.\${DOMAIN}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Set default output directory if not provided
|
||||
if [[ -z "$OUTPUT_DIR" ]]; then
|
||||
OUTPUT_DIR="$SCRIPT_DIR/../services/$SERVICE_NAME"
|
||||
fi
|
||||
|
||||
echo "Generating $SERVICE_TYPE service configuration for: $SERVICE_NAME"
|
||||
echo "Namespace: $NAMESPACE"
|
||||
echo "Image: $IMAGE"
|
||||
echo "Port: $PORT"
|
||||
echo "Domain Template: $SERVICE_DOMAIN"
|
||||
echo "Output Directory: $OUTPUT_DIR"
|
||||
echo
|
||||
|
||||
# Get the appropriate template
|
||||
if [[ "$SERVICE_TYPE" == "microservice" ]]; then
|
||||
TEMPLATE_FILE="$SCRIPT_DIR/../services/templates/microservice/service.yaml"
|
||||
else
|
||||
TEMPLATE_FILE="$SCRIPT_DIR/../services/templates/${SERVICE_TYPE}-service/service.yaml"
|
||||
fi
|
||||
|
||||
if [[ ! -f "$TEMPLATE_FILE" ]]; then
|
||||
echo "Error: Template file not found: $TEMPLATE_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create output directory if it doesn't exist
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
# Create the service YAML
|
||||
echo "Creating service configuration..."
|
||||
|
||||
# Prepare variables for substitution
|
||||
export SERVICE_NAME="$SERVICE_NAME"
|
||||
export SERVICE_NAMESPACE="$NAMESPACE"
|
||||
export SERVICE_IMAGE="\"$IMAGE\""
|
||||
export SERVICE_PORT="$PORT"
|
||||
export SERVICE_DOMAIN="$SERVICE_DOMAIN"
|
||||
|
||||
# Process the template with variable substitution
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
# Define which variables to replace - only those from command arguments
|
||||
VARS_TO_REPLACE='${SERVICE_NAME},${SERVICE_NAMESPACE},${SERVICE_IMAGE},${SERVICE_PORT},${SERVICE_DOMAIN}'
|
||||
|
||||
# Process the template, only substituting the variables from arguments
|
||||
cat "$TEMPLATE_FILE" | envsubst "$VARS_TO_REPLACE" > "$OUTPUT_DIR/service.yaml"
|
||||
|
||||
echo "✅ Service configuration generated successfully!"
|
||||
echo "Configuration file: $OUTPUT_DIR/service.yaml"
|
||||
echo ""
|
||||
echo "To deploy this service configuration:"
|
||||
echo " ./bin/deploy-service $SERVICE_NAME"
|
||||
echo ""
|
||||
echo "To customize further, edit the generated file before deployment."
|
Reference in New Issue
Block a user