deploy_app.sh•3.4 kB
#!/usr/bin/env bash
################################################################################
#
# Script Name: deploy_app.sh
# ----------------
# Deploys a specified application to a target environment on a cloud provider.
#
# @author Nicholas Wilde, 0xb299a622
# @date 02 Sep 2025
# @version 0.1.0
#
################################################################################
set -o errexit
set -o nounset
set -o pipefail
# --- Global Variables ---
APP_NAME=""
APP_VERSION=""
ENVIRONMENT=""
CLOUD_PROVIDER=""
REGION=""
CONFIG_FILE=""
# --- Functions ---
# Function to display script usage
usage() {
echo "Usage: $0 --app-name <name> --version <version> --environment <env> --cloud-provider <provider> [--region <region>] [--config-file <path>]"
echo " --app-name Name of the application to deploy."
echo " --version Version of the application (e.g., Docker image tag)."
echo " --environment Deployment environment (e.g., dev, staging, prod)."
echo " --cloud-provider Cloud provider (e.g., aws, azure, gcp)."
echo " --region (Optional) Cloud region for deployment. Defaults to provider's default."
echo " --config-file (Optional) Path to an environment-specific configuration file."
exit 1
}
# Function to parse command-line arguments
parse_args() {
while [[ "$#" -gt 0 ]]; do
case "$1" in
--app-name) APP_NAME="$2"; shift ;;
--version) APP_VERSION="$2"; shift ;;
--environment) ENVIRONMENT="$2"; shift ;;
--cloud-provider) CLOUD_PROVIDER="$2"; shift ;;
--region) REGION="$2"; shift ;;
--config-file) CONFIG_FILE="$2"; shift ;;
-h|--help) usage ;;
*) echo "Unknown parameter passed: $1"; usage ;;
esac
shift
done
# Validate required arguments
if [[ -z "$APP_NAME" || -z "$APP_VERSION" || -z "$ENVIRONMENT" || -z "$CLOUD_PROVIDER" ]]; then
echo "Error: Missing required arguments."
usage
fi
}
# Function to deploy to AWS
deploy_aws() {
echo "Deploying $APP_NAME v$APP_VERSION to AWS $ENVIRONMENT in region $REGION..."
# Add AWS-specific deployment logic here (e.g., AWS CLI commands, CloudFormation, CDK)
# Example: aws ecs update-service --cluster my-cluster --service my-service --force-new-deployment
echo "AWS deployment complete."
}
# Function to deploy to Azure
deploy_azure() {
echo "Deploying $APP_NAME v$APP_VERSION to Azure $ENVIRONMENT in region $REGION..."
# Add Azure-specific deployment logic here (e.g., Azure CLI commands, ARM templates)
echo "Azure deployment complete."
}
# Function to deploy to GCP
deploy_gcp() {
echo "Deploying $APP_NAME v$APP_VERSION to GCP $ENVIRONMENT in region $REGION..."
# Add GCP-specific deployment logic here (e.g., gcloud CLI commands, Deployment Manager)
echo "GCP deployment complete."
}
# --- Main Logic ---
main() {
parse_args "$@"
echo "Starting deployment of $APP_NAME v$APP_VERSION to $ENVIRONMENT environment on $CLOUD_PROVIDER."
if [[ -n "$CONFIG_FILE" ]]; then
echo "Using configuration file: $CONFIG_FILE"
# Load configuration from file (e.g., parse YAML/JSON with yq/jq)
fi
case "$CLOUD_PROVIDER" in
aws)
deploy_aws
;;
azure)
deploy_azure
;;
gcp)
deploy_gcp
;;
*)
echo "Error: Unsupported cloud provider: $CLOUD_PROVIDER"
usage
;;
esac
echo "Deployment script finished."
}
main "$@"