From c47bef40cc3b01d0dac1941b9be9ce7229d40af9 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Sat, 26 Feb 2022 20:52:03 +0330 Subject: a working dockerfile --- Dockerfile | 17 +++++++++---- build.gradle.kts | 28 ++++++++++++++-------- docker-compose.yaml | 15 ++++++++---- .../com/terminaldweller/main/MainApplication.java | 2 +- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 03628b8..a421feb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,13 @@ -FROM openjdk:11-jdk-alpine -ARG JAR_FILE=./build/libs/src.jar -COPY ${JAR_FILE} src.jar -ENTRYPOINT ["java", "-jar", "/src.jar"] +FROM gradle:7.3.3-jdk11-alpine AS builder +WORKDIR /home/springapp +COPY --chown=gradle:gradle ./gradlew /home/springapp/ +COPY --chown=gradle:gradle ./settings.gradle.kts /home/springapp/ +COPY --chown=gradle:gradle ./build.gradle.kts /home/springapp/ +RUN gradle wrapper --no-daemon +COPY --chown=gradle:gradle ./src /home/springapp/src +RUN gradle bootJar --no-daemon + +FROM eclipse-temurin:11-jre-alpine +WORKDIR /springapp +COPY --from=builder /home/springapp/build/libs/src.jar ./src.jar +ENTRYPOINT ["java", "-jar", "/springapp/src.jar"] diff --git a/build.gradle.kts b/build.gradle.kts index 4fb985e..d08e6f6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,22 +12,30 @@ repositories { } dependencies { - implementation("org.springframework.boot:spring-boot-starter-data-jdbc") + // implementation("org.springframework.boot:spring-boot-starter-data-jdbc") implementation("org.springframework.boot:spring-boot-starter-web") - runtimeOnly("org.postgresql:postgresql") + // runtimeOnly("org.postgresql:postgresql") testImplementation("org.springframework.boot:spring-boot-starter-test") } -tasks.create("FatJar", Jar::class) { - description = "makes a fatjar" - group = "build" - manifest.attributes["Main-Class"] = "com.terminaldweller.MainApplication" - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - val dependencies = configurations.runtimeClasspath.get().map(::zipTree) - from(dependencies) - with(tasks.jar.get()) +// tasks.create("FatJar", Jar::class) { +// description = "makes a fatjar" +// group = "build" +// manifest.attributes["Main-Class"] = "com.terminaldweller.MainApplication" +// duplicatesStrategy = DuplicatesStrategy.EXCLUDE +// val dependencies = configurations.runtimeClasspath.get().map(::zipTree) +// from(dependencies) +// with(tasks.jar.get()) +// } + +springBoot { + mainClass.set("com.terminaldweller.MainApplication") } +// application { +// mainClass.set("com.terminaldweller.MainApplication") +// } + sourceSets { main { java { diff --git a/docker-compose.yaml b/docker-compose.yaml index f3c7718..f92cc94 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,10 +1,19 @@ version: "3" services: server: + image: spring + build: + context: . + ports: + - "9080:8080" + networks: + - springnet + cap_drop: + - ALL postgres: image: postgres:14-alpine networks: - - dbnet + - springnet volumes: - db-data:/var/lib/postgresql/14/ ports: @@ -19,10 +28,8 @@ services: - pg_user_secret - pg_initdb_args_secret - pg_db_secret - cap_drop: - - ALL networks: - dbnet: + springnet: volumes: db-data: secrets: diff --git a/src/main/java/com/terminaldweller/main/MainApplication.java b/src/main/java/com/terminaldweller/main/MainApplication.java index 3738769..c577139 100644 --- a/src/main/java/com/terminaldweller/main/MainApplication.java +++ b/src/main/java/com/terminaldweller/main/MainApplication.java @@ -1,4 +1,4 @@ -package com.terminaldweller.main; +package com.terminaldweller; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -- cgit v1.2.3