Skip to content

Commit e8ca792

Browse files
✨ test : 도커 이미지 빌드 시간 최적화 테스트
1 parent 1f23ee1 commit e8ca792

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

.github/workflows/ci-cd-main.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,51 +10,70 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13+
# 1. Checkout code
1314
- name: Checkout code
1415
uses: actions/checkout@v3 # 최신 버전 사용
1516

17+
# 2. Cache Gradle dependencies
18+
- name: Cache Gradle dependencies
19+
uses: actions/cache@v4
20+
with:
21+
path: ~/.gradle/caches
22+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradlew') }}
23+
restore-keys: |
24+
${{ runner.os }}-gradle-
25+
26+
# 3. Set up Docker Buildx
1627
- name: Set up Docker Buildx
1728
uses: docker/setup-buildx-action@v2 # 최신 버전 사용
1829

30+
# 4. Cache Docker layers
1931
- name: Cache Docker layers
20-
uses: actions/cache@v3 # 최신 버전 사용
32+
uses: actions/cache@v3
2133
with:
2234
path: /tmp/.buildx-cache
2335
key: ${{ runner.os }}-buildx-${{ github.sha }}
2436
restore-keys: |
2537
${{ runner.os }}-buildx-
2638
39+
# 5. Log in to Google Cloud
2740
- name: Log in to Google Cloud
28-
uses: google-github-actions/auth@v1 # 최신 버전 사용
41+
uses: google-github-actions/auth@v1
2942
with:
3043
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
3144

45+
# 6. Configure docker for gcloud
3246
- name: Configure docker for gcloud
3347
run: gcloud auth configure-docker asia-northeast3-docker.pkg.dev
3448

49+
# 7. Build and push Docker image
3550
- name: Build and push Docker image
3651
run: |
3752
docker buildx build --push \
3853
--cache-from=type=local,src=/tmp/.buildx-cache \
3954
--cache-to=type=local,dest=/tmp/.buildx-cache \
55+
--build-arg GRADLE_USER_HOME=/home/gradle/.gradle \
4056
--tag asia-northeast3-docker.pkg.dev/symbolic-yen-441710-h6/practice-main/kafka-user:${{ github.sha }} .
4157
4258
deploy:
4359
runs-on: ubuntu-latest
4460
needs: build
4561

4662
steps:
63+
# 1. Checkout deployment repo
4764
- name: Checkout deployment repo
48-
uses: actions/checkout@v3 # 최신 버전 사용
65+
uses: actions/checkout@v3
4966
with:
5067
repository: kafka-practice/kafka-manifest
5168
path: manifests
5269
token: ${{ secrets.DEPLOY_KEY }}
5370

71+
# 2. Update manifest
5472
- name: Update manifest
5573
run: |
5674
sed -i "s|image: .*|image: asia-northeast3-docker.pkg.dev/symbolic-yen-441710-h6/practice-main/kafka-user:${{ github.sha }}|" manifests/kafka-user/deployment.yaml
57-
75+
76+
# 3. Commit and push changes
5877
- name: Commit and push changes
5978
working-directory: manifests
6079
run: |

Dockerfile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,12 @@ FROM amazoncorretto:17-al2-jdk AS builder
66
RUN mkdir /kafka-user
77
WORKDIR /kafka-user
88

9-
# Gradle 캐시 디렉토리 복사 (이미 존재한다면 재사용)
10-
COPY --chown=gradle:gradle .gradle /home/gradle/.gradle
9+
RUN mkdir -p /home/gradle/.gradle
1110

12-
# 소스 코드 복사
1311
COPY . .
1412

15-
# 실행 권한 추가
1613
RUN chmod +x gradlew
17-
18-
# Gradle 종속성 설치 (종속성 변경 없으면 캐시 사용)
1914
RUN ./gradlew dependencies
20-
21-
# 애플리케이션 빌드
2215
RUN ./gradlew clean bootJar
2316

2417
# runtime image

0 commit comments

Comments
 (0)