From cd176dc975bdc26834a0078ab8f5c7ac0ca6094b Mon Sep 17 00:00:00 2001 From: Omid Mohkamkar Date: Wed, 1 May 2024 01:15:50 +0330 Subject: [PATCH] dockerize iam-api --- Dockerfile | 25 +++++++++++++++++++ docker-compose.yml | 25 ++++++++++++------- iam-api/Dockerfile | 13 ++++++++++ .../main/resources/application-dev.properties | 10 +------- .../resources/application-prod.properties | 10 +------- .../src/main/resources/application.properties | 13 ---------- 6 files changed, 56 insertions(+), 40 deletions(-) create mode 100644 Dockerfile create mode 100644 iam-api/Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b2b3fa9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM maven:3.8.3-openjdk-17 AS build + +# Set the working directory +WORKDIR /app + +# Copy the source code +COPY ./iam-api . + +# Build the project +RUN mvn clean package -DskipTests + +# Create the final image with the built JAR file +FROM openjdk:17-jdk-slim + +# Set the working directory +WORKDIR /opt/iam-aas + +# Copy the JAR file +COPY --from=build /app/target/iam-api-2.0.2.jar ./application.jar + +# Expose the port +EXPOSE 8000 + +# Run the application +ENTRYPOINT ["java", "-jar", "./application.jar"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 846eeae..99ea7d5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=iam-password ports: - - "5432" + - "5432:5432" healthcheck: test: "pg_isready -U postgres" @@ -51,15 +51,22 @@ services: labels: org.springframework.boot.ignore: true - pgadmin-main: - image: dpage/pgadmin4 + iam-api: + image: omidmk567/iam-aas:1.0.0 + container_name: iam-api environment: - PGADMIN_DEFAULT_EMAIL: omidmk567@gmail.com - PGADMIN_DEFAULT_PASSWORD: admin + - SPRING_DATASOURCE_URL=jdbc:postgresql://iam-postgres:5432/iam + - SPRING_DATASOURCE_USERNAME=postgres + - SPRING_DATASOURCE_PASSWORD=iam-password + - SPRING_DATASOURCE_DRIVER_CLASS_NAME=org.postgresql.Driver + - APP_IAM_AAS_KEYCLOAK_BASE_URL=http://keycloak:8080 + - APP_IAM_AAS_KEYCLOAK_MASTER_REALM=master + - APP_IAM_AAS_KEYCLOAK_MASTER_USERNAME=admin + - APP_IAM_AAS_KEYCLOAK_MASTER_PASSWORD=admin + - APP_IAM_AAS_KEYCLOAK_MASTER_CLIENT_ID=admin-cli + - APP_IAM_AAS_KEYCLOAK_AUTH_REALM=IAM-aaS depends_on: - - keycloak-db - iam-api-db + - keycloak ports: - - '5051:80' - labels: - org.springframework.boot.ignore: true + - "8000:8000" \ No newline at end of file diff --git a/iam-api/Dockerfile b/iam-api/Dockerfile new file mode 100644 index 0000000..a435017 --- /dev/null +++ b/iam-api/Dockerfile @@ -0,0 +1,13 @@ +FROM openjdk:17-jdk-slim + +# Set the working directory +WORKDIR /opt/iam-aas + +# Copy the JAR file +COPY ./target/iam-api-2.0.2.jar ./application.jar + +# Expose the port +EXPOSE 8000 + +# Run the application +ENTRYPOINT ["java", "-jar", "./application.jar"] \ No newline at end of file diff --git a/iam-api/src/main/resources/application-dev.properties b/iam-api/src/main/resources/application-dev.properties index ae2a7b2..8406fcf 100644 --- a/iam-api/src/main/resources/application-dev.properties +++ b/iam-api/src/main/resources/application-dev.properties @@ -12,20 +12,12 @@ spring.jpa.hibernate.ddl-auto=create-drop # Flyway spring.flyway.enabled=false -# Keycloak -app.iam-aas.keycloak.base-url=http://localhost:8080 -app.iam-aas.keycloak.master-realm=master -app.iam-aas.keycloak.master-username=admin -app.iam-aas.keycloak.master-password=admin -app.iam-aas.keycloak.master-client-id=admin-cli -app.iam-aas.keycloak.auth-realm=IAM-aaS - # Keycloak OAuth2 Resource Server spring.security.oauth2.resourceserver.jwt.issuer-uri=${app.iam-aas.keycloak.base-url}/realms/${app.iam-aas.keycloak.auth-realm} spring.security.oauth2.resourceserver.jwt.jwk-set-uri=${app.iam-aas.keycloak.base-url}/realms/${app.iam-aas.keycloak.auth-realm}/protocol/openid-connect/certs app.iam-aas.jwt.role.converter.clients=iam-admins,iam-customers # Docker compose -spring.docker.compose.enabled=true +spring.docker.compose.enabled=false spring.docker.compose.file=../docker-compose.yml spring.docker.compose.lifecycle-management=start_only diff --git a/iam-api/src/main/resources/application-prod.properties b/iam-api/src/main/resources/application-prod.properties index 9f24c02..e3c652a 100644 --- a/iam-api/src/main/resources/application-prod.properties +++ b/iam-api/src/main/resources/application-prod.properties @@ -5,20 +5,12 @@ app.iam-aas.cors.allowed-origins=http://localhost:3000 spring.jpa.show-sql=false spring.jpa.hibernate.ddl-auto=update -# Keycloak -app.iam-aas.keycloak.base-url=http://localhost:8080 -app.iam-aas.keycloak.master-realm=master -app.iam-aas.keycloak.master-username=admin -app.iam-aas.keycloak.master-password=admin -app.iam-aas.keycloak.master-client-id=admin-cli -app.iam-aas.keycloak.auth-realm=IAM-aaS - # Keycloak OAuth2 Resource Server spring.security.oauth2.resourceserver.jwt.issuer-uri=${app.iam-aas.keycloak.base-url}/realms/${app.iam-aas.keycloak.auth-realm} spring.security.oauth2.resourceserver.jwt.jwk-set-uri=${app.iam-aas.keycloak.base-url}/realms/${app.iam-aas.keycloak.auth-realm}/protocol/openid-connect/certs app.iam-aas.jwt.role.converter.clients=iam-admins,iam-customers # Docker compose -spring.docker.compose.enabled=true +spring.docker.compose.enabled=false spring.docker.compose.file=../docker-compose.yml spring.docker.compose.lifecycle-management=start_and_stop diff --git a/iam-api/src/main/resources/application.properties b/iam-api/src/main/resources/application.properties index e7798d4..7f2c09a 100644 --- a/iam-api/src/main/resources/application.properties +++ b/iam-api/src/main/resources/application.properties @@ -13,11 +13,6 @@ app.iam-aas.cost-factor=1 app.iam-aas.fail-on-mail-error=false # Database & JPA -spring.datasource.url=jdbc:h2:mem:iam-db -spring.datasource.driver-class-name=org.h2.Driver -spring.datasource.username=sa -spring.datasource.password=password -spring.h2.console.enabled=true spring.jpa.properties.hibernate.event.merge.entity_copy_observer=allow spring.jpa.show-sql=true spring.jpa.hibernate.ddl-auto=update @@ -30,14 +25,6 @@ spring.flyway.enabled=true spring.data.web.pageable.default-page-size=10 spring.data.web.pageable.max-page-size=100 -# Keycloak -app.iam-aas.keycloak.base-url=http://localhost:8080 -app.iam-aas.keycloak.master-realm=master -app.iam-aas.keycloak.master-username=omidmk -app.iam-aas.keycloak.master-password=omidmk -app.iam-aas.keycloak.master-client-id=admin-cli -app.iam-aas.keycloak.auth-realm=iam-aas - # Keycloak OAuth2 Resource Server spring.security.oauth2.resourceserver.jwt.issuer-uri=${app.iam-aas.keycloak.base-url}/realms/${app.iam-aas.keycloak.auth-realm} spring.security.oauth2.resourceserver.jwt.jwk-set-uri=${app.iam-aas.keycloak.base-url}/realms/${app.iam-aas.keycloak.auth-realm}/protocol/openid-connect/certs