diff --git a/.gitignore b/.gitignore index c426c32..2713573 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,5 @@ out/ /.nb-gradle/ ### VS Code ### -.vscode/ \ No newline at end of file +.vscode/ +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ec97a32 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM gradle:7-jdk11 AS build +COPY --chown=gradle:gradle . /home/gradle/src +WORKDIR /home/gradle/src +RUN gradle buildFatJar --no-daemon + +FROM openjdk:11 +EXPOSE 3002 +RUN mkdir /app +COPY --from=build /home/gradle/src/.env /home/gradle/src/build/libs/*.jar /app/ + +ENV PORT=3002 +ENTRYPOINT ["java","-jar","/app/schools-all.jar"] diff --git a/build.gradle.kts b/build.gradle.kts index 96ef556..ab50d7c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -45,7 +45,7 @@ dependencies { implementation("org.jetbrains.exposed:exposed-dao:$exposed_version") implementation("org.jetbrains.exposed:exposed-jdbc:$exposed_version") implementation("org.jetbrains.exposed:exposed-java-time:$exposed_version") - implementation("com.h2database:h2:$h2_version") + implementation("com.impossibl.pgjdbc-ng:pgjdbc-ng:0.8.9") testImplementation("io.ktor:ktor-server-tests-jvm") testImplementation("io.ktor:ktor-server-test-host-jvm") diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..a4438e4 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,33 @@ +version: "3.8" + +services: + schools: + build: . + ports: + - "3002:3002" + networks: + - docker_network + depends_on: + - db + + db: + image: postgres:16-alpine + restart: always + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=schools + ports: + - '5004:5432' + networks: + - docker_network + volumes: + - db:/var/lib/postgresql/data + +volumes: + db: + driver: local + +networks: + docker_network: + name: wulkanowy_network diff --git a/src/main/kotlin/io/github/wulkanowy/schools/Application.kt b/src/main/kotlin/io/github/wulkanowy/schools/Application.kt index f7555f2..8c05a48 100644 --- a/src/main/kotlin/io/github/wulkanowy/schools/Application.kt +++ b/src/main/kotlin/io/github/wulkanowy/schools/Application.kt @@ -7,7 +7,7 @@ import io.ktor.server.engine.* import io.ktor.server.netty.* fun main() { - embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module) + embeddedServer(Netty, port = 3002, host = "0.0.0.0", module = Application::module) .start(wait = true) } diff --git a/src/main/kotlin/io/github/wulkanowy/schools/DatabaseFactory.kt b/src/main/kotlin/io/github/wulkanowy/schools/DatabaseFactory.kt index b40427e..cb4332d 100644 --- a/src/main/kotlin/io/github/wulkanowy/schools/DatabaseFactory.kt +++ b/src/main/kotlin/io/github/wulkanowy/schools/DatabaseFactory.kt @@ -9,10 +9,12 @@ import org.jetbrains.exposed.sql.transactions.transaction object DatabaseFactory { fun init() { - val driverClassName = "org.h2.Driver" - val jdbcURL = "jdbc:h2:file:./build/db" - val database = Database.connect(jdbcURL, driverClassName) - + val database = Database.connect( + url = "jdbc:pgsql://localhost:5004/schools", + driver = "com.impossibl.postgres.jdbc.PGDriver", + user = "postgres", + password = "postgres", + ) transaction(database) { SchemaUtils.create(LoginEvents)