From a658cfce225097e99dd493c8076b834ce341b98a Mon Sep 17 00:00:00 2001 From: mikekks Date: Wed, 5 Feb 2025 16:02:39 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[UNI-65]=20chore:=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=A7=88=EB=8B=A4=20yml=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev.yml | 41 +++++++++++++++++++ .../src/main/resources/application-local.yml | 15 ++++++- .../resources/application-test.yml | 4 ++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 uniro_backend/src/main/resources/application-dev.yml rename uniro_backend/src/{test => main}/resources/application-test.yml (92%) diff --git a/uniro_backend/src/main/resources/application-dev.yml b/uniro_backend/src/main/resources/application-dev.yml new file mode 100644 index 0000000..56670dd --- /dev/null +++ b/uniro_backend/src/main/resources/application-dev.yml @@ -0,0 +1,41 @@ +spring: + config: + import: application.properties + datasource: + url: ${DB_URL} + username: ${DB_USER} + password: ${DB_PASSWORD} + driver-class-name: com.mysql.cj.jdbc.Driver + jpa: + hibernate: + ddl-auto: + properties: + hibernate: + dialect: org.hibernate.dialect.MySQL8Dialect + format_sql: true + show_sql: true + open-in-view: false + defer-datasource-initialization: true + sql: + init: + schema-locations: classpath:h2gis-setting.sql + h2: + console: + enabled: true + path: /h2-console +map: + api: + key: ${google.api.key} + +management: + endpoints: + jmx: + exposure: + exclude: "*" + web: + exposure: + include: info, health, prometheus + prometheus: + metrics: + export: + enabled: true \ No newline at end of file diff --git a/uniro_backend/src/main/resources/application-local.yml b/uniro_backend/src/main/resources/application-local.yml index 8ca1b45..941128a 100644 --- a/uniro_backend/src/main/resources/application-local.yml +++ b/uniro_backend/src/main/resources/application-local.yml @@ -23,4 +23,17 @@ spring: path: /h2-console map: api: - key: ${google.api.key} \ No newline at end of file + key: ${google.api.key} + +management: + endpoints: + jmx: + exposure: + exclude: "*" + web: + exposure: + include: info, health, prometheus + prometheus: + metrics: + export: + enabled: true \ No newline at end of file diff --git a/uniro_backend/src/test/resources/application-test.yml b/uniro_backend/src/main/resources/application-test.yml similarity index 92% rename from uniro_backend/src/test/resources/application-test.yml rename to uniro_backend/src/main/resources/application-test.yml index 290adb9..944a3b1 100644 --- a/uniro_backend/src/test/resources/application-test.yml +++ b/uniro_backend/src/main/resources/application-test.yml @@ -1,4 +1,8 @@ spring: + config: + activate: + on-profile: test + datasource: url: jdbc:h2:mem:uniro-local-db;DATABASE_TO_UPPER=FALSE;mode=mysql driverClassName: org.h2.Driver From 3c4bd1e63f95d337d87f0f604636323952fbd462 Mon Sep 17 00:00:00 2001 From: mikekks Date: Wed, 5 Feb 2025 16:05:52 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[UNI-65]=20feat:=20ci/cd=20=EA=B5=AC?= =?UTF-8?q?=EC=B6=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/be-cd.yml | 70 +++++++++++++++++++++++++++++++++++++ .github/workflows/be-ci.yml | 42 ++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 .github/workflows/be-cd.yml create mode 100644 .github/workflows/be-ci.yml diff --git a/.github/workflows/be-cd.yml b/.github/workflows/be-cd.yml new file mode 100644 index 0000000..a490f33 --- /dev/null +++ b/.github/workflows/be-cd.yml @@ -0,0 +1,70 @@ +name: Uniro-server CD + +on: + push: + branches: + - be + +jobs: + uniro-ci: + name: Build & Push Docker Image + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'temurin' + + - name: Cache Gradle packages + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + + - name: Create application.properties from secret + run: | + echo "${{ secrets.BE_SPRING_APPLICATION_SECRET }}" > ./uniro_backend/src/main/resources/application.properties + shell: bash + + - name: Build Spring Boot Application + run: | + cd uniro_backend + ./gradlew clean build -x test + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Docker Hub Login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_LOGIN_USERNAME }} + password: ${{ secrets.DOCKERHUB_LOGIN_ACCESSTOKEN }} + + - name: Build & Push Multi-Arch Docker Image + run: | + cd uniro_backend + docker buildx create --use + docker buildx build --platform linux/amd64,linux/arm64 -t uniro5th/uniro-docker-repo:develop --build-arg SPRING_PROFILE=dev --push . + + deploy-run: + name: Deploy to Server + needs: uniro-ci + runs-on: ubuntu-latest + steps: + - name: Run Docker Container on Server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.BE_SERVER_IP }} + username: ${{ secrets.BE_SERVER_USER }} + key: ${{ secrets.BE_SERVER_KEY }} + script: | + cd ~/myapp + chmod +x ./deploy.sh + ./deploy.sh diff --git a/.github/workflows/be-ci.yml b/.github/workflows/be-ci.yml new file mode 100644 index 0000000..c724bfc --- /dev/null +++ b/.github/workflows/be-ci.yml @@ -0,0 +1,42 @@ +name: Uniro-server CI + +on: + pull_request: + branches: + - be + +jobs: + build-springboot: + name: Build and analyze (SpringBoot) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'temurin' + + - name: Cache Gradle packages + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + + - name: Create application.properties from secret + run: | + echo "${{ secrets.BE_SPRING_APPLICATION_SECRET }}" > ./uniro_backend/src/main/resources/application.properties + shell: bash + + - name: Debug application.properties + run: cat ./uniro_backend/src/main/resources/application.properties + + - name: Build and analyze (SpringBoot) + run: | + cd uniro_backend + ./gradlew clean build -x test \ No newline at end of file From 23cec84c9a59fc227825b9d4fbe69cda5f5efb31 Mon Sep 17 00:00:00 2001 From: mikekks Date: Wed, 5 Feb 2025 16:06:10 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[UNI-65]=20fix:=20=EC=8A=A4=ED=94=84?= =?UTF-8?q?=EB=A7=81=20=EB=B2=84=EC=A0=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uniro_backend/build.gradle | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/uniro_backend/build.gradle b/uniro_backend/build.gradle index cbe08a2..f5f78cc 100644 --- a/uniro_backend/build.gradle +++ b/uniro_backend/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.4.2' + id 'org.springframework.boot' version '3.3.8' id 'io.spring.dependency-management' version '1.1.7' id 'org.hibernate.orm' version '6.3.1.Final' } @@ -65,6 +65,9 @@ dependencies { //webClient implementation 'org.springframework.boot:spring-boot-starter-webflux' + + // actuator + implementation 'org.springframework.boot:spring-boot-starter-actuator' } tasks.named('test') { From 3d718caf752ab1f1d561bf732101d7cbb5188028 Mon Sep 17 00:00:00 2001 From: mikekks Date: Wed, 5 Feb 2025 16:06:51 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[UNI-65]=20feat:=20=EC=8A=A4=ED=94=84?= =?UTF-8?q?=EB=A7=81=20=EC=84=9C=EB=B2=84=20=EB=8F=84=EC=BB=A4=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uniro_backend/Dockerfile | 10 ++++++++++ uniro_backend/docker-compose.yml | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 uniro_backend/Dockerfile create mode 100644 uniro_backend/docker-compose.yml diff --git a/uniro_backend/Dockerfile b/uniro_backend/Dockerfile new file mode 100644 index 0000000..e8f6db7 --- /dev/null +++ b/uniro_backend/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:17 + +ARG JAR_FILE=./build/libs/*.jar +ARG SPRING_PROFILE + +COPY ${JAR_FILE} uniro-server.jar + +ENV SPRING_PROFILE=${SPRING_PROFILE} + +ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=${SPRING_PROFILE}" ,"-jar" ,"uniro-server.jar"] \ No newline at end of file diff --git a/uniro_backend/docker-compose.yml b/uniro_backend/docker-compose.yml new file mode 100644 index 0000000..319bb0f --- /dev/null +++ b/uniro_backend/docker-compose.yml @@ -0,0 +1,28 @@ +version: '3.8' + +services: + spring-green: + image: uniro5th/uniro-docker-repo:develop + container_name: spring-green + environment: + - SPRING_PROFILES_ACTIVE=dev + restart: always + ports: + - "8080:8080" + networks: + - my_network1 + + spring-blue: + image: uniro5th/uniro-docker-repo:develop + container_name: spring-blue + environment: + - SPRING_PROFILES_ACTIVE=dev + restart: always + ports: + - "8081:8080" + networks: + - my_network1 + +networks: + my_network1: + external: true From 63d49b046e17597ed0850229db5c2a78c6fe7bdd Mon Sep 17 00:00:00 2001 From: mikekks Date: Wed, 5 Feb 2025 16:07:03 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[UNI-65]=20test:=20test=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softeer5/uniro_backend/node/client/MapClientImplTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/uniro_backend/src/test/java/com/softeer5/uniro_backend/node/client/MapClientImplTest.java b/uniro_backend/src/test/java/com/softeer5/uniro_backend/node/client/MapClientImplTest.java index 98d17b9..b887b25 100644 --- a/uniro_backend/src/test/java/com/softeer5/uniro_backend/node/client/MapClientImplTest.java +++ b/uniro_backend/src/test/java/com/softeer5/uniro_backend/node/client/MapClientImplTest.java @@ -10,12 +10,14 @@ import org.locationtech.jts.geom.Point; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest +@ActiveProfiles("test") public class MapClientImplTest { @Autowired private MapClientImpl mapClientImpl;