From 7496a77213aa5006998519912167d32caf2a173a Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Mon, 10 Nov 2025 15:47:05 +0100 Subject: [PATCH] Add docker image build --- SmartClinicManagementSystem/app/Dockerfile | 13 ++++++++++ SmartClinicManagementSystem/app/build.gradle | 10 +++++--- .../src/main/resources/application.properties | 2 +- .../docker-compose.yml | 24 +++++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 SmartClinicManagementSystem/app/Dockerfile diff --git a/SmartClinicManagementSystem/app/Dockerfile b/SmartClinicManagementSystem/app/Dockerfile new file mode 100644 index 0000000..b67b2ca --- /dev/null +++ b/SmartClinicManagementSystem/app/Dockerfile @@ -0,0 +1,13 @@ +# Step 1: Use Maven with JDK 21 to build the app +FROM gradle:8.14.3-jdk21-alpine AS builder +WORKDIR /app +COPY build.gradle . +COPY src ./src +RUN gradle clean bootJar -DskipTests + +# Step 2: Use lightweight JRE 21 for running the app +FROM eclipse-temurin:21-jre-alpine-3.22 +WORKDIR /app +COPY --from=builder /app/build/libs/app-1.0.0.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/SmartClinicManagementSystem/app/build.gradle b/SmartClinicManagementSystem/app/build.gradle index ce04590..51daf58 100644 --- a/SmartClinicManagementSystem/app/build.gradle +++ b/SmartClinicManagementSystem/app/build.gradle @@ -1,5 +1,9 @@ import org.springframework.boot.gradle.plugin.SpringBootPlugin +plugins { + id 'org.springframework.boot' version '3.5.7' +} + apply plugin: 'java' apply plugin: 'org.springframework.boot' @@ -28,11 +32,11 @@ dependencies { runtimeOnly 'com.mysql:mysql-connector-j' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.6' - testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}" - testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}" + testImplementation "org.junit.jupiter:junit-jupiter-api:5.9.3" + testImplementation "org.junit.jupiter:junit-jupiter-params:5.9.3" testImplementation 'org.springframework.boot:spring-boot-starter-test' - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.9.3" } test { diff --git a/SmartClinicManagementSystem/app/src/main/resources/application.properties b/SmartClinicManagementSystem/app/src/main/resources/application.properties index bc2e1b0..5323a4d 100644 --- a/SmartClinicManagementSystem/app/src/main/resources/application.properties +++ b/SmartClinicManagementSystem/app/src/main/resources/application.properties @@ -10,7 +10,7 @@ spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.open-in-view=false -spring.data.mongodb.uri=mongodb://root:cms@localhost:27017/prescriptions?authSource=admin +spring.data.mongodb.uri=${SPRING_DATA_MONGODB_URI:mongodb://root:cms@localhost:27017/prescriptions?authSource=admin} logging.level.org.springframework.jdbc.datasource.init=DEBUG spring.sql.init.mode=always diff --git a/SmartClinicManagementSystem/docker-compose.yml b/SmartClinicManagementSystem/docker-compose.yml index e243b12..9cbb0f2 100644 --- a/SmartClinicManagementSystem/docker-compose.yml +++ b/SmartClinicManagementSystem/docker-compose.yml @@ -1,4 +1,18 @@ services: + app: + build: + context: ./app + ports: + - "8080:8080" + depends_on: + mysql: + condition: service_healthy + mongo: + condition: service_healthy + environment: + SPRING_DATASOURCE_URL: jdbc:mysql://root:cms@mysql:3306/cms + SPRING_DATA_MONGODB_URI: mongodb://root:cms@mongo:27017/prescriptions?authSource=admin + mysql: image: mysql:8.0 container_name: mysql @@ -9,6 +23,11 @@ services: - mysql-data:/var/lib/mysql ports: - "3306:3306" + healthcheck: + test: ["CMD", "mysql", "-uroot", "-pcms", "-e", "SELECT 1"] + interval: 10s + timeout: 5s + retries: 5 mongo: image: mongo:8.2.1 @@ -21,6 +40,11 @@ services: - mongodb-data:/data/db ports: - "27017:27017" + healthcheck: + test: [ "CMD", "mongosh", "--quiet", "--eval", "db.runCommand({ ping: 1 })" ] + interval: 10s + timeout: 5s + retries: 5 volumes: mysql-data: