Skip to content

Commit

Permalink
Merge pull request #6 from averak/feature/2_setup_spanner
Browse files Browse the repository at this point in the history
Spannerを導入
  • Loading branch information
averak authored Oct 15, 2023
2 parents bcc1f13 + 1408866 commit 9cf424f
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 35 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ jobs:
distribution: corretto
java-version: 17
cache: gradle
- uses: google-github-actions/setup-gcloud@v1

- name: start database
run: |
make init_spanner_emulator
- name: backend test
run: |
./gradlew test -x build
make test
lint:
runs-on: ubuntu-latest
Expand All @@ -39,7 +44,7 @@ jobs:

- name: backend lint
run: |
./gradlew spotlessCheck
make lint
build:
runs-on: ubuntu-latest
Expand Down
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
GOOGLE_CLOUD_PROJECT_ID="gsync"

.PHONY: init_spanner_emulator
init_spanner_emulator:
docker-compose up -d
gcloud config configurations create emulator || true
gcloud config set auth/disable_credentials true
gcloud config set project ${GOOGLE_CLOUD_PROJECT_ID}
gcloud config set api_endpoint_overrides/spanner http://localhost:9020/
gcloud spanner instances create gsync --config=emulator-config --description="gsync" --nodes=1
gcloud spanner databases create gsync --instance=gsync

.PHONY: test
test:
./gradlew test

.PHONY: lint
lint:
./gradlew spotlessCheck

.PHONY: format
format:
./gradlew spotlessApply

.PHONY: check_dependencies
check_dependencies:
./gradlew dependencyUpdates -Drevision=release
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ This component provides only reusable features that can be used across various g
* Java OpenJDK 17
* Kotlin 1.9
* Quarkus 3.4
* TiDB 7.1
* Cloud Spanner

### Running the application in dev mode

You can run your application in dev mode that enables live coding.

```shell
docker compose up -d
make init_spanner_emulator
./gradlew quarkusDev
```

Expand Down Expand Up @@ -66,13 +66,13 @@ Or, if you don't have GraalVM installed, you can run the native executable build
[Gradle Versions Plugin](https://github.com/ben-manes/gradle-versions-plugin) checks outdated dependencies.

```shell
$ ./gradlew dependencyUpdates -Drevision=release
make check_dependencies
```

### Run code formatter

This codebase is formatted by [ktlint](https://github.com/pinterest/ktlint).

```shell
./gradlew spotlessApply
make format
```
16 changes: 16 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ val quarkusPlatformArtifactId: String by project
val quarkusPlatformVersion: String by project

dependencies {
// Quarkus
implementation(enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}"))
implementation("io.quarkus:quarkus-kotlin")
implementation("io.quarkus:quarkus-resteasy-reactive-jackson")
Expand All @@ -44,6 +45,21 @@ dependencies {
implementation("io.quarkus:quarkus-config-yaml")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

// GCP
// implementation("io.quarkiverse.googlecloudservices:quarkus-google-cloud-parent:2.5.0")
// implementation("com.google.cloud:google-cloud-spanner:6.51.0")
implementation("io.quarkiverse.googlecloudservices:quarkus-google-cloud-spanner:2.5.0") {
modules {
module("com.google.guava:listenablefuture") {
replacedBy("com.google.guava:guava", "listenablefuture is part of guava")
}
}
}

// utils
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.2")
implementation("com.google.guava:guava:32.1.3-jre")

// test
testImplementation("io.quarkus:quarkus-junit5")
testImplementation("io.github.dvgaba:easy-random-core:6.2.0")
Expand Down
6 changes: 6 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
spanner:
build: ./docker/spanner
ports:
- "9010:9010"
- "9020:9020"
1 change: 1 addition & 0 deletions docker/spanner/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM gcr.io/cloud-spanner-emulator/emulator
41 changes: 41 additions & 0 deletions src/main/kotlin/net/averak/gsync/infrastructure/json/JsonUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.averak.gsync.infrastructure.json

import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.KotlinFeature
import com.fasterxml.jackson.module.kotlin.KotlinModule

class JsonUtils {

companion object {

private val objectMapper = ObjectMapper()
.registerModule(
KotlinModule.Builder()
.withReflectionCacheSize(512)
.configure(KotlinFeature.NullToEmptyCollection, false)
.configure(KotlinFeature.NullToEmptyMap, false)
.configure(KotlinFeature.NullIsSameAsDefault, false)
.configure(KotlinFeature.SingletonSupport, false)
.configure(KotlinFeature.StrictNullChecks, false)
.build(),
)
.registerModule(JavaTimeModule())
.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, true)

@JvmStatic
fun encode(value: Any?): String {
return if (value == null) {
"{}"
} else {
objectMapper.writeValueAsString(value)
}
}

@JvmStatic
fun <T> decode(json: String, clazz: Class<T>): T {
return objectMapper.readValue(json, clazz)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.averak.gsync.infrastructure.spanner

import com.google.cloud.spanner.Spanner
import jakarta.inject.Singleton

@Singleton
class SpannerClient(
private val spanner: Spanner,
)
16 changes: 16 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
quarkus:
application:
name: "gsync"
version: "1.0.0-SNAPSHOT"
# datasource:
# db-kind: spanner
# jdbc:
# url: jdbc:cloudspanner:/projects/${quarkus.google.cloud.project-id}/instances/${quarkus.google.cloud.instance-id}/databases/${quarkus.google.cloud.database-id}
# driver: com.google.cloud.spanner.jdbc.JdbcDriver
google:
cloud:
project-id: ${GOOGLE_CLOUD_PROJECT_ID:gsync}
instance-id: ${GOOGLE_CLOUD_SPANNER_INSTANCE_ID:gsync}
database-id: ${GOOGLE_CLOUD_SPANNER_DATABASE_NAME:gsync}
spanner:
emulator-host: http://localhost:9020
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.averak.gsync.adapter.handler.controller

import net.averak.gsync.AbstractSpec

class AbstractController_IT extends AbstractSpec {
}
29 changes: 0 additions & 29 deletions src/test/kotlin/net/averak/gsync/testutils/JsonUtils.kt

This file was deleted.

Empty file.

0 comments on commit 9cf424f

Please sign in to comment.