Skip to content

Commit 1c71edb

Browse files
author
gahyeon
committed
[infra/#97] : user-service CI/CD 파이프라인 구축
1 parent 2d74aa8 commit 1c71edb

3 files changed

Lines changed: 173 additions & 1 deletion

File tree

.github/workflows/deploy-user.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: User 서비스 ECS에 배포
2+
on:
3+
push:
4+
branches: [main]
5+
paths:
6+
- "user-service/**"
7+
8+
env:
9+
AWS_REGION: ap-northeast-2
10+
ECR_REPOSITORY: user-service
11+
ECS_CLUSTER: msa-cluster
12+
ECS_SERVICE: user-service-task-service-u806lsfc
13+
CONTAINER_NAME: user-service
14+
15+
jobs:
16+
Deploy-user-service:
17+
runs-on: ubuntu-latest
18+
steps:
19+
20+
- name: Github Actions ci 환경에 레포지토리 코드 받아오기
21+
uses: actions/checkout@v4
22+
23+
- name: AWS 인증
24+
uses: aws-actions/configure-aws-credentials@v4
25+
with:
26+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
27+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
28+
aws-region: ${{ env.AWS_REGION }}
29+
30+
- name: AWS ECR 로그인
31+
run: |
32+
aws ecr get-login-password | docker login --username AWS --password-stdin \
33+
${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com
34+
35+
- name: JDK 21 설치
36+
uses: actions/setup-java@v3
37+
with:
38+
java-version: '21'
39+
distribution: 'temurin'
40+
41+
- name: 프로젝트 빌드
42+
run: |
43+
chmod +x gradlew
44+
./gradlew :user-service:clean
45+
./gradlew :user-service:build
46+
47+
- name: 빌드파일로 도커 이미지 빌드
48+
run: |
49+
docker build -t ${{ env.ECR_REPOSITORY }} ./user-service
50+
docker tag ${{ env.ECR_REPOSITORY }}:latest \
51+
${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:latest
52+
53+
- name: ECR에 도커 이미지 푸시
54+
run: |
55+
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:latest
56+
57+
- name: ECS 태스크 정의에 환경변수 설정
58+
run: |
59+
sudo apt-get update && sudo apt-get install -y gettext
60+
export IMAGE_URI=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:latest
61+
envsubst < ecs/taskdef-user-template.json > ecs/taskdef-user.json
62+
63+
- name: taskdef-user.json 존재 확인
64+
run: cat ecs/taskdef-user.json
65+
66+
- name: 태스크 정의 등록
67+
id: register-task
68+
run: |
69+
arn=$(aws ecs register-task-definition \
70+
--cli-input-json file://ecs/taskdef-user.json \
71+
--query 'taskDefinition.taskDefinitionArn' \
72+
--output text)
73+
echo "task-definition-arn=$arn" >> $GITHUB_OUTPUT
74+
75+
- name: 태스크 정의 ARN을 env 변수로 설정
76+
run: echo "TASK_DEF_ARN=${{ steps.register-task.outputs.task-definition-arn }}" >> $GITHUB_ENV
77+
78+
- name: ECS 서비스 배포
79+
run: |
80+
aws ecs update-service \
81+
--cluster $ECS_CLUSTER \
82+
--service $ECS_SERVICE \
83+
--task-definition $TASK_DEF_ARN

ecs/taskdef-user-template.json

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"family": "user-service-task",
3+
"executionRoleArn": "arn:aws:iam::826331271523:role/ecsTaskExecutionRole",
4+
"taskRoleArn": "arn:aws:iam::826331271523:role/ecsUserServiceRole",
5+
"networkMode": "awsvpc",
6+
"requiresCompatibilities": [
7+
"FARGATE"
8+
],
9+
"cpu": "1024",
10+
"memory": "3072",
11+
"containerDefinitions": [
12+
{
13+
"name": "user-service-task",
14+
"image": "${IMAGE_URI}",
15+
"essential": true,
16+
"cpu": 0,
17+
"portMappings": [
18+
{
19+
"containerPort": 50051,
20+
"hostPort": 50051,
21+
"protocol": "tcp",
22+
"name": "user-service-50051-tcp",
23+
"appProtocol": "grpc"
24+
},
25+
{
26+
"containerPort": 8081,
27+
"hostPort": 8081,
28+
"protocol": "tcp",
29+
"name": "user-service-8081-tcp",
30+
"appProtocol": "http"
31+
}
32+
],
33+
"environment": [
34+
{ "name": "EUREKA_CLIENT_ENABLED", "value": "true" },
35+
{ "name": "GRPC_PORT", "value": "50051" },
36+
{ "name": "EUREKA_INSTANCE_HOSTNAME", "value": "user-service.hanium.local" },
37+
{ "name": "DB_PORT", "value": "3306" },
38+
{ "name": "SPRING_CONFIG_IMPORT", "value": "configserver:http://config-service.hanium.local:8888" },
39+
{ "name": "SPRING_PROFILES_ACTIVE", "value": "prod" },
40+
{ "name": "SPRING_APPLICATION_NAME", "value": "user-service" },
41+
{ "name": "ZIPKIN_ENDPOINT", "value": "http://zipkin-service.hanium.local:9411/api/v2/spans" },
42+
{ "name": "EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE", "value": "http://discovery-service.hanium.local:8761/eureka" }
43+
],
44+
"secrets": [
45+
{ "name": "DB_HOST", "valueFrom": "arn:aws:secretsmanager:ap-northeast-2:826331271523:secret:prod/mysql/user-service-GfKyQU:host::" },
46+
{ "name": "DB_NAME", "valueFrom": "arn:aws:secretsmanager:ap-northeast-2:826331271523:secret:prod/mysql/user-service-GfKyQU:name::" },
47+
{ "name": "DB_PASSWORD", "valueFrom": "arn:aws:secretsmanager:ap-northeast-2:826331271523:secret:prod/mysql/user-service-GfKyQU:password::" },
48+
{ "name": "DB_USER", "valueFrom": "arn:aws:secretsmanager:ap-northeast-2:826331271523:secret:prod/mysql/user-service-GfKyQU:username::" }
49+
],
50+
"healthCheck": {
51+
"command": [ "CMD-SHELL", "curl -f http://localhost:8081/actuator/health || exit 1" ],
52+
"interval": 30,
53+
"retries": 3,
54+
"startPeriod": 120,
55+
"timeout": 5
56+
},
57+
"logConfiguration": {
58+
"logDriver": "awslogs",
59+
"options": {
60+
"awslogs-group": "/ecs/user-service-task",
61+
"awslogs-create-group": "true",
62+
"awslogs-region": "ap-northeast-2",
63+
"awslogs-stream-prefix": "ecs"
64+
}
65+
}
66+
},
67+
{
68+
"name": "redis",
69+
"image": "redis:7-alpine",
70+
"essential": false,
71+
"cpu": 0,
72+
"portMappings": [
73+
{
74+
"containerPort": 6379,
75+
"hostPort": 6379,
76+
"protocol": "tcp",
77+
"name": "redis-6379-tcp"
78+
}
79+
],
80+
"healthCheck": {
81+
"command": [ "CMD-SHELL", "redis-cli ping | grep PONG || exit 1" ],
82+
"interval": 5,
83+
"timeout": 3,
84+
"retries": 5,
85+
"startPeriod": 5
86+
}
87+
}
88+
]
89+
}

user-service/src/main/java/hanium/user_service/service/impl/AuthServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public Member signUp(SignUpRequestDTO dto) {
6161
memberRepository.save(member);
6262
profileRepository.save(profile);
6363

64-
log.info("✅ [회원가입 완료] Profile id={} for Member id={}", profile.getId(), member.getId());
64+
log.info("✅ [회원가입 완료]: Profile id={} for Member id={}", profile.getId(), member.getId());
6565

6666
return member;
6767
}

0 commit comments

Comments
 (0)