Skip to content

Commit

Permalink
add conditions to install tools step
Browse files Browse the repository at this point in the history
  • Loading branch information
Oloruntobi Olurombi committed Aug 29, 2024
1 parent 4c5a048 commit 8eb9958
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions .github/workflows/eks-setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,39 @@ jobs:
set -x
ssh -o StrictHostKeyChecking=no -i /tmp/private_key ec2-user@${{ env.EC2_PUBLIC_IP }} << 'EOF'
sudo yum install -y unzip
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
curl -O "https://s3.us-west-2.amazonaws.com/amazon-eks/1.28.11/2024-07-12/bin/linux/amd64/kubectl"
chmod +x ./kubectl
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH
# Check if AWS CLI exists
if ! command -v aws &> /dev/null
then
echo "AWS CLI not found, installing..."
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
else
echo "AWS CLI already installed"
fi
# Check if kubectl exists
if ! command -v kubectl &> /dev/null
then
echo "kubectl not found, installing..."
curl -O "https://s3.us-west-2.amazonaws.com/amazon-eks/1.28.11/2024-07-12/bin/linux/amd64/kubectl"
chmod +x ./kubectl
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH
else
echo "kubectl already installed"
fi
kubectl version --client
aws eks update-kubeconfig --region ${{ env.AWS_REGION }} --name ${{ env.EKS_CLUSTER_NAME }}
EOF
EOF
- name: Verify EC2 Instance State
run: |
run: |
INSTANCE_STATE=$(aws ec2 describe-instances --instance-ids $(terraform output -raw ec2_instance_id) --query 'Reservations[*].Instances[*].State.Name' --output text)
echo "EC2 Instance State: $INSTANCE_STATE"
if [[ "$INSTANCE_STATE" != "running" ]]; then
echo "Error: EC2 instance is not running."
exit 1
fi
fi

0 comments on commit 8eb9958

Please sign in to comment.