Skip to content

Commit 2d74aa8

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

3 files changed

Lines changed: 132 additions & 101 deletions

File tree

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,85 @@
1-
#name: Product 서비스 ECS에 배포
2-
#on:
3-
# push:
4-
# branches: [ main ]
5-
# paths:
6-
# - "product-service/**"
7-
#
8-
#env:
9-
# AWS_REGION: ap-northeast-2
10-
# ECR_REPOSITORY: product-service
11-
# ECS_CLUSTER: msa-cluster
12-
# ECS_SERVICE: product-service-task-service-gzt0voxw
13-
# CONTAINER_NAME: product-service
14-
#
15-
#jobs:
16-
# Deploy-product-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 :product-service:clean
45-
# ./gradlew :product-service:build
46-
#
47-
# - name: 빌드파일로 도커 이미지 빌드
48-
# run: |
49-
# docker build -t ${{ env.ECR_REPOSITORY }} ./product-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 GIT_USERNAME=${{ secrets.GIT_USERNAME }}
61-
# export GIT_TOKEN=${{ secrets.GIT_TOKEN }}
62-
# export IMAGE_URI=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:latest
63-
# envsubst < ecs/taskdef-product-template.json > ecs/taskdef-product.json
64-
#
65-
# - name: taskdef-product.json 존재 확인
66-
# run: cat ecs/taskdef-product.json
67-
#
68-
# - name: 태스크 정의 등록
69-
# id: register-task
70-
# run: |
71-
# arn=$(aws ecs register-task-definition \
72-
# --cli-input-json file://ecs/taskdef-product.json \
73-
# --query 'taskDefinition.taskDefinitionArn' \
74-
# --output text)
75-
# echo "task-definition-arn=$arn" >> $GITHUB_OUTPUT
76-
#
77-
# - name: 태스크 정의 ARN을 env 변수로 설정
78-
# run: echo "TASK_DEF_ARN=${{ steps.register-task.outputs.task-definition-arn }}" >> $GITHUB_ENV
79-
#
80-
# - name: ECS 서비스 배포
81-
# run: |
82-
# aws ecs update-service \
83-
# --cluster $ECS_CLUSTER \
84-
# --service $ECS_SERVICE \
85-
# --task-definition $TASK_DEF_ARN
1+
name: Product 서비스 ECS에 배포
2+
on:
3+
push:
4+
branches: [main]
5+
paths:
6+
- "product-service/**"
7+
8+
env:
9+
AWS_REGION: ap-northeast-2
10+
ECR_REPOSITORY: product-service
11+
ECS_CLUSTER: msa-cluster
12+
ECS_SERVICE: product-service-task-service-gzt0voxw
13+
CONTAINER_NAME: product-service
14+
15+
jobs:
16+
Deploy-product-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 :product-service:clean
45+
./gradlew :product-service:build
46+
47+
- name: 빌드파일로 도커 이미지 빌드
48+
run: |
49+
docker build -t ${{ env.ECR_REPOSITORY }} ./product-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 GIT_USERNAME=${{ secrets.GIT_USERNAME }}
61+
export GIT_TOKEN=${{ secrets.GIT_TOKEN }}
62+
export IMAGE_URI=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:latest
63+
envsubst < ecs/taskdef-product-template.json > ecs/taskdef-product.json
64+
65+
- name: taskdef-product.json 존재 확인
66+
run: cat ecs/taskdef-product.json
67+
68+
- name: 태스크 정의 등록
69+
id: register-task
70+
run: |
71+
arn=$(aws ecs register-task-definition \
72+
--cli-input-json file://ecs/taskdef-product.json \
73+
--query 'taskDefinition.taskDefinitionArn' \
74+
--output text)
75+
echo "task-definition-arn=$arn" >> $GITHUB_OUTPUT
76+
77+
- name: 태스크 정의 ARN을 env 변수로 설정
78+
run: echo "TASK_DEF_ARN=${{ steps.register-task.outputs.task-definition-arn }}" >> $GITHUB_ENV
79+
80+
- name: ECS 서비스 배포
81+
run: |
82+
aws ecs update-service \
83+
--cluster $ECS_CLUSTER \
84+
--service $ECS_SERVICE \
85+
--task-definition $TASK_DEF_ARN

ecs/taskdef-product-template.json

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,43 @@
1212
"name": "product-service-task",
1313
"image": "${IMAGE_URI}",
1414
"essential": true,
15+
"cpu": 0,
1516
"portMappings": [
1617
{
1718
"containerPort": 8084,
1819
"hostPort": 8084,
19-
"protocol": "tcp"
20+
"protocol": "tcp",
21+
"name": "product-service-task-8084-tcp",
22+
"appProtocol": "http"
2023
},
2124
{
22-
"appProtocol": "grpc",
2325
"containerPort": 50051,
2426
"hostPort": 50051,
25-
"protocol": "tcp"
27+
"protocol": "tcp",
28+
"name": "product-service-task-50051-tcp",
29+
"appProtocol": "grpc"
2630
}
2731
],
2832
"environment": [
29-
{
30-
"name": "SPRING_PROFILES_ACTIVE",
31-
"value": "prod"
32-
},
33-
{
34-
"name": "SPRING_APPLICATION_NAME",
35-
"value": "product-service"
36-
}
33+
{ "name": "EUREKA_CLIENT_ENABLED", "value": "true" },
34+
{ "name": "GRPC_PORT", "value": "50051" },
35+
{ "name": "EUREKA_INSTANCE_HOSTNAME", "value": "product-service.hanium.local" },
36+
{ "name": "DB_PORT", "value": "3306" },
37+
{ "name": "SPRING_CONFIG_IMPORT", "value": "configserver:http://config-service.hanium.local:8888" },
38+
{ "name": "SPRING_PROFILES_ACTIVE", "value": "prod" },
39+
{ "name": "SPRING_APPLICATION_NAME", "value": "product-service" },
40+
{ "name": "SPRING_ELASTICSEARCH_URIS", "value": "http://10.0.142.27:9200" },
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/product-service-b6oExO:host::" },
46+
{ "name": "DB_NAME", "valueFrom": "arn:aws:secretsmanager:ap-northeast-2:826331271523:secret:prod/mysql/product-service-b6oExO:name::" },
47+
{ "name": "DB_PASSWORD", "valueFrom": "arn:aws:secretsmanager:ap-northeast-2:826331271523:secret:prod/mysql/product-service-b6oExO:password::" },
48+
{ "name": "DB_USER", "valueFrom": "arn:aws:secretsmanager:ap-northeast-2:826331271523:secret:prod/mysql/product-service-b6oExO:username::" }
3749
],
3850
"healthCheck": {
39-
"command": [
40-
"CMD-SHELL",
41-
"curl -f http://localhost:8084/actuator/health || exit 1"
42-
],
51+
"command": [ "CMD-SHELL", "curl -f http://localhost:8084/actuator/health || exit 1" ],
4352
"interval": 30,
4453
"retries": 3,
4554
"startPeriod": 120,
@@ -49,10 +58,32 @@
4958
"logDriver": "awslogs",
5059
"options": {
5160
"awslogs-group": "/ecs/product-service-task",
61+
"awslogs-create-group": "true",
5262
"awslogs-region": "ap-northeast-2",
5363
"awslogs-stream-prefix": "ecs"
5464
}
5565
}
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+
}
5687
}
5788
]
5889
}

product-service/src/main/java/hanium/product_service/service/impl/DeliveryServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void createWayBill(CreateWayBillRequestDTO dto){
4343
Delivery delivery = Delivery.of(trade, dto);
4444
deliveryRepository.save(delivery);
4545
tradeRepository.updateStatus(trade.getChatroom().getId(), TradeStatus.SHIPPED);
46-
log.info("✅ {} 거래 {} 송장 등록 성공", dto.getTradeId(), dto.getInvoiceNo());
46+
log.info("✅ {} 거래에 대한 {} 송장 등록 성공", dto.getTradeId(), dto.getInvoiceNo());
4747
}
4848

4949
@Override

0 commit comments

Comments
 (0)