From 6ec81a8d4bd27cc42fe1316ab0d11b52aebd6475 Mon Sep 17 00:00:00 2001 From: mirageoasis Date: Tue, 20 Aug 2024 20:21:24 +0900 Subject: [PATCH 01/10] =?UTF-8?q?chore:=20prometheus=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 4208a4c0..ca23869e 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-data-redis' + implementation 'io.micrometer:micrometer-registry-prometheus' // Redisson implementation 'org.redisson:redisson-spring-boot-starter:3.17.6' From b0d9e848ef125088ed4db5e843127ae4145682e5 Mon Sep 17 00:00:00 2001 From: mirageoasis Date: Tue, 20 Aug 2024 20:21:42 +0900 Subject: [PATCH 02/10] =?UTF-8?q?chore:=20version=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index d91a162e..3aec8957 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,4 +1,4 @@ -/version: '3.8' +version: '3.8' services: mysql: image: mysql:8.0.32 From e93ea393370d1fc51270e8ec275c4a41ac24046f Mon Sep 17 00:00:00 2001 From: mirageoasis Date: Tue, 20 Aug 2024 20:42:02 +0900 Subject: [PATCH 03/10] =?UTF-8?q?chore:=20backend-config=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend-config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend-config b/backend-config index 4c5331e6..c77fb71d 160000 --- a/backend-config +++ b/backend-config @@ -1 +1 @@ -Subproject commit 4c5331e614055376ff0d1f4a76a78f961858054c +Subproject commit c77fb71d2fdda0ae42928d5f1fd8ee05791756a0 From 70d5f61c434b43a0d7dacb480969f362db951850 Mon Sep 17 00:00:00 2001 From: mirageoasis Date: Tue, 20 Aug 2024 21:15:03 +0900 Subject: [PATCH 04/10] =?UTF-8?q?chore:=20=EB=A1=9C=EC=BB=AC=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend-config | 2 +- docker/docker-compose.yml | 2 +- scripts/local-end.sh | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 scripts/local-end.sh diff --git a/backend-config b/backend-config index c77fb71d..20885cc2 160000 --- a/backend-config +++ b/backend-config @@ -1 +1 @@ -Subproject commit c77fb71d2fdda0ae42928d5f1fd8ee05791756a0 +Subproject commit 20885cc25e27bd86f571509e4d256b17f90bf88d diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 3aec8957..30525d6c 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -6,7 +6,7 @@ services: container_name: mysql environment: MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: demo + MYSQL_DATABASE: ticketing ports: - "3306:3306" restart: always diff --git a/scripts/local-end.sh b/scripts/local-end.sh new file mode 100644 index 00000000..66904bd6 --- /dev/null +++ b/scripts/local-end.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# 현재 스크립트의 디렉토리로 이동 +cd "$(dirname "$0")" + +# Docker Compose 파일이 있는 디렉토리로 이동 +cd ../docker + +# Docker Compose를 사용하여 서비스 종료 +docker-compose -f docker-compose.yml down \ No newline at end of file From e4ab74bc65e88c9c5d569a7c8192592767d1a859 Mon Sep 17 00:00:00 2001 From: mirageoasis Date: Wed, 21 Aug 2024 10:24:48 +0900 Subject: [PATCH 05/10] =?UTF-8?q?chore:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20wo?= =?UTF-8?q?rkflow=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 51 +++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 66bc167e..1f8f7945 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,10 +1,34 @@ -name: unit test on push +name: test on push on: [ pull_request ] jobs: deploy: - name: unit test + name: test runs-on: ubuntu-latest + services: + mysql: + image: mysql:8.0.32 + ports: + - 3306:3306 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: ticketing + options: >- + --health-cmd "mysqladmin ping -u root -proot" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + redis: + image: redis:7.0.11 + ports: + - 6379:6379 + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - name: checkout uses: actions/checkout@v3 @@ -18,7 +42,28 @@ jobs: distribution: 'temurin' java-version: '17' + - name: Set /etc/hosts for MySQL and Redis + run: | + echo "127.0.0.1 mysql" | sudo tee -a /etc/hosts + echo "127.0.0.1 redis" | sudo tee -a /etc/hosts + + - name: Wait for MySQL to be ready + run: | + until mysqladmin ping -h mysql -u root -proot --silent; do + echo 'waiting for mysql...' + sleep 5 + done + + - name: Wait for Redis to be ready + run: | + until nc -zv redis 6379; do + echo 'waiting for redis...' + sleep 5 + done + + - name: Build with Gradle run: | chmod +x ./gradlew - ./gradlew --info test + ./gradlew copyYml + ./gradlew test From 02d038550c9cc05322181f0860c667fa9d2768e6 Mon Sep 17 00:00:00 2001 From: mirageoasis Date: Wed, 21 Aug 2024 11:21:27 +0900 Subject: [PATCH 06/10] =?UTF-8?q?chore:=20copyYml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index ca23869e..455af41a 100644 --- a/build.gradle +++ b/build.gradle @@ -61,6 +61,7 @@ dependencies { testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor' testImplementation "org.testcontainers:testcontainers:1.20.1" + testImplementation 'org.testcontainers:mysql:1.20.1' testImplementation 'org.testcontainers:junit-jupiter:1.20.1' } @@ -110,14 +111,6 @@ tasks.register('copyYml') { } into("src/main/resources") } - - copy { - duplicatesStrategy = dupStr - from(src) { - include(fileExt) - } - into("src/test/resources") - } } build { From 6ff336f808b2d730e8d8c0cbcbbdd1973de33d67 Mon Sep 17 00:00:00 2001 From: mirageoasis Date: Wed, 21 Aug 2024 11:21:50 +0900 Subject: [PATCH 07/10] =?UTF-8?q?chore:=20test=20=EC=95=84=EB=9E=98?= =?UTF-8?q?=EC=97=90=20=EC=9E=88=EB=8A=94=20yml=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=9D=B8=EC=8B=9D=20=EB=90=98=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d3a1b168..272d24af 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ bin/ !**/src/main/**/bin/ !**/src/test/**/bin/ # src 아래 yml파일 잠금 -**/src/**/*.yml +**/src/main/**/*.yml backend-config/*.yml ### IntelliJ IDEA ### From 075f15a88598289cedb3fcedf37881a65cbabf5b Mon Sep 17 00:00:00 2001 From: mirageoasis Date: Wed, 21 Aug 2024 11:23:37 +0900 Subject: [PATCH 08/10] =?UTF-8?q?chore:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BB=A8=ED=85=8C=EC=9D=B4=EB=84=88=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/TestContainerStarter.java | 25 ++++++++++++++++++- src/test/resources/application.yml | 18 +++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/application.yml diff --git a/src/test/java/com/thirdparty/ticketing/support/TestContainerStarter.java b/src/test/java/com/thirdparty/ticketing/support/TestContainerStarter.java index d71aff86..a36927d5 100644 --- a/src/test/java/com/thirdparty/ticketing/support/TestContainerStarter.java +++ b/src/test/java/com/thirdparty/ticketing/support/TestContainerStarter.java @@ -3,6 +3,7 @@ import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.MySQLContainer; import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers @@ -12,14 +13,36 @@ public class TestContainerStarter { private static final int REDIS_PORT = 6379; private static final GenericContainer REDIS; + private static final String MYSQL_IMAGE = "mysql:8.0.32"; + private static final int MYSQL_PORT = 3306; + private static final MySQLContainer MYSQL; + static { REDIS = new GenericContainer<>(REDIS_IMAGE).withExposedPorts(REDIS_PORT).withReuse(true); REDIS.start(); + + MYSQL = + new MySQLContainer<>(MYSQL_IMAGE) + .withExposedPorts(MYSQL_PORT) + .withUsername("root") + .withPassword("root") + .withDatabaseName("ticketing") + .withReuse(false); + MYSQL.start(); } @DynamicPropertySource - private static void registerRedisProperties(DynamicPropertyRegistry registry) { + private static void registerProperties(DynamicPropertyRegistry registry) { registry.add("spring.data.redis.host", REDIS::getHost); registry.add("spring.data.redis.port", () -> REDIS.getMappedPort(REDIS_PORT).toString()); + + String mysqlUrl = + String.format( + "jdbc:mysql://%s:%s/ticketing", + MYSQL.getHost(), MYSQL.getMappedPort(MYSQL_PORT)); + + registry.add("spring.datasource.url", () -> mysqlUrl); + registry.add("spring.datasource.username", () -> "root"); + registry.add("spring.datasource.password", () -> "root"); } } diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 00000000..012371a2 --- /dev/null +++ b/src/test/resources/application.yml @@ -0,0 +1,18 @@ +spring: + data: + redis: + host: localhost + port: 6379 + datasource: + url: jdbc:mysql://localhost:3306/ticketing + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver + jpa: + hibernate: + ddl-auto: create-drop + +jwt: + issuer: test + expiry-seconds: 1800 + secret: thisisjusttestaccesssecretsodontworry \ No newline at end of file From 47c5c96ea2cbe76278c6039998e1415aec22683f Mon Sep 17 00:00:00 2001 From: mirageoasis Date: Wed, 21 Aug 2024 11:24:02 +0900 Subject: [PATCH 09/10] =?UTF-8?q?chore:=20workflow=20=EB=A1=A4=EB=B0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 51 +++----------------------------------- 1 file changed, 3 insertions(+), 48 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f8f7945..66bc167e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,34 +1,10 @@ -name: test on push +name: unit test on push on: [ pull_request ] jobs: deploy: - name: test + name: unit test runs-on: ubuntu-latest - services: - mysql: - image: mysql:8.0.32 - ports: - - 3306:3306 - env: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: ticketing - options: >- - --health-cmd "mysqladmin ping -u root -proot" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - - redis: - image: redis:7.0.11 - ports: - - 6379:6379 - options: >- - --health-cmd "redis-cli ping" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - steps: - name: checkout uses: actions/checkout@v3 @@ -42,28 +18,7 @@ jobs: distribution: 'temurin' java-version: '17' - - name: Set /etc/hosts for MySQL and Redis - run: | - echo "127.0.0.1 mysql" | sudo tee -a /etc/hosts - echo "127.0.0.1 redis" | sudo tee -a /etc/hosts - - - name: Wait for MySQL to be ready - run: | - until mysqladmin ping -h mysql -u root -proot --silent; do - echo 'waiting for mysql...' - sleep 5 - done - - - name: Wait for Redis to be ready - run: | - until nc -zv redis 6379; do - echo 'waiting for redis...' - sleep 5 - done - - - name: Build with Gradle run: | chmod +x ./gradlew - ./gradlew copyYml - ./gradlew test + ./gradlew --info test From babc7da6b604402074b08322fe0952c3d505544a Mon Sep 17 00:00:00 2001 From: mirageoasis Date: Wed, 21 Aug 2024 11:24:48 +0900 Subject: [PATCH 10/10] =?UTF-8?q?chore:=20=EC=83=88=EB=A1=9C=EC=9A=B4=20ym?= =?UTF-8?q?l=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend-config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend-config b/backend-config index 20885cc2..1937897c 160000 --- a/backend-config +++ b/backend-config @@ -1 +1 @@ -Subproject commit 20885cc25e27bd86f571509e4d256b17f90bf88d +Subproject commit 1937897ca5f9355d72fecfc7064e5140b6e3b010