Skip to content

Commit 84401c1

Browse files
committed
chore: test cicd with submodule
1 parent 8465ded commit 84401c1

2 files changed

Lines changed: 121 additions & 1 deletion

File tree

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Product Server Deploy to Amazon ECS
2+
3+
# release, develop 브랜치에 푸시되거나 PR이 닫힐 때마다 실행되는 워크플로우입니다.
4+
on:
5+
push:
6+
branches:
7+
- "release"
8+
- "develop"
9+
pull_request:
10+
types: [closed]
11+
branches:
12+
- "release"
13+
- "develop"
14+
15+
jobs:
16+
deploy:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout source code
20+
uses: actions/checkout@v3
21+
22+
# 1. JDK 17 세팅
23+
- name: Set up JDK 17
24+
uses: actions/setup-java@v3
25+
with:
26+
java-version: '17'
27+
distribution: 'temurin'
28+
29+
# 2. 환경변수(yml)가 있는 서브모듈 가져오기
30+
- name: Checkout
31+
uses: actions/checkout@v3
32+
with:
33+
token: ${{ secrets.ACTION_TOKEN }}
34+
submodules: true
35+
36+
# 3. Gradle 실행 권한 부여
37+
- name: Grant execute permission for Gradle
38+
run: chmod +x ./gradlew
39+
40+
# 4. Gradle로 빌드
41+
- name: Build with Gradle
42+
run: ./gradlew clean build
43+
44+
# 5. AWS 자격 증명 구성
45+
- name: Configure AWS credentials
46+
uses: aws-actions/configure-aws-credentials@v2
47+
with:
48+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
49+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
50+
aws-region: ap-northeast-2
51+
52+
# 6. Amazon ECR에 로그인
53+
- name: Login to Amazon ECR
54+
id: login-ecr
55+
uses: aws-actions/amazon-ecr-login@v2
56+
57+
# 7. Docker 이미지 빌드 및 태그, Amazon ECR에 이미지 푸시
58+
- name: Build Docker image and tag, push image to Amazon ECR - release
59+
if: github.ref == 'refs/heads/release'
60+
id: build-image-release
61+
run: |
62+
docker build --platform linux/amd64 -t ${{ secrets.ECR_REPO_NAME_PROD }} .
63+
docker tag ${{ secrets.ECR_REPO_NAME_PROD }}:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/${{ secrets.ECR_REPO_NAME_PROD }}:latest # 이미지를 ECR 리포지토리로 태깅합니다.
64+
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/${{ secrets.ECR_REPO_NAME_PROD }}:latest # 이미지를 ECR에 푸시합니다.
65+
echo "image=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/${{ secrets.ECR_REPO_NAME_PROD }}:latest" >> $GITHUB_OUTPUT
66+
67+
- name: Build Docker image and tag, push image to Amazon ECR - develop
68+
if: github.ref == 'refs/heads/develop'
69+
id: build-image-develop
70+
run: |
71+
docker build --platform linux/amd64 -t ${{ secrets.ECR_REPO_NAME_DEV }} .
72+
docker tag ${{ secrets.ECR_REPO_NAME_DEV }}:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/${{ secrets.ECR_REPO_NAME_DEV }}:latest # 이미지를 ECR 리포지토리로 태깅합니다.
73+
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/${{ secrets.ECR_REPO_NAME_DEV }}:latest # 이미지를 ECR에 푸시합니다.
74+
echo "image=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/${{ secrets.ECR_REPO_NAME_DEV }}:latest" >> $GITHUB_OUTPUT
75+
76+
# 8. Amazon ECS 태스크 정의에 새 이미지 ID 채우기
77+
- name: Fill in the new image ID in the Amazon ECS task definition - release
78+
if: github.ref == 'refs/heads/release'
79+
id: task-def-release
80+
uses: aws-actions/amazon-ecs-render-task-definition@v1
81+
with:
82+
task-definition: task-definition-prod.json
83+
container-name: ${{ secrets.ECS_CONTAINER_NAME_PROD }}
84+
image: ${{ steps.build-image-release.outputs.image }}
85+
86+
- name: Fill in the new image ID in the Amazon ECS task definition - release
87+
if: github.ref == 'refs/heads/develop'
88+
id: task-def-develop
89+
uses: aws-actions/amazon-ecs-render-task-definition@v1
90+
with:
91+
task-definition: task-definition-prod.json
92+
container-name: ${{ secrets.ECS_CONTAINER_NAME_DEV }}
93+
image: ${{ steps.build-image-develop.outputs.image }}
94+
95+
# 9. ECS에 배포
96+
- name: Deploy to ECS
97+
if: github.ref == 'refs/heads/release'
98+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
99+
with:
100+
task-definition: ${{ steps.task-def.outputs.task-definition }} # ECS 태스크 정의 파일을 지정합니다.
101+
service: ${{ secrets.ECS_SERVICE_NAME_PROD }}
102+
cluster: ${{ secrets.ECS_CLUSTER_NAME }}
103+
wait-for-service-stability: true # 서비스가 안정화될 때까지 대기합니다.
104+
105+
- name: Deploy to ECS
106+
if: github.ref == 'refs/heads/develop'
107+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
108+
with:
109+
task-definition: ${{ steps.task-def.outputs.task-definition }} # ECS 태스크 정의 파일을 지정합니다.
110+
service: ${{ secrets.ECS_SERVICE_NAME_DEV }}
111+
cluster: ${{ secrets.ECS_CLUSTER_NAME }}
112+
wait-for-service-stability: true # 서비스가 안정화될 때까지 대기합니다.
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
package bitnagil.bitnagil_backend;
22

3+
import org.springframework.beans.factory.annotation.Value;
34
import org.springframework.http.ResponseEntity;
45
import org.springframework.web.bind.annotation.GetMapping;
56
import org.springframework.web.bind.annotation.RestController;
67

78
@RestController
89
public class HealthCheckController {
910

11+
@Value("${spring.port}")
12+
private String port;
13+
14+
@Value("${spring.config.active.on-profile}")
15+
private String activeProfile;
16+
17+
1018
@GetMapping("/health-check")
1119
public ResponseEntity<String> health() {
12-
return ResponseEntity.ok("OK-과연...!");
20+
return ResponseEntity.ok("pot: " + port + ", active profile: " + activeProfile);
1321
}
1422
}

0 commit comments

Comments
 (0)