Skip to content

Commit 9ef011a

Browse files
committed
chore : cicd 설정
1 parent c5b71ab commit 9ef011a

File tree

4 files changed

+89
-6
lines changed

4 files changed

+89
-6
lines changed

.github/workflows/deploy.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- feature/issue-4
8+
9+
jobs:
10+
CI-CD:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Set up JDK 17
15+
uses: actions/setup-java@v3
16+
with:
17+
java-version: 17
18+
distribution: 'temurin'
19+
20+
- name: Grant execute permissions for gradlew
21+
run: chmod +x ./gradlew
22+
23+
- name: Verify Gradle version
24+
run: ./gradlew --version
25+
26+
# gradle build
27+
- name: Build with Gradle
28+
run: ./gradlew build -x test
29+
30+
# docker build & push to production
31+
- name: Docker build & push to prod
32+
# if: contains(github.ref, 'main')
33+
if: github.ref == 'refs/heads/feature/issue-4'
34+
run: |
35+
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
36+
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/embitips_back .
37+
docker push ${{ secrets.DOCKER_USERNAME }}/embitips_back
38+
39+
## deploy to production
40+
- name: Deploy to prod
41+
uses: appleboy/ssh-action@master
42+
id: deploy-prod
43+
# if: contains(github.ref, 'main')
44+
if: github.ref == 'refs/heads/feature/issue-4'
45+
with:
46+
host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS
47+
username: ${{ secrets.USERNAME }}
48+
key: ${{ secrets.PRIVATE_KEY }}
49+
envs: GITHUB_SHA
50+
script: |
51+
# 기존 컨테이너 중지 및 삭제
52+
sudo docker stop embitips_back || true
53+
sudo docker rm embitips_back || true
54+
sudo docker ps
55+
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/embitips_back
56+
sudo docker run -d -p 8080:8080 -e DB_URL="${{ secrets.DB_URL }}" -e DB_USERNAME="${{ secrets.DB_USERNAME }}" -e DB_PASSWORD="${{ secrets.DB_PASSWORD }}" --name embitips_back ${{ secrets.DOCKER_USERNAME }}/embitips_back
57+
sudo docker image prune -f

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Dockerfile
2+
FROM eclipse-temurin:17-jdk-alpine
3+
4+
# 작업 디렉토리 설정
5+
WORKDIR /app
6+
7+
# 의존성 파일 복사 및 캐싱
8+
COPY ./api/build/libs/*.jar app.jar
9+
10+
# 애플리케이션 실행
11+
ENTRYPOINT ["java", "-jar", "app.jar"]

build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,13 @@ subprojects {
4848
tasks.test {
4949
useJUnitPlatform()
5050
}
51+
}
52+
53+
tasks.bootJar {
54+
archiveBaseName.set("embitips") // JAR 이름
55+
archiveVersion.set("0.0.1") // 버전
56+
mainClass.set("api.com.baekjoon.MbtipsApplication")
57+
}
58+
tasks.jar {
59+
enabled = false
5160
}
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
21
spring:
32
datasource:
3+
# url: ${DB_URL}
4+
# username: ${DB_USERNAME}
5+
# password: ${DB_PASSWORD}
46
driver-class-name: com.mysql.cj.jdbc.Driver
5-
url: "jdbc:mysql://localhost:3306/problem"
6-
username: root
7-
password: "!qotjrdyd1"
8-
7+
url: jdbc:mysql://34.47.101.168:3306/embitips?serverTimezone=UTC&useSSL=false
8+
username: embitipsdb
9+
password: embitipsdb0214
910
jpa:
11+
database-platform: org.hibernate.dialect.MySQL8Dialect
1012
show-sql: true
1113
hibernate:
1214
ddl-auto: update
1315
properties:
1416
hibernate:
1517
format_sql: true
16-
open-in-view: false
18+
open-in-view: false
19+
logging:
20+
level:
21+
org.hibernate.SQL: DEBUG
22+
org.hibernate.type.descriptor.sql.BasicBinder: TRACE

0 commit comments

Comments
 (0)