-
Notifications
You must be signed in to change notification settings - Fork 1
163 lines (153 loc) · 8.37 KB
/
backcicd.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Backend CI/CD Pipeline
on:
push:
branches:
- 48-Develop브랜치-푸시시-CI/CD-구현
jobs:
build_and_deploy:
name: Build and Deploy Modules
runs-on: ubuntu-latest
strategy:
matrix:
include:
- module: auth
dockerfile_path: ./gitfolio-auth/Dockerfile
build_context: ./gitfolio-auth
image_name: aida0/gitfolio_auth:test
ec2_filters: |
Name=tag:Name,Values=Gitfolio BE1
Name=tag:Environment,Values=dev
Name=tag:Type,Values=ec2
- module: member
dockerfile_path: ./gitfolio-member/Dockerfile
build_context: ./gitfolio-member
image_name: aida0/gitfolio_member:test
ec2_filters: |
Name=tag:Name,Values=Gitfolio BE1
Name=tag:Environment,Values=dev
Name=tag:Type,Values=ec2
- module: payment
dockerfile_path: ./gitfolio-payment/Dockerfile
build_context: ./gitfolio-payment
image_name: aida0/gitfolio_payment:test
ec2_filters: |
Name=tag:Name,Values=Gitfolio BE2
Name=tag:Environment,Values=dev
Name=tag:Type,Values=ec2
- module: resume
dockerfile_path: ./gitfolio-resume/Dockerfile
build_context: ./gitfolio-resume
image_name: aida0/gitfolio_resume:test
ec2_filters: |
Name=tag:Name,Values=Gitfolio BE2
Name=tag:Environment,Values=dev
Name=tag:Type,Values=ec2
steps:
- name: Checkout code
uses: actions/checkout@v3
- 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: ap-northeast-2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build the Docker image
run: |
docker build \
--build-arg REDIRECT_ONBOARDING_URL=${{ secrets.REDIRECT_ONBOARDING_URL }} \
--build-arg REDIRECT_MAIN_URL=${{ secrets.REDIRECT_MAIN_URL }} \
--build-arg MEMBER_SERVER_URL=${{ secrets.MEMBER_SERVER_URL }} \
--build-arg PAYMENT_SERVER_URL=${{ secrets.PAYMENT_SERVER_URL }} \
--build-arg AI_SERVER_URL=${{ secrets.AI_SERVER_URL }} \
--build-arg MEMBER_GRPC_PORT=${{ secrets.MEMBER_GRPC_PORT }} \
--build-arg AUTH_SERVER_PORT=${{ secrets.AUTH_SERVER_PORT }} \
--build-arg MEMBER_SERVER_PORT=${{ secrets.MEMBER_SERVER_PORT }} \
--build-arg RESUME_SERVER_PORT=${{ secrets.RESUME_SERVER_PORT }} \
--build-arg PAYMENT_SERVER_PORT=${{ secrets.PAYMENT_SERVER_PORT }} \
--build-arg NOTIFICATION_SERVER_PORT=${{ secrets.NOTIFICATION_SERVER_PORT }} \
--build-arg CHAT_SERVER_PORT=${{ secrets.CHAT_SERVER_PORT }} \
--build-arg GH_CLIENT_ID=${{ secrets.GH_CLIENT_ID }} \
--build-arg GH_CLIENT_SECRET=${{ secrets.GH_CLIENT_SECRET }} \
--build-arg GH_REDIRECT_URI=${{ secrets.GH_REDIRECT_URI }} \
--build-arg GH_API_TOKEN=${{ secrets.GH_API_TOKEN }} \
--build-arg JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }} \
--build-arg ACCESS_TOKEN_EXPIRY=${{ secrets.ACCESS_TOKEN_EXPIRY }} \
--build-arg REFRESH_TOKEN_EXPIRY=${{ secrets.REFRESH_TOKEN_EXPIRY }} \
--build-arg AUTH_REDIS_HOST=${{ secrets.AUTH_REDIS_HOST }} \
--build-arg AUTH_REDIS_PORT=${{ secrets.AUTH_REDIS_PORT }} \
--build-arg RESUME_REDIS_HOST=${{ secrets.RESUME_REDIS_HOST }} \
--build-arg RESUME_REDIS_PORT=${{ secrets.RESUME_REDIS_PORT }} \
--build-arg MEMBER_MYSQL_DB_HOST=${{ secrets.MEMBER_MYSQL_DB_HOST }} \
--build-arg MEMBER_MYSQL_DB_PORT=${{ secrets.MEMBER_MYSQL_DB_PORT }} \
--build-arg MEMBER_MYSQL_DB_NAME=${{ secrets.MEMBER_MYSQL_DB_NAME }} \
--build-arg MEMBER_MYSQL_DB_PASSWORD=${{ secrets.MEMBER_MYSQL_DB_PASSWORD }} \
--build-arg MEMBER_MYSQL_DB_USERNAME=${{ secrets.MEMBER_MYSQL_DB_USERNAME }} \
--build-arg LIKE_MYSQL_DB_HOST=${{ secrets.LIKE_MYSQL_DB_HOST }} \
--build-arg LIKE_MYSQL_DB_PORT=${{ secrets.LIKE_MYSQL_DB_PORT }} \
--build-arg LIKE_MYSQL_DB_NAME=${{ secrets.LIKE_MYSQL_DB_NAME }} \
--build-arg LIKE_MYSQL_DB_PASSWORD=${{ secrets.LIKE_MYSQL_DB_PASSWORD }} \
--build-arg LIKE_MYSQL_DB_USERNAME=${{ secrets.LIKE_MYSQL_DB_USERNAME }} \
--build-arg PAYMENT_MYSQL_DB_HOST=${{ secrets.PAYMENT_MYSQL_DB_HOST }} \
--build-arg PAYMENT_MYSQL_DB_PORT=${{ secrets.PAYMENT_MYSQL_DB_PORT }} \
--build-arg PAYMENT_MYSQL_DB_NAME=${{ secrets.PAYMENT_MYSQL_DB_NAME }} \
--build-arg PAYMENT_MYSQL_DB_PASSWORD=${{ secrets.PAYMENT_MYSQL_DB_PASSWORD }} \
--build-arg PAYMENT_MYSQL_DB_USERNAME=${{ secrets.PAYMENT_MYSQL_DB_USERNAME }} \
--build-arg NOTIFICATION_MYSQL_DB_HOST=${{ secrets.NOTIFICATION_MYSQL_DB_HOST }} \
--build-arg NOTIFICATION_MYSQL_DB_PORT=${{ secrets.NOTIFICATION_MYSQL_DB_PORT }} \
--build-arg NOTIFICATION_MYSQL_DB_NAME=${{ secrets.NOTIFICATION_MYSQL_DB_NAME }} \
--build-arg NOTIFICATION_MYSQL_DB_PASSWORD=${{ secrets.NOTIFICATION_MYSQL_DB_PASSWORD }} \
--build-arg NOTIFICATION_MYSQL_DB_USERNAME=${{ secrets.NOTIFICATION_MYSQL_DB_USERNAME }} \
--build-arg MEMBER_MONGO_DB_USERNAME=${{ secrets.MEMBER_MONGO_DB_USERNAME }} \
--build-arg MEMBER_MONGO_DB_PORT=${{ secrets.MEMBER_MONGO_DB_PORT }} \
--build-arg MEMBER_MONGO_DB_DATABASE=${{ secrets.MEMBER_MONGO_DB_DATABASE }} \
--build-arg RESUME_MONGO_DB_USERNAME=${{ secrets.RESUME_MONGO_DB_USERNAME }} \
--build-arg RESUME_MONGO_DB_PORT=${{ secrets.RESUME_MONGO_DB_PORT }} \
--build-arg RESUME_MONGO_DB_DATABASE=${{ secrets.RESUME_MONGO_DB_DATABASE }} \
--build-arg CHAT_MONGO_DB_USERNAME=${{ secrets.CHAT_MONGO_DB_USERNAME }} \
--build-arg CHAT_MONGO_DB_PORT=${{ secrets.CHAT_MONGO_DB_PORT }} \
--build-arg CHAT_MONGO_DB_DATABASE=${{ secrets.CHAT_MONGO_DB_DATABASE }} \
--build-arg S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }} \
--build-arg S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }} \
--build-arg S3_URL_PREFIX=${{ secrets.S3_URL_PREFIX }} \
--build-arg KAKAO_API_URL=${{ secrets.KAKAO_API_URL }} \
--build-arg KAKAOPAY_SECRET_KEY=${{ secrets.KAKAOPAY_SECRET_KEY }} \
--build-arg KAFKA_HOST1=${{ secrets.KAFKA_HOST1 }} \
--build-arg KAFKA_PORT1=${{ secrets.KAFKA_PORT1 }} \
-f ${{ matrix.dockerfile_path }} \
-t ${{ matrix.image_name }} \
${{ matrix.build_context }}
- name: Push the Docker image
run: |
docker push ${{ matrix.image_name }}
- name: Get EC2 Instance IDs
id: get_instances
run: |
FILTERS=$(echo "${{ matrix.ec2_filters }}" | tr '\n' ' ' | sed 's/\(Name=[^ ]*\)/"\1"/g')
INSTANCE_IDS=$(aws ec2 describe-instances \
--region ap-northeast-2 \
--filters $FILTERS \
--query 'Reservations[].Instances[].InstanceId' \
--output text)
echo "INSTANCE_IDS=$INSTANCE_IDS"
echo "instance_ids=$INSTANCE_IDS" >> $GITHUB_OUTPUT
- name: Deploy to EC2 instances
run: |
if [ -z "${{ steps.get_instances.outputs.instance_ids }}" ]; then
echo "No instance IDs found for ${{ matrix.module }} module. Exiting."
exit 1
fi
aws ssm send-command \
--instance-ids "${{ steps.get_instances.outputs.instance_ids }}" \
--document-name "AWS-RunShellScript" \
--comment "Deploying ${{ matrix.module }} module" \
--parameters commands='cd /home/ec2-user && docker-compose down -v --rmi all && docker-compose pull && docker-compose up -d' \
--timeout-seconds 600 \
--region ap-northeast-2
- name: Wait for command to complete
run: |
echo "Deployment command sent for ${{ matrix.module }} module."