Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
54 changes: 15 additions & 39 deletions .github/workflows/dev-ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Dev CI/CD - Build and Deploy
name: Dev CI/CD - Build, Push and Deploy

on:
push:
Expand All @@ -12,13 +12,13 @@ concurrency:
env:
REGISTRY: docker.io
IMAGE_NAME: ninecraft0523/ninecraft-server
MODULE: apis

jobs:
build-and-push:
build-push-and-deploy:
runs-on: ubuntu-24.04
timeout-minutes: 20
outputs:
tags: ${{ steps.meta.outputs.tags }}
environment: development

steps:
- name: Checkout code
Expand All @@ -28,27 +28,17 @@ jobs:
run: |
mkdir ./secret
echo "${{ secrets.DEV_SECRET_PROPERTIES }}" > ./secret/application-dev-secret.properties
echo "${{ secrets.PROD_SECRET_PROPERTIES }}" > ./secret/application-prod-secret.properties
echo "${{ secrets.TEST_SECRET_PROPERTIES }}" > ./secret/application-test-secret.properties
chmod 600 ./secret/*

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: gradle
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
gradle-home-cache-cleanup: true

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Run full Gradle build
run: ./gradlew build --parallel --build-cache
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
Expand All @@ -58,32 +48,20 @@ jobs:
tags: |
type=raw,value=development-latest

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
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
runs-on: ubuntu-24.04
timeout-minutes: 10
environment: development

steps:
- name: Deploy to Development Server
uses: appleboy/[email protected]
with:
Expand All @@ -92,11 +70,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 }}"
export IMAGE_TAG="$(echo "${{ steps.meta.outputs.tags }}" | head -n1)"
cd ~/deploy
chmod +x ./deploy.sh
./deploy.sh

60 changes: 17 additions & 43 deletions .github/workflows/prod-ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Prod CI/CD - Build and Deploy
name: Prod CI/CD - Build, Push and Deploy

on:
release:
types:
- published # Release가 published 때만 실행
- published # GitHub Release가 'published' 상태일 때만 워크플로우를 실행합니다.

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -12,15 +12,13 @@ concurrency:
env:
REGISTRY: docker.io
IMAGE_NAME: ninecraft0523/ninecraft-server
MODULE: apis

jobs:
build-and-push:
build-push-and-deploy:
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 }}
environment: production

steps:
- name: Checkout code
Expand All @@ -29,28 +27,18 @@ jobs:
- name: Inject application-secret.properties from Secrets
run: |
mkdir ./secret
echo "${{ secrets.DEV_SECRET_PROPERTIES }}" > ./secret/application-dev-secret.properties
echo "${{ secrets.PROD_SECRET_PROPERTIES }}" > ./secret/application-prod-secret.properties
echo "${{ secrets.TEST_SECRET_PROPERTIES }}" > ./secret/application-test-secret.properties
chmod 600 ./secret/*

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: gradle
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
gradle-home-cache-cleanup: true

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Run full Gradle build with strict validation
run: ./gradlew build --parallel --build-cache --warning-mode all
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
Expand All @@ -61,33 +49,20 @@ jobs:
type=semver,pattern={{version}}
type=raw,value=production-latest

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
id: build
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
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 }}

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
runs-on: ubuntu-24.04
timeout-minutes: 20
environment: production

steps:
- name: Deploy to Production Server
uses: appleboy/[email protected]
with:
Expand All @@ -96,11 +71,10 @@ 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)"
export VERSION_TAG="${{ needs.build-and-push.outputs.version }}"
export IMAGE_TAG="$(echo "${{ steps.meta.outputs.tags }}" | head -n1)"
export VERSION_TAG="${{ steps.meta.outputs.version }}"
export RELEASE_VERSION="${{ github.event.release.tag_name }}"
cd ~/deploy
chmod +x ./deploy.sh
Expand Down
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Build stage
FROM gradle:8.7-jdk21 AS build
ARG MODULE=apis
WORKDIR /app

# 의존성 캐싱 최적화를 위한 단계별 복사
# 1. 의존성 관련 파일만 먼저 복사
COPY build.gradle settings.gradle ./
COPY ${MODULE}/build.gradle ./${MODULE}/

# 2. 소스코드 없이 의존성만 다운로드
RUN ./gradlew :${MODULE}:dependencies --no-daemon

# 3. 소스코드 전체 복사
COPY . .

Comment on lines +6 to +16
Copy link
Member

Choose a reason for hiding this comment

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

궁금한게 의존성 캐싱처리했을 때와 캐싱하지 않았을 경우 빌드차이속도가 어느정도 나는지 궁금하네요!
혹시 한번 테스트가능할까요!?

# 4. 실제 애플리케이션 빌드
RUN ./gradlew :${MODULE}:bootJar --parallel --no-daemon

# Run stage
FROM openjdk:21-slim
ARG MODULE=apis
WORKDIR /app

# 멀티스테이지 빌드로 최종 이미지 크기 최소화
COPY --from=build /app/${MODULE}/build/libs/${MODULE}-*.jar app.jar

# 런타임에 필요한 secret 폴더 복사
COPY --from=build /app/secret ./secret/

# JVM 실행 설정
# - Xms512m: 초기 힙 메모리 512MB
# - Xmx1g: 최대 힙 메모리 1GB
ENTRYPOINT ["java", "-Xms512m", "-Xmx1g", "-jar", "app.jar"]
Copy link
Member

Choose a reason for hiding this comment

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

현재 EC2 기본 인스턴스(1GB 메모리)에서 MySQL, Redis, Nginx, 그리고 Java 기반 애플리케이션까지 함께 구동하고자 하는 상황인데, 메모리가 다소 부족할 수 있을 것 같아 별도로 스왑 메모리를 설정해놓았는데 제대로 버틸지 의문이긴하네요 256MB로 조금이나마 작게 가져가는건 어떨까요 너무적을까요!?

34 changes: 34 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Build stage
FROM gradle:8.7-jdk21 AS build
ARG MODULE=apis
WORKDIR /app

# 의존성 캐싱 최적화를 위한 단계별 복사
# 1. 의존성 관련 파일만 먼저 복사
COPY build.gradle settings.gradle ./
COPY ${MODULE}/build.gradle ./${MODULE}/

# 2. 소스코드 없이 의존성만 다운로드
RUN ./gradlew :${MODULE}:dependencies --no-daemon

# 3. 소스코드 전체 복사
COPY . .

# 4. 실제 애플리케이션 빌드
RUN ./gradlew :${MODULE}:bootJar --parallel --no-daemon

# Run stage
FROM openjdk:21-slim
ARG MODULE=apis
WORKDIR /app

# 멀티스테이지 빌드로 최종 이미지 크기 최소화
COPY --from=build /app/${MODULE}/build/libs/${MODULE}-*.jar app.jar

# 런타임에 필요한 secret 폴더 복사
COPY --from=build /app/secret ./secret/

# JVM 실행 설정
# Xms512m: 초기 힙 메모리 512MB
# Xmx1g: 최대 힙 메모리 1GB
ENTRYPOINT ["java", "-Xms512m", "-Xmx1g", "-jar", "app.jar"]