diff --git a/Dockerfile b/Dockerfile index 1c2f880..4d37bdd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,7 @@ RUN yum -y update && yum -y updateinfo && yum install -y \ && chmod 700 get_helm.sh \ && sh ./get_helm.sh \ && yum upgrade openssl \ + && pip3 install urllib3==1.26.7 \ && pip3 install print-env \ && yum clean all ENV PATH="/root/.tfenv/bin:$PATH" diff --git a/script.sh b/script.sh index 06d8eac..1ddede4 100644 --- a/script.sh +++ b/script.sh @@ -1,19 +1,19 @@ #!/usr/bin/env bash -# Exit on error or if an undefined variable is used -set -eu +# Exit on any error +set -e -# Check for dependencies -for cmd in jq tfenv aws curl; do - command -v "$cmd" >/dev/null 2>&1 || error_exit "$cmd is required but not installed." -done - -# Print error and exit +# Function to print an error and exit function error_exit { echo "$1" >&2 exit "${2:-1}" } +# Check for dependencies +for cmd in jq tfenv aws curl print-env; do + command -v "$cmd" >/dev/null 2>&1 || error_exit "$cmd is required but not installed." +done + # Ensure PORTUNUS_TOKEN is set [[ -z "${PORTUNUS_TOKEN}" ]] && error_exit "PORTUNUS_TOKEN is not set." @@ -22,19 +22,20 @@ while IFS="=" read -r key value; do export "$key=$(printf %b "$value")" done < <(print-env --api "https://portunusapiprod.ashishjullia.com/env" --format json | jq -r 'to_entries[] | "\(.key)=\(.value)"') -# Install specified Terraform version or default to the latest +# Install the specified Terraform version or default to the latest TF_VERSION="${TF_VERSION:-latest}" echo "Installing Terraform version: ${TF_VERSION}" tfenv install "$TF_VERSION" || error_exit "Failed to install Terraform version: ${TF_VERSION}" tfenv use "$TF_VERSION" || error_exit "Failed to switch to Terraform version: ${TF_VERSION}" -# Configure AWS with specified credentials +# Configure AWS with the specified or default credentials +AWS_REGION="${AWS_REGION:-us-west-1}" # Consider adding a default if appropriate echo "Configuring AWS with region: ${AWS_REGION}" aws configure set region "$AWS_REGION" || error_exit "Failed to set AWS region: ${AWS_REGION}" aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID" || error_exit "Failed to set AWS access key." aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY" || error_exit "Failed to set AWS secret access key." -# Update kubeconfig if cluster name is provided +# Update kubeconfig if a cluster name is provided if [[ -n "${NAME_OF_CLUSTER}" ]]; then aws eks update-kubeconfig --region "$AWS_REGION" --name "$NAME_OF_CLUSTER" || error_exit "Failed to update kubeconfig for cluster: ${NAME_OF_CLUSTER}" fi @@ -45,4 +46,5 @@ if [[ -n "$FLUX_VERSION" ]]; then curl -s https://fluxcd.io/install.sh | bash || error_exit "Failed to install Flux version: ${FLUX_VERSION}" fi +# Exit to a bash prompt /bin/bash