-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (84 loc) · 3.21 KB
/
deploy.yml
File metadata and controls
104 lines (84 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Build and Deploy
on:
push:
branches: [ main, feature/terraform-eks ]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to secrets
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push client
uses: docker/build-push-action@v5
with:
context: ./client
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/client:${{ github.run_number }}
${{ secrets.DOCKERHUB_USERNAME }}/client:latest
- name: Build and Push server
uses: docker/build-push-action@v5
with:
context: ./server
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/server:${{ github.run_number }}
${{ secrets.DOCKERHUB_USERNAME }}/server:latest
provision:
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
aws-region: ${{ secrets.AWS_REGION }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
- name: Terraform Init
run: terraform -chdir=infra init
- name: Terraform Plan
run: terraform -chdir=infra plan
- name: Terraform Apply
run: terraform -chdir=infra apply -auto-approve
deploy:
runs-on: ubuntu-latest
needs: provision
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
aws-region: ${{ secrets.AWS_REGION }}
- name: Set up kubectl
uses: azure/setup-kubectl@v3
- name: Configure kubeconfig
run: |
aws eks update-kubeconfig --region ${{ secrets.AWS_REGION }} --name ${{ secrets.EKS_CLUSTER_NAME }}
- name: Update image tags
run: |
sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/server:.*|image: ${{ secrets.DOCKERHUB_USERNAME }}/server:${{ github.run_number }}|" k8s/backend/deployment.yaml
sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/client:.*|image: ${{ secrets.DOCKERHUB_USERNAME }}/client:${{ github.run_number }}|" k8s/frontend/deployment.yaml
- name: Deploy to EKS Cluster
run: |
kubectl apply -f k8s/postgres/secret.yaml
kubectl apply -f k8s/postgres/deployment.yaml
kubectl apply -f k8s/backend/deployment.yaml
kubectl apply -f k8s/frontend/deployment.yaml
kubectl rollout status deployment/backend --timeout=300s
kubectl rollout status deployment/frontend --timeout=300s
- name: Verify deployment
run: |
kubectl get pods
kubectl get services