From c7f81ca722f67d9288bfd1739cb1a193c50e4aed Mon Sep 17 00:00:00 2001
From: Ali Dosmukhamedov <ali.dosmukhamedov@student.reutlingen-university.de>
Date: Tue, 17 Dec 2024 23:09:41 +0100
Subject: [PATCH] Version with docker compose

---
 .dockerignore                                 |  4 +++
 .idea/codeStyles/Project.xml                  | 10 ++++++
 .idea/codeStyles/codeStyleConfig.xml          |  5 +++
 .idea/misc.xml                                |  2 +-
 Dockerfile                                    | 21 +++++++++++
 docker-compose.yml                            | 35 +++++++++++++++++++
 gradle.properties.txt                         |  3 ++
 site/build.gradle.kts                         |  2 ++
 .../jvmMain/kotlin/todo/data/MongoDbImp.kt    |  2 +-
 9 files changed, 82 insertions(+), 2 deletions(-)
 create mode 100644 .dockerignore
 create mode 100644 .idea/codeStyles/Project.xml
 create mode 100644 .idea/codeStyles/codeStyleConfig.xml
 create mode 100644 Dockerfile
 create mode 100644 docker-compose.yml
 create mode 100644 gradle.properties.txt

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..30ec52e
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,4 @@
+build/
+.gradle/
+.idea/
+node_modules/
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..1bec35e
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,10 @@
+<component name="ProjectCodeStyleConfiguration">
+  <code_scheme name="Project" version="173">
+    <JetCodeStyleSettings>
+      <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
+    </JetCodeStyleSettings>
+    <codeStyleSettings language="kotlin">
+      <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
+    </codeStyleSettings>
+  </code_scheme>
+</component>
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+<component name="ProjectCodeStyleConfiguration">
+  <state>
+    <option name="USE_PER_PROJECT_SETTINGS" value="true" />
+  </state>
+</component>
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 1cb24d3..c087b6e 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -4,5 +4,5 @@
   <component name="FrameworkDetectionExcludesConfiguration">
     <file type="web" url="file://$PROJECT_DIR$" />
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK" />
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK" />
 </project>
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..0f5bb40
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,21 @@
+FROM gradle:jdk11
+
+# Set the working directory
+WORKDIR /app
+
+# Copy all files to the container
+COPY . .
+
+# Convert gradlew to Unix line endings and make it executable
+RUN sed -i 's/\r$//' gradlew && chmod +x gradlew
+
+
+# Build the app
+RUN ./gradlew clean build --no-daemon
+
+
+# Expose the application port
+EXPOSE 8080
+
+# Run the application with Kobweb
+CMD ["./gradlew", "kobwebStart", "-t"]
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..511aefe
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,35 @@
+version: '3.9'
+services:
+  mongodbservice:
+    container_name: mongo_database
+    image: mongo:5.0
+    restart: always
+    ports:
+      - 27017:27017
+    volumes:
+      - mongo-data:/data/db
+    networks:
+      - todolist-network
+  todolistservice:
+    container_name: kobweb_backend
+    image: gradle:jdk11
+    build:
+      context: .
+      dockerfile: Dockerfile
+    ports:
+      - 8080:8080
+    environment:
+      MONGO_URL: mongodb://mongodbservice:27017
+    depends_on:
+      - mongodbservice
+    networks:
+      - todolist-network
+volumes:
+  mongo-data:
+
+networks:
+  todolist-network:
+    driver: bridge
+
+
+    
\ No newline at end of file
diff --git a/gradle.properties.txt b/gradle.properties.txt
new file mode 100644
index 0000000..643758f
--- /dev/null
+++ b/gradle.properties.txt
@@ -0,0 +1,3 @@
+kotlin.code.style=official
+org.gradle.caching=true
+org.gradle.configuration-cache=true
\ No newline at end of file
diff --git a/site/build.gradle.kts b/site/build.gradle.kts
index bb9e813..1a17768 100644
--- a/site/build.gradle.kts
+++ b/site/build.gradle.kts
@@ -20,6 +20,8 @@ repositories {
 group = "todo"
 version = "1.0-SNAPSHOT"
 
+
+
 kotlin {
     configAsKobwebApplication(includeServer = true)
 
diff --git a/site/src/jvmMain/kotlin/todo/data/MongoDbImp.kt b/site/src/jvmMain/kotlin/todo/data/MongoDbImp.kt
index 3633fd0..a797aea 100644
--- a/site/src/jvmMain/kotlin/todo/data/MongoDbImp.kt
+++ b/site/src/jvmMain/kotlin/todo/data/MongoDbImp.kt
@@ -20,7 +20,7 @@ fun initializeMongo(context: InitApiContext) {
 
 class MongoDbImp(): MongoDb {
 
-    private val client = MongoClient.create()
+    private val client = MongoClient.create(System.getenv("MONGO_URL"))
     private val database = client.getDatabase("todolist")
     private val tasksCollection = database.getCollection<Task>("tasks")
     private val finishedTasksCollection = database.getCollection<Task>("finishedTasks")
-- 
GitLab