Skip to content

Commit 07de673

Browse files
authored
[Feature] cd 구성 GitHub actions로 마이그레이션 (#272)
* fix: full text search 와일드 카드 위치 조정 * style: 코드 줄바꿈으로 가독성 개선 * refactor: github token 통일 * feat: 생성된 docker image 변수화 * feat: AWS EC2 SSH 접속 및 배포 * feat: GitHub Actions Runner의 Public IP 확인 * feat: GitHub Actions Runner의 Public IP를 SSH 인바운드에 추가 * feat: GitHub Actions Runner의 Public IP를 SSH 인바운드에서 삭제 * feat: deploy job의 동시 실행 제어 * feat: GitHub Actions Runner의 IP를 인바운드에서 반드시 삭제
1 parent bd38fa1 commit 07de673

3 files changed

Lines changed: 69 additions & 14 deletions

File tree

.github/workflows/docker-build-develop.yaml

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: develop 브랜치 도커 이미지 생성
1+
name: develop 브랜치 Docker Build & 무중단 배포
22

33
on:
44
push:
@@ -8,6 +8,8 @@ on:
88
jobs:
99
build:
1010
runs-on: ubuntu-latest
11+
outputs:
12+
docker_image: ${{ steps.docker.outputs.docker_image }}
1113

1214
steps:
1315
- name: 리포지토리 체크아웃
@@ -38,14 +40,15 @@ jobs:
3840

3941
- name: GitHub Container Registry 로그인
4042
run: |
41-
export CR_PAT=${{ secrets.SIGNAL_BUDDY_TOKEN }}
43+
export CR_PAT=${{ secrets.GIT_TOKEN }}
4244
echo $CR_PAT | docker login ghcr.io -u ${{ secrets.GIT_ID }} --password-stdin
4345
44-
4546
- name: 도커 이미지 생성
47+
id: docker
4648
run: |
4749
TAG=$(git rev-parse --short HEAD)
4850
DOCKER_IMAGE=${{ secrets.DOCKER_REGISTRY }}/signal-buddy:$TAG
51+
echo "docker_image=$DOCKER_IMAGE" >> "$GITHUB_OUTPUT"
4952
docker build -t test -f submodule/docker/dev.Dockerfile .
5053
docker tag test $DOCKER_IMAGE
5154
docker push $DOCKER_IMAGE
@@ -61,4 +64,49 @@ jobs:
6164
env:
6265
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
6366
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
64-
run: ./gradlew sonar --info --stacktrace
67+
run: ./gradlew sonar --info --stacktrace
68+
69+
deploy:
70+
runs-on: ubuntu-latest
71+
needs: build
72+
73+
concurrency:
74+
group: deploy
75+
cancel-in-progress: true # 기존 실행 중인 워크플로우는 취소, 새 커밋 기준으로 실행
76+
77+
steps:
78+
- name: GitHub Actions Runner의 Public IP 가져오기
79+
id: ip
80+
uses: haythem/public-ip@v1
81+
82+
- name: AWS credentials 설정
83+
uses: aws-actions/configure-aws-credentials@v4
84+
with:
85+
aws-access-key-id: ${{ secrets.AWS_IAM_ACCESS_KEY_ID }}
86+
aws-secret-access-key: ${{ secrets.AWS_IAM_SECRET_ACCESS_KEY }}
87+
aws-region: ${{ secrets.AWS_REGION }}
88+
89+
- name: GitHub Actions IP를 인바운드 룰에 임시 추가
90+
run: |
91+
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SECURITY_GROUP_ID }} \
92+
--protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
93+
94+
- name: AWS EC2 SSH 접속 및 배포
95+
uses: appleboy/ssh-action@v1
96+
with:
97+
host: ${{ secrets.EC2_HOST }}
98+
username: ${{ secrets.EC2_USERNAME }}
99+
key: ${{ secrets.EC2_SSH_KEY }}
100+
script: |
101+
set -e
102+
echo ${{ secrets.GIT_TOKEN }} | docker login ghcr.io -u ${{ secrets.GIT_ID }} --password-stdin
103+
docker pull ${{ needs.build.outputs.docker_image }}
104+
echo 'DOCKER_IMAGE=${{ needs.build.outputs.docker_image }}' > ${{ secrets.SUBMODULE_DIRECTORY }}/docker/.env
105+
sudo sh ${{ secrets.SUBMODULE_DIRECTORY }}/script/deploy.sh
106+
docker system prune -a -f || true
107+
108+
- name: GitHub Actions Runner의 IP를 인바운드에서 삭제
109+
if: always()
110+
run: |
111+
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SECURITY_GROUP_ID }} \
112+
--protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32

.github/workflows/docker-build-main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
- name: GitHub Container Registry 로그인
4040
run: |
41-
export CR_PAT=${{ secrets.SIGNAL_BUDDY_TOKEN }}
41+
export CR_PAT=${{ secrets.GIT_TOKEN }}
4242
echo $CR_PAT | docker login ghcr.io -u ${{ secrets.GIT_ID }} --password-stdin
4343
4444

src/main/java/org/programmers/signalbuddyfinal/global/util/QueryDslUtils.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ public final class QueryDslUtils {
3131
* @param endDate 조회하려는 끝 날짜 (null이면 없는 것으로 처리)
3232
* @return 시작 날짜 ~ 끝 날짜 범위를 조건으로 설정하여 반환 (둘 다 null이면 전체 조회)
3333
*/
34-
public static BooleanExpression betweenDates(DateTimePath<LocalDateTime> path,
35-
LocalDate startDate, LocalDate endDate) {
34+
public static BooleanExpression betweenDates(
35+
DateTimePath<LocalDateTime> path,
36+
LocalDate startDate, LocalDate endDate
37+
) {
3638
BooleanExpression predicate = null;
3739

3840
if (startDate != null) {
@@ -57,8 +59,11 @@ public static BooleanExpression betweenDates(DateTimePath<LocalDateTime> path,
5759
* @throws org.springframework.dao.InvalidDataAccessApiUsageException 잘못된 필드명을 입력하면 쿼리를 처리하는 중
5860
* 해당 예외가 발생한다.
5961
*/
60-
public static OrderSpecifier<?>[] getOrderSpecifiers(Pageable pageable, Class<?> type,
61-
String variable) {
62+
public static OrderSpecifier<?>[] getOrderSpecifiers(
63+
Pageable pageable,
64+
Class<?> type,
65+
String variable
66+
) {
6267
List<OrderSpecifier<?>> orderSpecifiers = new ArrayList<>();
6368

6469
// 정렬 조건이 없는 경우
@@ -76,8 +81,7 @@ public static OrderSpecifier<?>[] getOrderSpecifiers(Pageable pageable, Class<?>
7681
}
7782

7883
@SuppressWarnings("unchecked")
79-
OrderSpecifier<?>[] results = orderSpecifiers.toArray(
80-
new OrderSpecifier<?>[0]);
84+
OrderSpecifier<?>[] results = orderSpecifiers.toArray(new OrderSpecifier<?>[0]);
8185
return results;
8286
}
8387

@@ -89,12 +93,15 @@ public static OrderSpecifier<?>[] getOrderSpecifiers(Pageable pageable, Class<?>
8993
* @param target2 타켓 컬럼 2
9094
* @return QueryDSL에서 Where의 조건으로 사용
9195
*/
92-
public static BooleanExpression fulltextSearch(String keyword, StringPath target1, StringPath target2) {
96+
public static BooleanExpression fulltextSearch(
97+
String keyword,
98+
StringPath target1, StringPath target2
99+
) {
93100
if (keyword == null || keyword.isBlank()) {
94101
return Expressions.TRUE;
95102
}
96103

97-
String formattedSearchWord = "\"" + keyword + "\"";
104+
String formattedSearchWord = keyword + "*";
98105
return numberTemplate(
99106
Double.class, "function('match2_against', {0}, {1}, {2})",
100107
target1, target2, formattedSearchWord
@@ -113,7 +120,7 @@ public static BooleanExpression fulltextSearch(String keyword, StringPath target
113120
return Expressions.TRUE;
114121
}
115122

116-
String formattedSearchWord = "\"" + keyword + "\"";
123+
String formattedSearchWord = keyword + "*";
117124
return numberTemplate(
118125
Double.class, "function('match_against', {0}, {1})",
119126
target, formattedSearchWord

0 commit comments

Comments
 (0)