1+ name : GET Infrastructure UP
2+
3+ on :
4+ workflow_dispatch :
5+
6+ jobs :
7+ setup :
8+ runs-on : ubuntu-latest
9+
10+ steps :
11+ - name : Checkout code
12+ uses : actions/checkout@v4
13+
14+ - name : Install kubectl CLI
15+ uses : azure/setup-kubectl@v3
16+ with :
17+ version : ' v1.30.0'
18+
19+ - name : Setup Terraform
20+ uses : hashicorp/setup-terraform@v3
21+ with :
22+ cli_config_credentials_token : ${{ secrets.TF_API_TOKEN }}
23+
24+ - name : Install AWS cli
25+ id : install-aws-cli
26+ uses : unfor19/install-aws-cli-action@master
27+ with :
28+ version : ' 2.17.15'
29+
30+ - name : Configure AWS credentials
31+ uses : aws-actions/configure-aws-credentials@v4
32+ with :
33+ aws-region : us-east-1
34+ aws-access-key-id : ${{secrets.AWS_ACCESS_KEY_ID }}
35+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
36+
37+ - name : Provision the infrastructure (init)
38+ working-directory : EKS/
39+ run : |
40+ terraform init \
41+ -backend-config="token=${{ secrets.TF_API_TOKEN }}" \
42+ -backend-config="organization=your-org-name" \
43+ -backend-config="workspace=eks-infrastructure"
44+
45+ - name : Provision the infrastructure (plan)
46+ working-directory : EKS/
47+ run : |
48+ terraform plan
49+
50+ - name : Provision the infrastructure (apply)
51+ working-directory : EKS/
52+ run : |
53+ terraform apply -auto-approve
54+
55+ - name : Create a KUBECONFIG
56+ run : |
57+ aws eks update-kubeconfig --region us-east-1 --name demo-eks
58+
59+ - name : Capture Terraform Output
60+ working-directory : EKS/
61+ id : output
62+ run : |
63+ echo "Retrieving NodeInstanceRole..."
64+ NodeInstanceRole=$(terraform output -raw NodeInstanceRole)
65+ echo "NodeInstanceRole=$NodeInstanceRole" >> $GITHUB_ENV
66+
67+ - name : Download the node authentication ConfigMap
68+ working-directory : EKS/
69+ run : |
70+ curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/cloudformation/2020-10-29/aws-auth-cm.yaml
71+
72+ - name : Replace Part of the File
73+ working-directory : EKS/
74+ run : |
75+ sed -i "s|<ARN of instance role (not instance profile)>|${{ env.NodeInstanceRole }}|g" aws-auth-cm.yaml
76+
77+ - name : Apply the edited ConfigMap to join the nodes
78+ working-directory : EKS/
79+ run : |
80+ kubectl apply -f aws-auth-cm.yaml
81+
82+ - name : Check node status
83+ run : |
84+ sleep 100
85+
86+ Install-Ingress :
87+ needs : setup
88+ runs-on : ubuntu-latest
89+
90+ steps :
91+ - name : Checkout code
92+ uses : actions/checkout@v4
93+
94+ - name : Install kubectl CLI
95+ uses : azure/setup-kubectl@v3
96+ with :
97+ version : ' v1.33.0'
98+
99+ - name : Install AWS cli
100+ id : install-aws-cli
101+ uses : unfor19/install-aws-cli-action@master
102+ with :
103+ version : ' 2.17.13'
104+
105+ - name : Configure AWS credentials
106+ uses : aws-actions/configure-aws-credentials@v4
107+ with :
108+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
109+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
110+ aws-region : us-east-1
111+
112+ - name : Create a KUBECONFIG
113+ run : |
114+ aws eks update-kubeconfig --region us-east-1 --name demo-eks
115+
116+ - name : Install NLB
117+ run : |
118+ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.11.1/deploy/static/provider/aws/deploy.yaml
119+
120+ Monitoring-Stack-Install :
121+ needs : setup
122+ runs-on : ubuntu-latest
123+
124+ steps :
125+ - name : Checkout code
126+ uses : actions/checkout@v4
127+
128+ - name : Install kubectl CLI
129+ uses : azure/setup-kubectl@v3
130+ with :
131+ version : ' v1.33.0'
132+
133+ - name : Install AWS cli
134+ id : install-aws-cli
135+ uses : unfor19/install-aws-cli-action@master
136+ with :
137+ version : ' 2.17.13'
138+
139+ - name : Configure AWS credentials
140+ uses : aws-actions/configure-aws-credentials@v4
141+ with :
142+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
143+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
144+ aws-region : us-east-1
145+
146+ - name : Install Helm
147+ run : |
148+ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
149+ chmod 700 get_helm.sh
150+ ./get_helm.sh
151+
152+ - name : Create a KUBECONFIG
153+ run : |
154+ aws eks update-kubeconfig --region us-east-1 --name demo-eks
155+
156+ - name : Add Prometheus-community charts
157+ run : |
158+ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
159+ helm repo update
160+
161+ - name : Install kube-prometheus-stack By helm chart
162+ run : |
163+ kubectl create namespace monitoring
164+ helm install prometheus prometheus-community/kube-prometheus-stack --namespace monitoring
165+
166+ - name : Install loki-stack By helm chart
167+ run : |
168+ helm repo add grafana https://grafana.github.io/helm-charts
169+ helm install loki grafana/loki-stack --namespace monitoring
170+
171+ notify :
172+ runs-on : ubuntu-latest
173+ needs : [Install-Ingress, Monitoring-Stack-Install]
174+
175+ steps :
176+ - name : Notify Success
177+ uses : slackapi/slack-github-action@v1.24.0
178+ with :
179+ channel-id : ' deployments'
180+ slack-message : |
181+ :cloud: Infrastructure Deployment Successful! :cloud:
182+
183+ *Environment:* Production
184+ *Status:* :white_check_mark: Infrastructure Ready
185+
186+ *Details:*
187+ - EKS Cluster: demo-eks
188+ - Region: us-east-1
189+ - Ingress Controller: Installed
190+ - Monitoring Stack: Installed
191+
192+ *Components Deployed:*
193+ - EKS Cluster
194+ - NLB Ingress Controller
195+ - Prometheus Stack
196+ - Loki Stack
197+
198+ *Triggered by:* ${{ github.actor }}
199+ env :
200+ SLACK_BOT_TOKEN : ${{ secrets.SLACK_BOT_TOKEN }}
201+
202+ - name : Notify Failure
203+ if : failure()
204+ uses : slackapi/slack-github-action@v1.24.0
205+ with :
206+ channel-id : ' deployments'
207+ slack-message : |
208+ :x: Infrastructure Deployment Failed! :x:
209+
210+ *Environment:* Production
211+ *Status:* :x: Deployment Failed
212+
213+ *Error Details:*
214+ ```${{ github.event.head_commit.message }}```
215+
216+ *Triggered by:* ${{ github.actor }}
217+ env :
218+ SLACK_BOT_TOKEN : ${{ secrets.SLACK_BOT_TOKEN }}
219+
220+
221+
222+
223+
0 commit comments