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
47 changes: 47 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CD

on:
workflow_run:
workflows: ["CI with Gradle"] # CI μ›Œν¬ν”Œλ‘œμš° 이름과 μ •ν™•νžˆ μΌμΉ˜ν•΄μ•Ό 함
types: [completed]
branches: [main] # main λΈŒλžœμΉ˜μ—μ„œ CIκ°€ μ„±κ³΅μ μœΌλ‘œ 끝났을 λ•Œλ§Œ μ‹€ν–‰

permissions:
contents: read

env:
IMAGE: ${{ secrets.DOCKER_USERNAME }}/bearchive # CI와 λ™μΌν•œ 이미지λͺ… μ‚¬μš©

jobs:
deploy:
name: Deploy to Server
runs-on: ubuntu-latest
# CI μ›Œν¬ν”Œλ‘œμš°κ°€ μ‹€νŒ¨ν•˜λ©΄ μ‹€ν–‰λ˜μ§€ μ•Šλ„λ‘ 쑰건 μΆ”κ°€
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v4

# SSH둜 μ„œλ²„μ— 접속해 배포
- name: Deploy over SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: 22
script: |
echo "${{ secrets.ENV_FILE }}" > /home/${{ secrets.SERVER_USER }}/.env
echo "[1/3] Pull latest Docker image..."
docker pull ${{ env.IMAGE }}:latest

echo "[2/3] Restart container with new image..."
docker stop bearchive || true
docker rm bearchive || true
docker run -d --name bearchive \
--env-file /home/${{ secrets.SERVER_USER }}/.env \
-p 8080:8080 \
${{ env.IMAGE }}:latest

echo "[3/3] Cleanup unused images..."
docker image prune -f
86 changes: 86 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: CI with Gradle

on:
pull_request:
branches: ["main"] # main λΈŒλžœμΉ˜μ— PR 이벀트 λ°œμƒ μ‹œ CI μ‹€ν–‰
push:
branches: ["main"] # main 브랜치둜 직접 push될 λ•Œλ„ CI μ‹€ν–‰
workflow_dispatch: # Actions νƒ­μ—μ„œ μˆ˜λ™ μ‹€ν–‰ λ²„νŠΌ 제곡

# 같은 λΈŒλžœμΉ˜μ—μ„œ 쀑볡 μ‹€ν–‰λ˜λ©΄ 이전 λΉŒλ“œ μ·¨μ†Œ
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

# μ „μ—­ ν™˜κ²½λ³€μˆ˜
env:
JAVA_VERSION: '21'
IMAGE: ${{ secrets.DOCKER_USERNAME }}/bearchive # Docker Hub 이미지λͺ… (μ†Œλ¬Έμž ν•„μˆ˜)

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Temurin JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

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

- name: Build JAR
# λΉŒλ“œν•  λͺ¨λ“ˆμ„ ':moamoa:' 둜 λͺ…ν™•νžˆ μ§€μ •
run: ./gradlew :moamoa:bootJar -x test --no-daemon

- name: Upload JAR artifact
uses: actions/upload-artifact@v4
with:
name: app-jar
# JAR 파일의 경둜λ₯Ό 'moamoa' λͺ¨λ“ˆμ˜ λΉŒλ“œ 경둜둜 λ³€κ²½
path: moamoa/build/libs/*.jar

docker-push:
name: Docker Build & Push
# 쑰건: PR μ΄λ²€νŠΈκ°€ μ•„λ‹ˆκ³  && λŒ€μƒ λΈŒλžœμΉ˜κ°€ main일 λ•Œλ§Œ 이미지 ν‘Έμ‹œ
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
needs: build # λΉŒλ“œ Job 성곡 ν›„μ—λ§Œ μ‹€ν–‰
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download JAR artifact
uses: actions/download-artifact@v4
with:
name: app-jar
# βœ… [μˆ˜μ •] μ•„ν‹°νŒ©νŠΈλ₯Ό λ‹€μš΄λ‘œλ“œν•  μœ„μΉ˜λ„ λ§žμΆ°μ£ΌλŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.
path: moamoa/build/libs

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build & Push image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ env.IMAGE }}:latest
${{ env.IMAGE }}:${{ github.sha }}
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac ###
.DS_Store

### ν™˜κ²½ λ³€μˆ˜, μ‹œν¬λ¦Ώ 파일 ###
application-secret.properties
.env

### ν™˜κ²½λ³€μˆ˜ 파일 ###
**/application-secret.properties

*.zip

logs

application.properties

10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM eclipse-temurin:21-jre

# μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ‹€ν–‰ 디렉토리
WORKDIR /app

# CIμ—μ„œ λ§Œλ“  JAR 파일의 경둜λ₯Ό 'moamoa' λͺ¨λ“ˆ 경둜둜 λ³€κ²½
COPY moamoa/build/libs/*.jar /app/app.jar

# μ‹€ν–‰
ENTRYPOINT ["java","-jar","/app/app.jar"]
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 3 additions & 2 deletions moamoa/gradlew β†’ gradlew
100644 β†’ 100755
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -205,7 +206,7 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
Expand Down
Loading