Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions .github/workflows/dev-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link

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
In .github/workflows/dev-ci-cd.yml around lines 49 to 50, the Gradle build is
executed twice, causing unnecessary build time increase. Refactor the workflow
to run the Gradle build only once by uploading the built artifacts after the
initial build step and then downloading them in the Docker build step, or pass
the built JAR as a build argument using --build-arg BUILT_JAR. This avoids
copying the entire source and rebuilding inside the Docker context, reducing
build time by 5 to 7 minutes.


- 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
Expand All @@ -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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

태그 전략 개선 권장 – development-latest 단일 태그는 충돌 위험
동시 커밋에서 같은 태그가 덮어써지면 롤백·디버깅이 어려워집니다. SHA 짧은값 또는 날짜를 추가해 고유 태그를 병행 저장하는 방식을 고려해 주세요.

예시:

tags: |
  type=raw,value=development-${{ github.sha }}
  type=raw,value=development-latest
🤖 Prompt for AI Agents
In .github/workflows/dev-ci-cd.yml around lines 73 to 79, the current tagging
strategy uses only the single tag "development-latest," which risks tag
collisions during concurrent commits. To fix this, modify the tags input to
include a unique tag using the short SHA or date along with
"development-latest." For example, add a tag like "development-${{ github.sha
}}" before "development-latest" to ensure each build has a unique tag for better
rollback and debugging.

- 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
Expand All @@ -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

39 changes: 25 additions & 14 deletions .github/workflows/prod-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

build-args에 추가 인자 여지 확보
현재 MODULE만 전달하지만, JAR 이름 또는 빌드 프로파일 등 추가 인자가 필요해질 수 있습니다. 다중 줄 블록을 유지하면서 주석으로 향후 확장성을 명시해 두면 유지보수에 도움이 됩니다.

🤖 Prompt for AI Agents
In .github/workflows/prod-ci-cd.yml around lines 93 to 95, the build-args
currently only pass the MODULE variable. To allow future expansion for
additional arguments like JAR name or build profile, keep the multi-line block
format and add a comment above or within the build-args section indicating that
more build arguments can be added here later. This improves maintainability by
explicitly noting the potential for extension.

deploy-prod:
needs: build-and-push
Expand All @@ -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)"
Expand Down
13 changes: 13 additions & 0 deletions Dockerfile
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
ENTRYPOINT ["java", "-jar", "app.jar"]
13 changes: 13 additions & 0 deletions Dockerfile-dev
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
ENTRYPOINT ["java", "-jar", "app.jar"]