Skip to content

Commit

Permalink
[modules]: refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
vlaship committed Jan 22, 2024
1 parent ff451c9 commit 7448b6b
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
uses: docker/build-push-action@v3
with:
context: .
file: ./jvm.Dockerfile
file: ./unpacked.Dockerfile
22 changes: 7 additions & 15 deletions backoffice-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ plugins {
id("org.springframework.boot")
id("io.spring.dependency-management")
id("dev.vlaship.lombok")
alias(libs.plugins.git.properties)
id("dev.vlaship.unpack")
id("dev.vlaship.git-properties")
}

val jwtVersion = "0.12.3" // "0.11.5" works with graalvm
Expand All @@ -12,19 +13,23 @@ val mapstructVersion = "1.5.5.Final"
val preLiquibaseVersion = "1.5.0"
val openTelemetryVersion = "2.0.0"
val micrometerVersion = "1.2.2"
val findbugsVersion = "3.0.2"

dependencies {
implementation(project(":backoffice-api"))

// avoid warnings
compileOnly("com.google.code.findbugs:jsr305:$findbugsVersion")

// security
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("io.jsonwebtoken:jjwt-api:$jwtVersion")
implementation("io.jsonwebtoken:jjwt-impl:$jwtVersion")
implementation("io.jsonwebtoken:jjwt-jackson:$jwtVersion")

// web
implementation("org.springframework.boot:spring-boot-starter-web")
implementation(libs.springdoc)
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-validation")

// mapper
Expand All @@ -47,19 +52,6 @@ dependencies {
testImplementation("org.springframework.security:spring-security-test")
}

gitProperties {
dateFormat = "yyyy-MM-dd HH:mm:ssZ"
dateFormatTimeZone = "GMT"
keys = arrayListOf("git.branch", "git.commit.id", "git.commit.id.abbrev", "git.commit.time", "git.tags")
}

tasks.named<Test>("test") {
useJUnitPlatform()
}

// task unpack
task("unpack", type = Copy::class) {
dependsOn("build")
from(zipTree(tasks.bootJar.get().archiveFile.get()))
into("build/unpacked")
}
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:
jvm-api:
build:
context: .
dockerfile: jvm.Dockerfile
dockerfile: gradle.Dockerfile
restart: unless-stopped
ports:
- "18080:18080"
Expand Down
3 changes: 3 additions & 0 deletions gradle-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ plugins {

dependencies {
implementation(libs.kotlin.gradle.plugin)
implementation(libs.graalvm.gradle.plugin)
implementation(libs.spring.boot.gradle.plugin)
implementation(libs.git.properties.gradle.plugin)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id("com.gorylenko.gradle-git-properties")
}

gitProperties {
dateFormat = "yyyy-MM-dd HH:mm:ssZ"
dateFormatTimeZone = "GMT"
keys = arrayListOf("git.branch", "git.commit.id", "git.commit.id.abbrev", "git.commit.time", "git.tags")
}
31 changes: 15 additions & 16 deletions gradle-plugins/src/main/kotlin/dev.vlaship.graalvm.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
plugins {
id("java-library")
// id("org.graalvm.buildtools.native")
id("org.graalvm.buildtools.native")
}

//graalvmNative {
// binaries {
// named("main") {
// imageName.set("app")
// useFatJar.set(true)
// }
// }
// binaries.all {
// buildArgs.add("--verbose")
// resources.autodetect()
// }
//
// toolchainDetection.set(true)
//}
graalvmNative {
binaries {
named("main") {
imageName.set("app")
useFatJar.set(true)
}
}
binaries.all {
buildArgs.add("--verbose")
resources.autodetect()
}

toolchainDetection.set(true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ java {
targetCompatibility = javaVersion
toolchain { languageVersion.set(JavaLanguageVersion.of(javaVersion.majorVersion)) }
}

tasks.withType<Test> {
useJUnitPlatform()
}
14 changes: 14 additions & 0 deletions gradle-plugins/src/main/kotlin/dev.vlaship.unpack.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.task

plugins {
id("java-library")
id("org.springframework.boot")
}

// task unpack
task("unpack", type = Copy::class) {
dependsOn("build")
from(zipTree(tasks.bootJar.get().archiveFile.get()))
into("build/unpacked")
}
4 changes: 2 additions & 2 deletions jvm.Dockerfile → gradle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FROM azul/zulu-openjdk-alpine:21 AS builder

# Set the working directory inside the container
WORKDIR /upacked
WORKDIR /

# Copy the source code into the container
COPY . .
Expand All @@ -12,7 +12,7 @@ COPY . .
RUN ./gradlew clean backoffice-app:unpack -x test --no-daemon

# Unpack the jar
ARG UNPACKED=backoffice-app/build/unpacked
ARG UNPACKED=/backoffice-app/build/unpacked

COPY ${UNPACKED}/BOOT-INF/lib /upacked/app/lib
COPY ${UNPACKED}/META-INF /upacked/app/META-INF
Expand Down
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ openApiVersion = "2.3.0"
springBootVersion = "3.2.2"
springDepManVersion = "1.1.4"
kotlinGradlePluginVersion = "1.9.22"
graalvmGradlePluginVersion = "0.9.28"
gitPropertiesGradlePluginVersion = "2.4.1"

[libraries]
springdoc = { module = "org.springdoc:springdoc-openapi-starter-webmvc-ui", version.ref = "openApiVersion" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinGradlePluginVersion" }
graalvm-gradle-plugin = { module = "org.graalvm.buildtools.native:org.graalvm.buildtools.native.gradle.plugin", version.ref = "graalvmGradlePluginVersion" }
spring-boot-gradle-plugin = { module = "org.springframework.boot:spring-boot-gradle-plugin", version.ref = "springBootVersion" }
git-properties-gradle-plugin = { module = "com.gorylenko.gradle-git-properties:gradle-git-properties", version.ref = "gitPropertiesGradlePluginVersion" }

[plugins]
spring-boot = { id = "org.springframework.boot", version.ref = "springBootVersion" }
spring-dependency-management = { id = "io.spring.dependency-management", version.ref = "springDepManVersion" }
git-properties = { id = "com.gorylenko.gradle-git-properties", version = "2.4.1" }
33 changes: 33 additions & 0 deletions unpacked.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
### Build stage
# Builder
FROM alpine:latest AS builder

# Set the working directory inside the container
WORKDIR /

# Copy unpacked into the container
COPY . .

# Unpack the jar
ARG UNPACKED=/backoffice-app/build/unpacked

COPY ${UNPACKED}/BOOT-INF/lib /upacked/app/lib
COPY ${UNPACKED}/META-INF /upacked/app/META-INF
COPY ${UNPACKED}/BOOT-INF/classes /upacked/app

### Run stage
# Create a minimal production image
FROM azul/zulu-openjdk-alpine:21-jre-headless

# Set the working directory inside the container
WORKDIR /app

# Avoid running code as a root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

# Copy only the necessary dirs and files from the builder stage
COPY --from=builder /upacked/app /app

# Run the binary when the container starts
ENTRYPOINT ["java", "-cp", "/app:/app/lib/*", "dev.vlaship.backoffice.App"]

0 comments on commit 7448b6b

Please sign in to comment.