Skip to content

Commit 87cf6d9

Browse files
authored
infra: CI/CD 파이프라인 구축
* feat: Dockerfile 작성 - 경량화 된 베이스 이미지 사용으로 이미지 용량 최적화 - 멀티 스테이지 빌드 수행 * chore: datasource 연결 정보 분리 - 환경 변수로 값 주입되도록 구현 * chore: 테스트 환경 h2 DB 의존성 추가 * infra: CI/CD workflow 작성 * infra: CI workflow 작성 - 코드 통합 이전에 오류 검출을 위함
1 parent 786f661 commit 87cf6d9

File tree

6 files changed

+102
-9
lines changed

6 files changed

+102
-9
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: [ "dev" ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/[email protected]
13+
14+
- name: Set up JDK 21
15+
uses: actions/[email protected]
16+
with:
17+
distribution: 'temurin'
18+
java-version: '21'
19+
cache: gradle
20+
21+
- name: Grant execute permission for gradlew
22+
run: chmod +x gradlew
23+
24+
- name: Build with Gradle
25+
run: ./gradlew clean build

.github/workflows/cicd.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: [ "dev" ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/[email protected]
13+
14+
- name: Log in to Docker Hub
15+
uses: docker/[email protected]
16+
with:
17+
username: ${{ secrets.DOCKER_USERNAME }}
18+
password: ${{ secrets.DOCKER_PASSWORD }}
19+
20+
- name: Build and Push Docker image
21+
if: github.ref == 'refs/heads/dev'
22+
uses: docker/[email protected]
23+
with:
24+
context: .
25+
file: ./Dockerfile
26+
push: true
27+
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROD_IMAGE_NAME }}:latest
28+
platforms: linux/amd64
29+
30+
deploy:
31+
runs-on: ubuntu-latest
32+
needs: build
33+
34+
steps:
35+
- name: SSH to Server and Deploy
36+
if: github.ref == 'refs/heads/dev'
37+
uses: appleboy/[email protected]
38+
with:
39+
host: ${{ secrets.PROD_SERVER_HOST }}
40+
port: ${{ secrets.PROD_SERVER_PORT }}
41+
username: ${{ secrets.PROD_SERVER_USERNAME }}
42+
key: ${{ secrets.PROD_SERVER_KEY }}
43+
script: |
44+
cd /home/ubuntu/dasom
45+
mkdir -p ./env
46+
echo "${{ secrets.ENV }}" > ./env/prodEnv
47+
./deploy.sh

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM gradle:8.12.1-jdk21-alpine AS build
2+
WORKDIR /home/gradle/project
3+
4+
COPY build.gradle settings.gradle ./
5+
COPY gradle gradle/
6+
7+
COPY src src
8+
9+
RUN gradle clean build
10+
11+
FROM eclipse-temurin:21-jre-alpine
12+
WORKDIR /app
13+
14+
COPY --from=build /home/gradle/project/build/libs/dmu-dasom-api.jar api.jar
15+
16+
ENTRYPOINT ["java", "-Dspring.profiles.active=default,credentials", "-jar", "api.jar"]

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ dependencies {
4444
developmentOnly 'org.springframework.boot:spring-boot-devtools'
4545
runtimeOnly 'com.oracle.database.jdbc:ojdbc11'
4646
annotationProcessor 'org.projectlombok:lombok'
47+
testImplementation 'com.h2database:h2'
4748
testImplementation 'org.springframework.boot:spring-boot-starter-test'
4849
testImplementation 'org.springframework.security:spring-security-test'
4950
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
spring:
2+
datasource:
3+
url: ${DB_URL}
4+
driver-class-name: oracle.jdbc.OracleDriver
5+
username: ${DB_USERNAME}
6+
password: ${DB_PASSWORD}
7+
jpa:
8+
hibernate:
9+
ddl-auto: ${DDL_AUTO}
10+
show-sql: ${SHOW_SQL}
11+
properties:
12+
hibernate:
13+
dialect: org.hibernate.dialect.OracleDialect

src/main/resources/application.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,3 @@ server:
33
spring:
44
application:
55
name: dasom-api
6-
datasource:
7-
url: ${DB_URL}
8-
driver-class-name: oracle.jdbc.OracleDriver
9-
username: ${DB_USERNAME}
10-
password: ${DB_PASSWORD}
11-
jpa:
12-
hibernate:
13-
ddl-auto: update
14-
show-sql: true

0 commit comments

Comments
 (0)