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

on:
push:
branches:
- develop

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout With Submodules
uses: actions/checkout@v4
with:
token: ${{ secrets.ACCESS_TOKEN }}
submodules: recursive
fetch-depth: 0

- name: Update Git Submodules
run: git submodule update --init --recursive

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

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

- name: Build Jar
run: ./gradlew clean bootJar -Dspring.profiles.active=prod

- name: Docker login
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

- name: Docker build and push
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest .
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest
deploy:
name: Deploy to NCP Server
runs-on: ubuntu-latest
needs: build-and-push

steps:
- name: Deploy to NCP EC2 via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.NCP_HOST }}
username: ${{ secrets.NCP_USER }}
password: ${{ secrets.NCP_PASSWORD }}
port: ${{ secrets.NCP_PORT }}
script: |
echo "Docker Image Pull"
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest

echo "Remove old containers"
docker rm -f spring-app || true
docker rm -f redis-container || true

echo "Create network if not exists"
docker network inspect app-net >/dev/null 2>&1 || docker network create app-net

echo "Create volume for Redis data if not exists"
docker volume inspect redis-data >/dev/null 2>&1 || docker volume create redis-data

echo "Run Redis container"
docker run -d --restart unless-stopped \
--name redis-container \
--network app-net \
-p ${{ secrets.REDIS_PORT }}:6379 \
-v redis-data:/data \
redis:latest \
redis-server --requirepass ${{ secrets.REDIS_PASSWORD }}

echo "Run SpringBoot container"
docker run -d --restart unless-stopped \
--name spring-app \
--network app-net \
-p ${{ secrets.SPRINGBOOT_PORT }}:8080 \
-e REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }} \
-e SPRINGBOOT_PORT=${{ secrets.SPRINGBOOT_PORT }} \
${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest
78 changes: 78 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: CI with Gradle

on:
push:
branches-ignore:
- main
- develop

pull_request:
branches:
- develop

jobs:
CI:
name: Continuous Integration
if: github.event_name != 'push' || github.event.created == false
runs-on: ubuntu-latest
permissions:
contents: read
checks: write
pull-requests: write


steps:
- name: Checkout With Submodules
uses: actions/checkout@v4
with:
token: ${{ secrets.ACCESS_TOKEN }}
submodules: recursive
fetch-depth: 0

- name: Update Git Submodules
run: git submodule update --init --recursive

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

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

- name: Start Redis
uses: supercharge/redis-github-action@1.7.0
with:
redis-version: ${{ secrets.REDIS_TEST_VERSION }}
redis-remove-container: true
redis-password: ${{ secrets.REDIS_TEST_PASSWORD }}

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

- name: Verify Config folders
run: ls -al BEconfig

- name: Build and Test with 'test' profile
run: |
echo " >>> Running Gradle build with 'test' profile"
./gradlew --no-daemon clean build -Dspring.profiles.active=test

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: '**/build/test-results/test/TEST-*.xml'
comment_mode: always

- name: Build summary
if: success()
run: |
echo "Gradle build successfully completed with tests (profile: test)"

- name: Mark failure if tests failed
if: failure()
run: |
echo "Tests failed. Please check the test logs for detail"
exit 1
2 changes: 1 addition & 1 deletion BEconfig
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:17-jdk-slim
ARG JAR_FILE=build/libs/*-SNAPSHOT.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul", "-Dspring.profiles.active=prod", "-jar", "/app.jar"]
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {

// Database
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'com.h2database:h2'

// Lombok
compileOnly 'org.projectlombok:lombok'
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/perfact/be/BeApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest
@ActiveProfiles("test")
class BeApplicationTests {

@Test
Expand Down