Skip to content

Commit c06797b

Browse files
authored
Merge pull request #34 from KB-Hackerton/feature/13
CI/CD 구축 완료!! Develop에 머지시 자동 배포
2 parents 46d70c5 + 5718c18 commit c06797b

File tree

5 files changed

+105
-2
lines changed

5 files changed

+105
-2
lines changed

.github/workflows/CI-CD.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: CI-CD.yml
2+
on:
3+
push:
4+
branches: ["develop"]
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: 📢 깃허브 checkout!!!!!
11+
uses: actions/checkout@v3
12+
13+
- name: 📢 GitHubAction JDK 17 설치
14+
uses: actions/setup-java@v3
15+
with:
16+
java-version: '17'
17+
distribution: 'temurin'
18+
19+
- name: 📢 Gradle 실행 권한 부여
20+
run: chmod +x gradlew
21+
22+
- name: 📢 Gradle 캐싱
23+
uses: actions/cache@v3
24+
with:
25+
path: |
26+
~/.gradle/caches
27+
~/.gradle/wrapper
28+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
29+
restore-keys: |
30+
${{ runner.os }}-gradle-
31+
32+
- name: 📢 GitIgnore 파일들 넣어주기
33+
env:
34+
APPLICATION_PROPERTIES: ${{ secrets.APPLICATION_PROPERTIES}}
35+
run: |
36+
rm -f src/main/resources/application.properties
37+
echo "${{ secrets.APPLICATION_PROPERTIES }}" > src/main/resources/application.properties
38+
39+
- name: 📢 Gradle 빌드(jar 만들기)
40+
run: ./gradlew clean bootJar -x test
41+
42+
- name: 📢 Docker image 만들기
43+
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/hackerton .
44+
45+
- name: 📢 DockerHub에 로그인
46+
uses: docker/login-action@v2
47+
with:
48+
username: ${{ secrets.DOCKERHUB_USERNAME}}
49+
password: ${{ secrets.DOCKERHUB_PASSWORD}}
50+
51+
- name: 📢 DockerHub에 PUSH
52+
run: docker push ${{ secrets.DOCKERHUB_USERNAME}}/hackerton
53+
54+
deploy:
55+
runs-on: ubuntu-latest
56+
needs: build
57+
if: github.event_name == 'push'
58+
steps:
59+
- name: 📢SSH로 EC2에 접속해보자
60+
uses: appleboy/ssh-action@master
61+
with:
62+
host: ${{ secrets.EC2_HOST}}
63+
username: ${{ secrets.EC2_USERNAME}}
64+
key: ${{ secrets.EC2_PRIVATE_KEY}}
65+
proxy_host: ${{ secrets.SSH_TUN_HOST }} # 퍼블릭 IP를 가진 중간 서버
66+
proxy_username: ${{ secrets.SSH_USER }} # 터널링 서버의 사용자
67+
proxy_key: ${{ secrets.SSH_PEM_KEY }}
68+
port: 22
69+
script: |
70+
echo "✅ EC2 연결 성공!"
71+
echo "✅ Docker를 실행 시키기 위해 compose.yml 파일로 고고띠"
72+
cd ~/hackerton
73+
74+
echo "✅ DockerHub 에서 이미지 가져오기(pull)"
75+
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/hackerton
76+
77+
echo "✅ 이제 DockeCompose 돌리자!!"
78+
docker compose down
79+
docker compose up -d
80+
81+
echo "✅ PortForwarding을 8080으로 했으니깐 Public IP의 8080포트로 가자 "
82+
echo "✅ 배포 완료"

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM openjdk:17-jdk
2+
COPY build/libs/*SNAPSHOT.jar app.jar
3+
ENTRYPOINT ["java","-jar","/app.jar"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package kb_hack.backend.domain.health.controller;
2+
3+
import kb_hack.backend.global.common.exception.enums.SuccessStatusCode;
4+
import kb_hack.backend.global.common.response.success.SuccessResponse;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.http.ResponseEntity;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
@RestController
12+
@RequestMapping("/check")
13+
@RequiredArgsConstructor
14+
public class HealthCheckController {
15+
@GetMapping("")
16+
public SuccessResponse<Void> test() { return SuccessResponse.makeResponse(SuccessStatusCode.HEALTH_CHECK_SUCCESS); }
17+
}

src/main/java/kb_hack/backend/global/common/exception/enums/SuccessStatusCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public enum SuccessStatusCode {
1212
LOGIN_SUCCESS(HttpStatus.OK,"로그인 성공!"),
1313
EMAIL_SEND_SUCCESS(HttpStatus.OK,"이메일 발송 성공!"),
1414
SIGNUP_SUCCESS(HttpStatus.CREATED,"회원 가입 성공!"),
15-
CRAWL_ARTICLE_SUCCESS(HttpStatus.OK,"공고 크롤링 성공!");
15+
CRAWL_ARTICLE_SUCCESS(HttpStatus.OK,"공고 크롤링 성공!"),
16+
HEALTH_CHECK_SUCCESS(HttpStatus.OK,"서버가 정상 작동 중입니다!");
1617

1718
private final HttpStatus httpStatus;
1819
private final String message;

src/main/java/kb_hack/backend/global/security/config/SecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public SecurityFilterChain filterChain (HttpSecurity http, JwtUsernamePasswordAu
7474
.authorizeHttpRequests((auth)-> auth
7575
.requestMatchers("/assets/**", "/favicon.ico", "/swagger-resources/**", "/swagger-ui.html", "/swagger-ui/**",
7676
"/v2/api-docs", "/v3/api-docs", "/webjars/**", "/swagger/**").permitAll()
77-
.requestMatchers("/", "/index.html","/swagger","/auth/login","/auth/refresh","/auth/password").permitAll()
77+
.requestMatchers("/", "/index.html","/swagger","/auth/login","/auth/refresh","/auth/password","/check").permitAll()
7878
.requestMatchers(HttpMethod.POST, "/auth/member-info").permitAll()
7979
.requestMatchers("/test").hasRole("Member")
8080
.requestMatchers("/crawl/admin").hasRole("Admin")

0 commit comments

Comments
 (0)