Skip to content

Commit cfc862f

Browse files
authored
๐ŸŽ perf : jib๋„์ž…์œผ๋กœ ์„ฑ๋Šฅ์ฆ๊ฐ€ (#212)
1 parent c1c531e commit cfc862f

File tree

4 files changed

+54
-115
lines changed

4 files changed

+54
-115
lines changed

โ€Ž.github/workflows/deploy-dev.ymlโ€Ž

Lines changed: 21 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -4,96 +4,64 @@ on:
44
push:
55
branches:
66
- "develop"
7-
workflow_dispatch:
87

98
permissions: write-all
109

1110
jobs:
12-
build:
13-
name: Deploy
11+
build-and-push:
1412
runs-on: ubuntu-latest
15-
13+
env:
14+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
15+
DOCKER_DEV_REPO: ${{ secrets.DOCKER_DEV_REPO }}
16+
CONTAINER_PORT_DEV: ${{ secrets.CONTAINER_PORT_DEV }}
1617
steps:
17-
- name: Start Timing
18-
run: |
19-
echo "WORKFLOW_START=$(date +%s)" >> $GITHUB_ENV
20-
2118
- name: ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค
22-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
2320
with:
2421
submodules: true
2522
token: ${{ secrets.SUBMODULE_TOKEN }}
2623

27-
- name: Record Checkout Time
28-
run: |
29-
echo "CHECKOUT_END=$(date +%s)" >> $GITHUB_ENV
30-
3124
- name: JDK 21์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค
3225
uses: actions/setup-java@v4
3326
with:
3427
java-version: '21'
3528
distribution: 'temurin'
36-
37-
- name: Record JDK Setup Time
38-
run: |
39-
echo "JDK_SETUP_END=$(date +%s)" >> $GITHUB_ENV
40-
41-
- name: Gradle ์บ์‹ฑ
42-
uses: actions/cache@v2
43-
with:
44-
path: |
45-
~/.gradle/caches
46-
~/.gradle/wrapper
47-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
48-
restore-keys: |
49-
${{ runner.os }}-gradle-
50-
51-
- name: Record Cache Time
52-
run: |
53-
echo "CACHE_END=$(date +%s)" >> $GITHUB_ENV
54-
55-
- name: gradlew ํŒŒ์ผ์— ์‹คํ–‰ ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค
56-
run: chmod +x gradlew
57-
58-
- name: ๋นŒ๋“œ๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค
59-
run: |
60-
echo "BUILD_START=$(date +%s)" >> $GITHUB_ENV
61-
./gradlew bootJar --stacktrace
62-
echo "BUILD_END=$(date +%s)" >> $GITHUB_ENV
29+
cache: gradle
6330

6431
- name: ๋„์ปค ๋กœ๊ทธ์ธ
65-
uses: docker/login-action@v2
32+
uses: docker/login-action@v3
6633
with:
6734
username: ${{ secrets.DOCKER_USERNAME }}
6835
password: ${{ secrets.DOCKER_PASSWORD }}
6936

70-
- name: ๋„์ปค ๋นŒ๋“œ
71-
run: |
72-
echo "DOCKER_BUILD_START=$(date +%s)" >> $GITHUB_ENV
73-
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_DEV_REPO }} .
74-
echo "DOCKER_BUILD_END=$(date +%s)" >> $GITHUB_ENV
37+
- name: gradlew ํŒŒ์ผ์— ์‹คํ–‰ ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค
38+
run: chmod +x gradlew
7539

76-
- name: ๋„์ปค ํ‘ธ์‹œ
40+
- name: Jib๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋„์ปค ์ด๋ฏธ์ง€ ๋นŒ๋“œ ๋ฐ ํ‘ธ์‹œ
7741
run: |
78-
echo "DOCKER_PUSH_START=$(date +%s)" >> $GITHUB_ENV
79-
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_DEV_REPO }}
80-
echo "DOCKER_PUSH_END=$(date +%s)" >> $GITHUB_ENV
42+
./gradlew jib --no-daemon --console=plain
8143
44+
deploy:
45+
needs: build-and-push
46+
runs-on: ubuntu-latest
47+
env:
48+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
49+
DOCKER_DEV_REPO: ${{ secrets.DOCKER_DEV_REPO }}
50+
steps:
8251
- name: AWS Credentials ์„ค์ •
83-
uses: aws-actions/configure-aws-credentials@v1
52+
uses: aws-actions/configure-aws-credentials@v4
8453
with:
8554
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
8655
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
8756
aws-region: ap-northeast-2
8857

8958
- name: ๊ฐœ๋ฐœ ์„œ๋ฒ„ ๋ฐฐํฌ
90-
uses: appleboy/ssh-action@master
59+
uses: appleboy/ssh-action@v1.0.3
9160
with:
9261
host: ${{ secrets.DEV_AWS_EC2_PUBLIC_IP }}
9362
username: ec2-user
9463
key: ${{ secrets.AWS_EC2_PEM_KEY }}
9564
script: |
96-
echo "DEPLOY_START=$(date +%s)" >> $GITHUB_ENV
9765
cd /home/ec2-user/potatoes/dev
9866
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
9967
docker stop develop-server
@@ -102,59 +70,3 @@ jobs:
10270
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_DEV_REPO }}:latest
10371
docker-compose up -d
10472
docker image prune -f
105-
echo "DEPLOY_END=$(date +%s)" >> $GITHUB_ENV
106-
107-
- name: Generate Performance Report
108-
run: |
109-
echo "WORKFLOW_END=$(date +%s)" >> $GITHUB_ENV
110-
111-
# Calculate times
112-
echo "# CI/CD Performance Report" > performance_report.md
113-
echo "## Execution Times" >> performance_report.md
114-
echo "" >> performance_report.md
115-
116-
# Checkout time
117-
checkout_time=$((CHECKOUT_END - WORKFLOW_START))
118-
echo "* Checkout Time: ${checkout_time}s" >> performance_report.md
119-
120-
# JDK setup time
121-
jdk_time=$((JDK_SETUP_END - CHECKOUT_END))
122-
echo "* JDK Setup Time: ${jdk_time}s" >> performance_report.md
123-
124-
# Cache time
125-
cache_time=$((CACHE_END - JDK_SETUP_END))
126-
echo "* Cache Setup Time: ${cache_time}s" >> performance_report.md
127-
128-
# Build time
129-
build_time=$((BUILD_END - BUILD_START))
130-
echo "* Gradle Build Time: ${build_time}s" >> performance_report.md
131-
132-
# Docker build time
133-
docker_build_time=$((DOCKER_BUILD_END - DOCKER_BUILD_START))
134-
echo "* Docker Build Time: ${docker_build_time}s" >> performance_report.md
135-
136-
# Docker push time
137-
docker_push_time=$((DOCKER_PUSH_END - DOCKER_PUSH_START))
138-
echo "* Docker Push Time: ${docker_push_time}s" >> performance_report.md
139-
140-
# Total time
141-
total_time=$((WORKFLOW_END - WORKFLOW_START))
142-
echo "* Total Workflow Time: ${total_time}s" >> performance_report.md
143-
144-
echo "" >> performance_report.md
145-
echo "## Build Information" >> performance_report.md
146-
echo "* Commit: ${{ github.sha }}" >> performance_report.md
147-
echo "* Branch: ${{ github.ref }}" >> performance_report.md
148-
echo "* Trigger: ${{ github.event_name }}" >> performance_report.md
149-
150-
# Add changed files information
151-
echo "" >> performance_report.md
152-
echo "## Change Information" >> performance_report.md
153-
echo "* Files changed: $(git diff --name-only HEAD HEAD~1 | wc -l)" >> performance_report.md
154-
echo "* Changes summary: $(git diff --shortstat HEAD HEAD~1)" >> performance_report.md
155-
156-
- name: Upload Performance Report
157-
uses: actions/upload-artifact@v2
158-
with:
159-
name: performance-report
160-
path: performance_report.md

โ€ŽDockerfileโ€Ž

Lines changed: 0 additions & 6 deletions
This file was deleted.

โ€Žbuild.gradleโ€Ž

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id 'java'
33
id 'org.springframework.boot' version '3.3.5'
44
id 'io.spring.dependency-management' version '1.1.6'
5+
id 'com.google.cloud.tools.jib' version '3.4.4'
56
}
67

78
group = 'Potatoes'
@@ -60,6 +61,16 @@ dependencies {
6061

6162
//Redis
6263
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
64+
65+
//Query Dsl
66+
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
67+
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
68+
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
69+
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
70+
71+
//MapStruct
72+
implementation 'org.mapstruct:mapstruct:1.5.3.Final'
73+
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
6374
}
6475

6576
tasks.named('test') {
@@ -75,3 +86,21 @@ tasks.register('copySecret', Copy) {
7586
}
7687
into('src/main/resources')
7788
}
89+
90+
def dockerUser = System.getenv('DOCKER_USERNAME')
91+
def dockerImage = System.getenv('DOCKER_DEV_REPO')
92+
def containerPort = System.getenv('CONTAINER_PORT_DEV')
93+
94+
jib {
95+
from {
96+
image = 'eclipse-temurin:21-jre-alpine'
97+
}
98+
to {
99+
image = "${dockerUser}/${dockerImage}"
100+
tags = ['latest']
101+
}
102+
container {
103+
jvmFlags = ['-Dspring.profiles.active=dev', '-Dfile.encoding=UTF-8']
104+
ports = [containerPort]
105+
}
106+
}

โ€Žgradle/wrapper/gradle-wrapper.propertiesโ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
77
zipStorePath=wrapper/dists
8+
org.gradle.daemon=true
9+
org.gradle.parallel=true
10+
org.gradle.caching=true
11+
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

0 commit comments

Comments
ย (0)