Skip to content

Commit 63498f0

Browse files
committed
small update :)
1 parent cdc4d45 commit 63498f0

File tree

7 files changed

+380
-0
lines changed

7 files changed

+380
-0
lines changed

.github/workflows/cd.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Continuous Deployment
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
AWS_REGION: us-east-1
8+
EKS_CLUSTER_NAME: demo-eks
9+
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Configure AWS credentials
18+
uses: aws-actions/configure-aws-credentials@v2
19+
with:
20+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
21+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
22+
aws-region: ${{ env.AWS_REGION }}
23+
24+
- name: Update kubeconfig
25+
run: aws eks update-kubeconfig --name ${{ env.EKS_CLUSTER_NAME }} --region ${{ env.AWS_REGION }}
26+
27+
- name: Install Helm
28+
uses: azure/setup-helm@v3
29+
with:
30+
version: v3.12.0
31+
32+
- name: Deploy to EKS
33+
run: |
34+
helm upgrade --install simple-go ./simple-go \
35+
--namespace production \
36+
--create-namespace \
37+
--set frontend.replicaCount=2 \
38+
--set backend.replicaCount=2 \
39+
--wait
40+
41+
- name: Verify deployment
42+
run: |
43+
kubectl rollout status deployment/frontend -n production
44+
kubectl rollout status deployment/backend -n production
45+
46+
- name: Get application URL
47+
id: url
48+
run: |
49+
INGRESS_URL=$(kubectl get ingress simple-go -n production -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
50+
echo "url=$INGRESS_URL" >> $GITHUB_OUTPUT
51+
52+
- name: Notify Slack
53+
uses: slackapi/slack-github-action@v1.24.0
54+
with:
55+
channel-id: 'deployments'
56+
slack-message: |
57+
:rocket: Deployment Successful! :rocket:
58+
59+
*Application:* Simple Go
60+
*Environment:* Production
61+
*Status:* :white_check_mark: Deployed Successfully
62+
*URL:* https://${{ steps.url.outputs.url }}
63+
64+
*Deployment Details:*
65+
- Frontend Replicas: 2
66+
- Backend Replicas: 2
67+
- Namespace: production
68+
69+
*Commit:* ${{ github.sha }}
70+
*Triggered by:* ${{ github.actor }}
71+
env:
72+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
73+
74+
- name: Notify on Failure
75+
if: failure()
76+
uses: slackapi/slack-github-action@v1.24.0
77+
with:
78+
channel-id: 'deployments'
79+
slack-message: |
80+
:x: Deployment Failed! :x:
81+
82+
*Application:* Simple Go
83+
*Environment:* Production
84+
*Status:* :x: Deployment Failed
85+
86+
*Error Details:*
87+
```${{ github.event.head_commit.message }}```
88+
89+
*Commit:* ${{ github.sha }}
90+
*Triggered by:* ${{ github.actor }}
91+
env:
92+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

.github/workflows/destroy.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Destroy All Infrastructure
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: Setup Terraform
15+
uses: hashicorp/setup-terraform@v3
16+
with:
17+
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
18+
19+
- name: Terraform Init
20+
working-directory: EKS/
21+
run: terraform init
22+
23+
- name: Terraform Apply
24+
working-directory: EKS/
25+
run: terraform destroy -auto-approve
26+
27+
- name: Notify Infrastructure Down
28+
uses: slackapi/slack-github-action@v1.24.0
29+
with:
30+
channel-id: 'deployments'
31+
slack-message: |
32+
:warning: Infrastructure Destruction Complete : ( !!!!! :warning:
33+
34+
*Environment:* Production
35+
*Status:* :x: Infrastructure Destroyed
36+
37+
*Components Removed:*
38+
- EKS Cluster
39+
- NLB Ingress Controller
40+
- Prometheus Stack
41+
- Loki Stack
42+
43+
*Triggered by:* ${{ github.actor }}
44+
env:
45+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
46+
47+
- name: Notify Failure
48+
if: failure()
49+
uses: slackapi/slack-github-action@v1.24.0
50+
with:
51+
channel-id: 'deployments'
52+
slack-message: |
53+
:x: Infrastructure Destruction Failed! :x:
54+
55+
*Environment:* Production
56+
*Status:* :x: Destruction Failed
57+
58+
*Error Details:*
59+
```${{ github.event.head_commit.message }}```
60+
61+
*Triggered by:* ${{ github.actor }}
62+
env:
63+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
64+
65+

.github/workflows/infra.yml

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
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+

images/kubelet.png

304 KB
Loading

images/node.png

165 KB
Loading

images/workflow.jpg

121 KB
Loading

terraform-modules/diagram.jpg

103 KB
Loading

0 commit comments

Comments
 (0)