From f30ea1e657cfc6409c9a6c99970e8ca056f11880 Mon Sep 17 00:00:00 2001 From: miguel-merlin Date: Mon, 18 Nov 2024 03:24:44 -0500 Subject: [PATCH] Modififed Dockerfile and Dockercompose --- Dockerfile | 25 +++--------------- docker-compose.prod.yaml | 32 +++++++++++++++++++++++ docker-compose.yaml | 2 +- src/main/resources/application.properties | 8 +++--- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index ac18cf0..ae445c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,5 @@ -FROM gradle:7.6.1-jdk17-alpine AS build +FROM openjdk:17 WORKDIR /app -COPY . . -RUN gradle build -x test --no-daemon +COPY build/libs/*.jar app.jar -# Run stage -FROM eclipse-temurin:17-jre-alpine -WORKDIR /app - -# Create a non-root user -RUN addgroup -S spring && adduser -S spring -G spring -USER spring:spring - -# Copy the jar file from build stage -COPY --from=build /app/build/libs/*.jar app.jar - -# Environment variables for database connection -ENV SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/blueprint -ENV SPRING_DATASOURCE_USERNAME=postgres -ENV SPRING_DATASOURCE_PASSWORD=postgres - -EXPOSE 8080 - -ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/docker-compose.prod.yaml b/docker-compose.prod.yaml index e69de29..9c22425 100644 --- a/docker-compose.prod.yaml +++ b/docker-compose.prod.yaml @@ -0,0 +1,32 @@ +services: + blueprint_admin_backend: + env_file: ".env" + build: + context: . + dockerfile: Dockerfile + environment: + - DATABASE_URL=jdbc:postgresql://postgres:5432/${POSTGRES_DB} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + ports: + - '8080:8080' + depends_on: + - postgres + + postgres: + env_file: ".env" + image: postgres:latest + restart: always + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + logging: + options: + max-size: "10m" + max-file: "3" + ports: + - '5432:5432' + volumes: + - ./postgres-data:/var/lib/postgresql/data + - ./initdb_prod:/docker-entrypoint-initdb.d \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index c1b76b0..3d4dbc3 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,6 +1,6 @@ services: postgres: - image: postgres:10.5 + image: postgres:latest restart: always environment: - POSTGRES_USER=${POSTGRES_USER} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 85d3825..ebfa2ff 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,8 +4,10 @@ spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.format_sql=true -spring.datasource.url=jdbc:postgresql://localhost:5432/postgres -spring.datasource.username=blueprint_admin_backend -spring.datasource.password=postgres +spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/postgres} +spring.datasource.username=${SPRING_DATASOURCE_USERNAME:blueprint_admin_backend} +spring.datasource.password=${SPRING_DATASOURCE_PASSWORD:postgres} + +spring.profiles.active=${SPRING_PROFILES_ACTIVE:dev} blueprint_yaml.api.baseurl = https://auth.api.sitblueprint.com/api/v1 \ No newline at end of file