Skip to content

Commit 3a8e9b7

Browse files
authored
Merge pull request #2 from UnionMate/feat/#1
Feat/#1 CI/CD 구축 및 Netflix Eureka 서버 설정
2 parents 0128061 + 8b3bab0 commit 3a8e9b7

11 files changed

Lines changed: 165 additions & 1 deletion

File tree

.github/workflows/cd-dev.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: discovery-service dev CD 파이프라인
2+
3+
on:
4+
workflow_run:
5+
workflows: ["discovery-service CI pipeline"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
deploy:
11+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
12+
runs-on: ubuntu-latest
13+
environment: dev
14+
permissions:
15+
contents: read
16+
17+
steps:
18+
- name: Docker 이미지 dev 서버 배포
19+
uses: appleboy/ssh-action@master
20+
with:
21+
host: ${{secrets.DEV_HOST}}
22+
username: ${{secrets.DEV_USERNAME}}
23+
key: ${{secrets.DEV_KEY}}
24+
script: |
25+
cd /home/ubuntu
26+
docker rm -f discovery-service-dev || true
27+
docker compose pull discovery-service-dev
28+
docker compose up -d --no-deps --force-recreate --pull always discovery-service-dev
29+
docker image prune -f

.github/workflows/cd-prod.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: discovery-service prod CD 파이프라인
2+
3+
on:
4+
workflow_run:
5+
workflows: ["discovery-service CI pipeline"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
deploy:
11+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
12+
runs-on: ubuntu-latest
13+
environment: prod
14+
permissions:
15+
contents: read
16+
17+
steps:
18+
- name: Docker 이미지 dev 서버 배포
19+
uses: appleboy/ssh-action@master
20+
with:
21+
host: ${{secrets.PROD_HOST}}
22+
username: ${{secrets.PROD_USERNAME}}
23+
key: ${{secrets.PROD_KEY}}
24+
script: |
25+
cd /home/ubuntu
26+
docker rm -f discovery-service-prod || true
27+
docker compose pull discovery-service-prod
28+
docker compose up -d --no-deps --force-recreate --pull always discovery-service-prod
29+
docker image prune -f

.github/workflows/ci.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: discovery-service CI pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
pull_request:
8+
branches:
9+
- dev
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
environment: production
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: jdk 설정
22+
uses: actions/setup-java@v4
23+
with:
24+
distribution: 'temurin'
25+
java-version: '21'
26+
cache: 'gradle'
27+
28+
- name: Gradle Wrapper 권한 부여
29+
run: chmod +x gradlew
30+
31+
- name: gradle 빌드
32+
run: ./gradlew clean build
33+
34+
- name: 도커 로그인
35+
uses: docker/login-action@v3
36+
with:
37+
username: ${{ secrets.DOCKER_USERNAME }}
38+
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
39+
40+
- name: 이미지 빌드 및 푸시
41+
uses: docker/build-push-action@v5
42+
with:
43+
context: .
44+
file: ./Dockerfile
45+
tags: ${{ secrets.DOCKER_USERNAME }}/unionmate-discovery-service:latest
46+
push: true

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM openjdk:21-jdk
2+
3+
COPY build/libs/*SNAPSHOT.jar app.jar
4+
5+
ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -Dspring.profiles.active=${PROFILE} -jar /app.jar"]

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ dependencyManagement {
3737

3838
tasks.named('test') {
3939
useJUnitPlatform()
40+
systemProperty "spring.profiles.active", "test"
4041
}

src/main/java/com/unionmate/discovery_service/DiscoveryServiceApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
56

67
@SpringBootApplication
8+
@EnableEurekaServer
79
public class DiscoveryServiceApplication {
810

911
public static void main(String[] args) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server:
2+
port: 8761
3+
4+
spring:
5+
application:
6+
name: discovery-service-dev
7+
8+
eureka:
9+
client:
10+
register-with-eureka: false
11+
fetch-registry: false
12+
13+
server:
14+
wait-time-in-ms-when-sync-empty: 0 # 초기 레지스트리 정보가 비어 있어도 지연 없이 즉시 서버 시작
15+
response-cache-update-interval-ms: 30000 # 클라이언트에게 제공할 서비스 목록 캐시를 30초마다 갱신
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server:
2+
port: 8761
3+
4+
spring:
5+
application:
6+
name: discovery-service
7+
8+
eureka:
9+
client:
10+
register-with-eureka: false
11+
fetch-registry: false
12+
13+
server:
14+
wait-time-in-ms-when-sync-empty: 0 # 초기 레지스트리 정보가 비어 있어도 지연 없이 즉시 서버 시작
15+
response-cache-update-interval-ms: 30000 # 클라이언트에게 제공할 서비스 목록 캐시를 30초마다 갱신
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server:
2+
port: 8761
3+
4+
spring:
5+
application:
6+
name: discovery-service-prod
7+
8+
eureka:
9+
client:
10+
register-with-eureka: false
11+
fetch-registry: false
12+
13+
server:
14+
wait-time-in-ms-when-sync-empty: 0 # 초기 레지스트리 정보가 비어 있어도 지연 없이 즉시 서버 시작
15+
response-cache-update-interval-ms: 30000 # 클라이언트에게 제공할 서비스 목록 캐시를 30초마다 갱신

src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)