Skip to content

Commit

Permalink
upadted script and dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishjullia committed Sep 18, 2023
1 parent 9ecd0de commit 240c81b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 13 additions & 11 deletions script.sh
Original file line number Diff line number Diff line change
@@ -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."

Expand All @@ -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
Expand All @@ -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

0 comments on commit 240c81b

Please sign in to comment.