@@ -29,14 +29,14 @@ jobs:
2929 java-version : ' 21'
3030 distribution : ' temurin'
3131
32- # Gradle 캐싱을 추가하여 빌드 속도를 개선합니다.
32+ # Gradle 캐싱 제거 -> 처음부터 빌드
3333 - name : Cache Gradle packages
3434 uses : actions/cache@v4
3535 with :
3636 path : |
3737 ~/.gradle/caches
3838 ~/.gradle/wrapper
39- key : ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
39+ key : ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}-v2
4040 restore-keys : |
4141 ${{ runner.os }}-gradle-
4242
7777 # 2. 릴리스 : main/develop 브랜치로 Push될 때만 실행
7878 makeTagAndRelease :
7979 name : Create Tag and Release
80- if : github.event_name == 'push'
80+ # if: github.event_name == 'push'
8181 needs : backend-ci
8282 runs-on : ubuntu-latest
8383 permissions :
@@ -107,46 +107,37 @@ jobs:
107107 # 3. 빌드 및 배포: main/develop 브랜치로 Push될 때만 실행
108108 buildImageAndPush :
109109 name : 도커 이미지 빌드와 푸시
110- if : github.event_name == 'push'
111110 needs : makeTagAndRelease
112111 runs-on : ubuntu-latest
113112 steps :
114- - uses : actions/checkout@v4
113+ - name : 1. 소스 코드 체크아웃
114+ uses : actions/checkout@v4
115115
116- - name : 빌드 컨텍스트 확인 (backend 폴더 내용)
117- run : |
118- echo "--- Docker 빌드에 사용될 backend 폴더의 전체 파일 목록입니다 ---"
119- ls -laR ./backend
116+ - name : 2. JDK 21 설치
117+ uses : actions/setup-java@v4
118+ with :
119+ java-version : ' 21'
120+ distribution : ' temurin'
120121
121- - name : application-secret.yml 생성
122+ - name : 3. Gradle 실행 권한 부여
123+ working-directory : ./backend
124+ run : chmod +x ./gradlew
125+
126+ - name : 4. application-secret.yml 생성 (빌드 전)
122127 env :
123128 APPLICATION_SECRET : ${{ secrets.APPLICATION_SECRET }}
124- run : |
125- mkdir -p ./backend/src/main/resources
126- echo "$APPLICATION_SECRET" > ./backend/src/main/resources/application-secret.yml
127- - name : Docker Buildx 설치
128- uses : docker/setup-buildx-action@v2
129- - name : 레지스트리 로그인
130- uses : docker/login-action@v2
131- with :
132- registry : ghcr.io
133- username : ${{ github.actor }}
134- password : ${{ secrets.GITHUB_TOKEN }}
129+ run : echo "$APPLICATION_SECRET" > ./backend/src/main/resources/application-secret.yml
135130
136- - name : set lower case owner name
137- id : set_owner
138- run : |
139- echo "OWNER_LC=${OWNER,,}" >> ${GITHUB_ENV}
140- env :
141- OWNER : ' ${{ github.repository_owner }}'
142-
143- - name : 빌드 앤 푸시
131+ - name : 5. CI 환경에서 Gradle 빌드 실행
132+ working-directory : ./backend
133+ run : ./gradlew clean build -x test
134+
135+ - name : 6. Docker 빌드 및 푸시
144136 uses : docker/build-push-action@v3
145137 with :
146138 context : ./backend
147139 push : true
148- # 이 옵션을 추가하여 Docker 빌드 캐시를 사용하지 않도록 강제합니다.
149140 no-cache : true
150141 tags : |
151- ghcr.io/${{ env.OWNER_LC }}/catch-course:${{ needs.makeTagAndRelease.outputs.tag_name }}
152- ghcr.io/${{ env.OWNER_LC }}/catch-course:latest
142+ ghcr.io/${{ github.repository_owner }}/catch-course:${{ needs.makeTagAndRelease.outputs.tag_name }}
143+ ghcr.io/${{ github.repository_owner }}/catch-course:latest
0 commit comments