-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (119 loc) · 6.41 KB
/
aws.yml
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Deploy to Amazon ECS
on:
push:
branches: [ "main" ]
env:
AWS_REGION: eu-south-2
ECR_REPOSITORY_BACKEND: ecommerce-backend
ECR_REPOSITORY_FRONTEND: ecommerce-frontend
ECR_REPOSITORY_NGINX: ecommerce-nginx
ECS_SERVICE: ecommerce-service
ECS_CLUSTER: e-commerce-cluster
ECS_TASK_DEFINITION: .aws/task-definition.json
CONTAINER_NAME_BACKEND: ecommerce-backend
CONTAINER_NAME_FRONTEND: ecommerce-frontend
CONTAINER_NAME_NGINX: ecommerce-nginx
permissions:
contents: read
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push Backend image to Amazon ECR
id: build-backend-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_TEST: ${{ secrets.DB_TEST }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_USER: ${{ secrets.DB_USER }}
DB_DRIVER: ${{ secrets.DB_DRIVER }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
REFRESH_SECRET: ${{ secrets.REFRESH_SECRET }}
JWT_EXPIRATION: ${{ secrets.JWT_EXPIRATION }}
JWT_REFRESH_EXPIRATION: ${{ secrets.JWT_REFRESH_EXPIRATION }}
JWT_VALIDATION_EXPIRATION: ${{ secrets.JWT_VALIDATION_EXPIRATION }}
SUPER_USER_USERNAME: ${{ secrets.SUPER_USER_USERNAME }}
SUPER_USER_PASSWORD: ${{ secrets.SUPER_USER_PASSWORD }}
SUPER_USER_EMAIL: ${{ secrets.SUPER_USER_EMAIL }}
SUPER_USER_FIRST_NAME: ${{ secrets.SUPER_USER_FIRST_NAME }}
SUPER_USER_LAST_NAME: ${{ secrets.SUPER_USER_LAST_NAME }}
SUPER_USER_AGE: ${{ secrets.SUPER_USER_AGE }}
run: |
echo "DB_HOST=${{ secrets.DB_HOST }}" >> .env
echo "DB_NAME=${{ secrets.DB_NAME }}" >> .env
echo "DB_TEST=${{ secrets.DB_TEST }}" >> .env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
echo "DB_USER=${{ secrets.DB_USER }}" >> .env
echo "DB_DRIVER=${{ secrets.DB_DRIVER }}" >> .env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
echo "REFRESH_SECRET=${{ secrets.REFRESH_SECRET }}" >> .env
echo "JWT_EXPIRATION=${{ secrets.JWT_EXPIRATION }}" >> .env
echo "JWT_REFRESH_EXPIRATION=${{ secrets.JWT_REFRESH_EXPIRATION }}" >> .env
echo "JWT_VALIDATION_EXPIRATION=${{ secrets.JWT_VALIDATION_EXPIRATION }}" >> .env
echo "SUPER_USER_USERNAME=${{ secrets.SUPER_USER_USERNAME }}" >> .env
echo "SUPER_USER_PASSWORD=${{ secrets.SUPER_USER_PASSWORD }}" >> .env
echo "SUPER_USER_EMAIL=${{ secrets.SUPER_USER_EMAIL }}" >> .env
echo "SUPER_USER_FIRST_NAME=${{ secrets.SUPER_USER_FIRST_NAME }}" >> .env
echo "SUPER_USER_LAST_NAME=${{ secrets.SUPER_USER_LAST_NAME }}" >> .env
echo "SUPER_USER_AGE=${{ secrets.SUPER_USER_AGE }}" >> .env
docker build -t $ECR_REGISTRY/${{ env.ECR_REPOSITORY_BACKEND }}:${{ github.sha }} --build-arg DB_HOST=$DB_HOST --build-arg DB_NAME=$DB_NAME --build-arg DB_TEST=$DB_TEST --build-arg DB_PASSWORD=$DB_PASSWORD --build-arg DB_USER=$DB_USER --build-arg DB_DRIVER=$DB_DRIVER --build-arg JWT_SECRET=$JWT_SECRET --build-arg REFRESH_SECRET=$REFRESH_SECRET --build-arg JWT_EXPIRATION=$JWT_EXPIRATION --build-arg JWT_REFRESH_EXPIRATION=$JWT_REFRESH_EXPIRATION --build-arg JWT_VALIDATION_EXPIRATION=$JWT_VALIDATION_EXPIRATION --build-arg SUPER_USER_USERNAME=$SUPER_USER_USERNAME --build-arg SUPER_USER_PASSWORD=$SUPER_USER_PASSWORD --build-arg SUPER_USER_EMAIL=$SUPER_USER_EMAIL --build-arg SUPER_USER_FIRST_NAME=$SUPER_USER_FIRST_NAME --build-arg SUPER_USER_LAST_NAME=$SUPER_USER_LAST_NAME --build-arg SUPER_USER_AGE=$SUPER_USER_AGE -f BackendProd.Dockerfile .
docker push $ECR_REGISTRY/${{ env.ECR_REPOSITORY_BACKEND }}:${{ github.sha }}
echo "backend_image=$ECR_REGISTRY/${{ env.ECR_REPOSITORY_BACKEND }}:${{ github.sha }}" >> $GITHUB_ENV
- name: Build, tag, and push Frontend image to Amazon ECR
id: build-frontend-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/${{ env.ECR_REPOSITORY_FRONTEND }}:${{ github.sha }} -f FrontendProd.Dockerfile .
docker push $ECR_REGISTRY/${{ env.ECR_REPOSITORY_FRONTEND }}:${{ github.sha }}
echo "frontend_image=$ECR_REGISTRY/${{ env.ECR_REPOSITORY_FRONTEND }}:${{ github.sha }}" >> $GITHUB_ENV
- name: Build, tag, and push Nginx image to Amazon ECR
id: build-nginx-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/${{ env.ECR_REPOSITORY_NGINX }}:${{ github.sha }} -f Nginx.Dockerfile .
docker push $ECR_REGISTRY/${{ env.ECR_REPOSITORY_NGINX }}:${{ github.sha }}
echo "nginx_image=$ECR_REGISTRY/${{ env.ECR_REPOSITORY_NGINX }}:${{ github.sha }}" >> $GITHUB_ENV
- name: Fill in the new image IDs in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME_BACKEND }}
image: ${{ env.backend_image }}
- uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
container-name: ${{ env.CONTAINER_NAME_FRONTEND }}
image: ${{ env.frontend_image }}
- uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
container-name: ${{ env.CONTAINER_NAME_NGINX }}
image: ${{ env.nginx_image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true