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/ssh-action@v1.2.0
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading