-
Notifications
You must be signed in to change notification settings - Fork 1
chore: Dockerfile 세팅 및 CI/CD스크립트 리팩터링 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
1565e32
e4f6797
23b7b96
c18f95a
2524890
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,13 +12,12 @@ concurrency: | |
| env: | ||
| REGISTRY: docker.io | ||
| IMAGE_NAME: ninecraft0523/ninecraft-server | ||
| MODULE: apis | ||
|
|
||
| jobs: | ||
| build-and-push: | ||
| build: | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 20 | ||
| outputs: | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
|
|
@@ -47,16 +46,19 @@ jobs: | |
| - name: Grant execute permission for gradlew | ||
| run: chmod +x gradlew | ||
|
|
||
| - name: Run full Gradle build | ||
| - name: Run full Gradle build and test | ||
| run: ./gradlew build --parallel --build-cache | ||
|
|
||
| - name: Extract metadata for Docker | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
| tags: | | ||
| type=raw,value=development-latest | ||
| build-and-push: | ||
| needs: build | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 15 | ||
| outputs: | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
@@ -67,15 +69,26 @@ jobs: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
|
||
| - name: Extract metadata for Docker | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
| tags: | | ||
| type=raw,value=development-latest | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) 태그 전략 개선 권장 – 예시: 🤖 Prompt for AI Agents |
||
| - name: Build and push Docker image | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| file: Dockerfile-dev | ||
| platforms: linux/amd64,linux/arm64 | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
| build-args: | | ||
| MODULE=${{ env.MODULE }} | ||
|
|
||
| deploy-dev: | ||
| needs: build-and-push | ||
|
|
@@ -92,11 +105,9 @@ jobs: | |
| key: ${{ secrets.DEV_SSH_KEY }} | ||
| port: ${{ secrets.DEV_PORT }} | ||
| script: | | ||
| cd /opt/app | ||
| export DOCKERHUB_USERNAME="${{ secrets.DOCKERHUB_USERNAME }}" | ||
| export DOCKERHUB_TOKEN="${{ secrets.DOCKERHUB_TOKEN }}" | ||
| export IMAGE_TAG="${{ needs.build-and-push.outputs.tags }}" | ||
| cd ~/deploy | ||
| chmod +x ./deploy.sh | ||
| ./deploy.sh | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,15 +12,12 @@ concurrency: | |
| env: | ||
| REGISTRY: docker.io | ||
| IMAGE_NAME: ninecraft0523/ninecraft-server | ||
| MODULE: apis | ||
|
|
||
| jobs: | ||
| build-and-push: | ||
| build: | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 25 | ||
| outputs: | ||
| image-digest: ${{ steps.build.outputs.digest }} | ||
| version: ${{ steps.meta.outputs.version }} | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
|
|
@@ -52,14 +49,18 @@ jobs: | |
| - name: Run full Gradle build with strict validation | ||
| run: ./gradlew build --parallel --build-cache --warning-mode all | ||
|
|
||
| - name: Extract metadata for Docker | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
| tags: | | ||
| type=semver,pattern={{version}} | ||
| type=raw,value=production-latest | ||
| build-and-push: | ||
| needs: build | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 20 | ||
| outputs: | ||
| image-digest: ${{ steps.build.outputs.digest }} | ||
| version: ${{ steps.meta.outputs.version }} | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
@@ -70,6 +71,15 @@ jobs: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
|
||
| - name: Extract metadata for Docker | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
| tags: | | ||
| type=semver,pattern={{version}} | ||
| type=raw,value=production-latest | ||
|
|
||
| - name: Build and push Docker image | ||
| id: build | ||
| uses: docker/build-push-action@v6 | ||
|
|
@@ -80,6 +90,8 @@ jobs: | |
| tags: ${{ steps.meta.outputs.tags }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
| build-args: | | ||
| MODULE=${{ env.MODULE }} | ||
|
|
||
|
Comment on lines
+63
to
65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive)
🤖 Prompt for AI Agents |
||
| deploy-prod: | ||
| needs: build-and-push | ||
|
|
@@ -96,7 +108,6 @@ jobs: | |
| key: ${{ secrets.PROD_SSH_KEY }} | ||
| port: ${{ secrets.PROD_PORT }} | ||
| script: | | ||
| cd /opt/app | ||
| export DOCKERHUB_USERNAME="${{ secrets.DOCKERHUB_USERNAME }}" | ||
| export DOCKERHUB_TOKEN="${{ secrets.DOCKERHUB_TOKEN }}" | ||
| export IMAGE_TAG="$(echo "${{ needs.build-and-push.outputs.tags }}" | head -n1)" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Build stage | ||
| FROM gradle:8.7-jdk21 AS build | ||
| ARG MODULE=apis | ||
| WORKDIR /app | ||
| COPY . . | ||
| RUN ./gradlew :${MODULE}:bootJar --no-daemon | ||
|
|
||
| # Run stage | ||
| FROM openjdk:21-slim | ||
| ARG MODULE=apis | ||
| WORKDIR /app | ||
| COPY --from=build /app/${MODULE}/build/libs/*.jar app.jar | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ENTRYPOINT ["java", "-jar", "app.jar"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Build stage | ||
| FROM gradle:8.7-jdk21 AS build | ||
| ARG MODULE=apis | ||
| WORKDIR /app | ||
| COPY . . | ||
| RUN ./gradlew :${MODULE}:bootJar --no-daemon | ||
|
|
||
| # Run stage | ||
| FROM openjdk:21-slim | ||
| ARG MODULE=apis | ||
| WORKDIR /app | ||
| COPY --from=build /app/${MODULE}/build/libs/*.jar app.jar | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ENTRYPOINT ["java", "-jar", "app.jar"] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Gradle 컴파일이 두 번 발생 → 빌드 시간 불필요 증가
build잡에서 이미./gradlew build를 수행했지만,docker build단계가 다시 소스 전체를 복사해 내부에서 Gradle 빌드를 반복합니다.아티팩트를 업로드‧다운로드해서 Docker 컨텍스트로 넘기거나,
--build-arg BUILT_JAR방식으로 한 번만 빌드하도록 리팩터링하면 5~7 분 단축됩니다.🤖 Prompt for AI Agents