-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (87 loc) · 3.41 KB
/
main.yaml
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
name: Deploy
on:
push:
branches: [ "eks" ]
jobs:
build-api:
name: Build API Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS ECR credentials
uses: aws-actions/configure-aws-credentials@v4
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: Login to Amazon ECR
id: login-aws-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push API image to ECR
env:
ECR_REGISTRY: ${{ steps.login-aws-ecr.outputs.registry }}
ECR_REPOSITORY: ${{secrets.API_IMAGE_REPO}}
IMAGE_TAG: v2
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./api
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
build-frontend:
name: Build Frontend Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS ECR credentials
uses: aws-actions/configure-aws-credentials@v4
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: Login to Amazon ECR
id: login-aws-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push Frontened image to ECR
env:
ECR_REGISTRY: ${{ steps.login-aws-ecr.outputs.registry }}
ECR_REPOSITORY: ${{secrets.FRONTEND_IMAGE_REPO}}
IMAGE_TAG: v2
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./frontend
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
deploy:
name: Deploy to EKS
runs-on: arc-runner-set
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
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: Install curl
run: |
echo "installing curl..."
sudo apt-get update
sudo apt-get install -y curl
- name: Intall Helm
run: |
echo "installing helm..."
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
- name: Install AWS CLI
run: |
echo "installing aws cli..."
sudo apt-get update
sudo apt-get install -y awscli
- name: Configure Kubectl
run: |
echo "configuring kubectl"
aws eks update-kubeconfig --name ${{secrets.K8S_CLUSTER_NAME}} --region ${{secrets.AWS_REGION}}
- name: Install/Update Helm Chart
run: |
echo "installing/updating helm chart..."
helm upgrade --install todo-app ./todo --set database.host=${{secrets.DB_HOST}} --set database.username=${{secrets.DB_USERNAME}} --set database.password=${{secrets.DB_PASSWORD}} --set api.image.repository=${{secrets.API_IMAGE_URI}} --set frontend.image.repository=${{secrets.FRONTEND_IMAGE_URI}}