diff --git a/README.md b/README.md index 598a8095f3e50012ea3ab3db05062fb185ad5df2..bd14cc90697496716badcc3492a1ecfb9e60adbe 100644 --- a/README.md +++ b/README.md @@ -37,4 +37,40 @@ System has three authorization roles - **Admin**, **Power Distribution Company E  +## Docker +To run contanariazed application run the command in root folder: + + docker-compose up + +End application with command: + + docker-compose down + +After updates in code run command: + + docker-compose down --rmi all + +Now you can run compose up with code updates :). +Service ports are not changed. + + +If you want to run core microservice locally, run postgres with adminer by following steps: + + - cd ./core + - docker-compose up + +If you want to run statistics microservice locally, run postgres with adminer by following steps: + + - cd ./core + - docker-compose up + +Adminer is a soft enabling developers to view postgres db. +It runs on port defined in docker compose file. +Sign up with adminer with this config.: + + system <postgresql> + server: <name_of_the_container_db> + username: <username_defined_in_docker_compose_file> + password: <password_defined_in_docker_compose_file> + db: (stays empty) diff --git a/core/Dockerfile b/core/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..153d2d324b38dd82fc551490743423e57df7db03 --- /dev/null +++ b/core/Dockerfile @@ -0,0 +1,11 @@ +FROM maven:3.8.3-openjdk-17 AS build + +WORKDIR /app +COPY ./.. /app +RUN mvn clean install + +WORKDIR ./core +RUN mvn clean install + +EXPOSE 8080 +CMD ["mvn", "spring-boot:run"] \ No newline at end of file diff --git a/core/docker-compose.yaml b/core/docker-compose.yaml new file mode 100644 index 0000000000000000000000000000000000000000..14630f9973ff3a4f30c0ac3edba847eaefe63844 --- /dev/null +++ b/core/docker-compose.yaml @@ -0,0 +1,18 @@ +version: '3' +services: + + core-database: + image: postgres:latest + restart: always + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_DB: postgres + ports: + - "5432:5432" + + adminer: + image: adminer + restart: always + ports: + - 8095:8080 diff --git a/core/pom.xml b/core/pom.xml index 65ef20a06630598f27f48815729b359bf064f1d8..1e2d6b3b24ed8ac4a1a590a0b9eda2e6f1cb4454 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -19,9 +19,9 @@ <scope>compile</scope> </dependency> <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>runtime</scope> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>42.5.4</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> diff --git a/core/src/main/resources/application.properties b/core/src/main/resources/application.properties index 69b89983cb2b54a75be402a7d8ff5f4c9cd4c069..070e8b6001edc3e74ec054d705c2ef0bf72f9340 100644 --- a/core/src/main/resources/application.properties +++ b/core/src/main/resources/application.properties @@ -1 +1,5 @@ -spring.h2.console.enabled=true \ No newline at end of file +##spring.h2.console.enabled=true +spring.datasource.url=jdbc:postgresql://localhost:5432/postgres +spring.datasource.username=postgres +spring.datasource.password=password +spring.jpa.hibernate.ddl-auto=create \ No newline at end of file diff --git a/core/src/main/resources/application.yml b/core/src/main/resources/application.yml index 53c22466a95dbb04615999faf6781494d7c5a309..c2e7d43b98aeaaf0975409abb27239b45fa2410a 100644 --- a/core/src/main/resources/application.yml +++ b/core/src/main/resources/application.yml @@ -13,15 +13,15 @@ logging: spring: mvc: log-request-details: true - datasource: - url: jdbc:h2:mem:mydb - username: sa - password: password - driverClassName: org.h2.Driver - jpa: - spring.jpa.database-platform: org.hibernate.dialect.H2Dialect - h2: - console.enabled: true +# datasource: +# url: jdbc:h2:mem:mydb +# username: sa +# password: password +# driverClassName: org.h2.Driver +# jpa: +# spring.jpa.database-platform: org.hibernate.dialect.H2Dialect +# h2: +# console.enabled: true springdoc: # https://springdoc.org/properties.html#_springdoc_openapi_core_properties diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000000000000000000000000000000000000..981da87627483960f7925f63dc3791dbe82d6af9 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,69 @@ +version: '3' +services: + core-service: + build: + context: . + dockerfile: ./core/Dockerfile + environment: + - spring.datasource.username=postgres + - spring.datasource.password=password + - spring.datasource.url=jdbc:postgresql://core-database:5432/postgres + - spring.jpa.hibernate.ddl-auto=create + depends_on: + - core-database + ports: + - "8080:8080" + + statistics-service: + build: + context: . + dockerfile: ./statistics/Dockerfile + environment: + - spring.datasource.username=postgres2 + - spring.datasource.password=password2 + - spring.datasource.url=jdbc:postgresql://statistics-database:5432/postgres + - spring.jpa.hibernate.ddl-auto=create + depends_on: + - statistics-database + ports: + - "8090:8090" + + email-service: + build: + context: . + dockerfile: ./emailmicroservice/Dockerfile + ports: + - "8081:8081" + + electricity-price-service: + build: + context: . + dockerfile: ./microservice4/Dockerfile + ports: + - "8088:8088" + + core-database: + image: postgres:latest + restart: always + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_DB: postgres + ports: + - "5432:5432" + + statistics-database: + image: postgres:latest + restart: always + environment: + POSTGRES_USER: postgres2 + POSTGRES_PASSWORD: password2 + POSTGRES_DB: postgres + ports: + - "5431:5432" + + adminer: + image: adminer + restart: always + ports: + - 8095:8080 diff --git a/emailmicroservice/Dockerfile b/emailmicroservice/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..eaf92758a1bbdafb807d49c26c1b41f5b98e6d0e --- /dev/null +++ b/emailmicroservice/Dockerfile @@ -0,0 +1,11 @@ +FROM maven:3.8.3-openjdk-17 AS build + +WORKDIR /app +COPY ./.. /app +RUN mvn clean install + +WORKDIR ./emailmicroservice +RUN mvn clean install + +EXPOSE 8081 +CMD ["mvn", "spring-boot:run"] \ No newline at end of file diff --git a/emailmicroservice/src/main/resources/application.yaml b/emailmicroservice/src/main/resources/application.yaml index 870a877b9e60e274aedf8fb10dd7824f53120f37..7338fecbf97c855e91219e7a13a54051f5eadcf1 100644 --- a/emailmicroservice/src/main/resources/application.yaml +++ b/emailmicroservice/src/main/resources/application.yaml @@ -1,3 +1,6 @@ +server: + port: 8081 + spring: mail: password: #TODO diff --git a/microservice4/Dockerfile b/microservice4/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..933651eeeb8a5be6e0ddc6d0dad7fb7f6e433bda --- /dev/null +++ b/microservice4/Dockerfile @@ -0,0 +1,11 @@ +FROM maven:3.8.3-openjdk-17 AS build + +WORKDIR /app +COPY ./.. /app +RUN mvn clean install + +WORKDIR ./microservice4 +RUN mvn clean install + +EXPOSE 8088 +CMD ["mvn", "spring-boot:run"] \ No newline at end of file diff --git a/statistics/Dockerfile b/statistics/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d7eec908d6e765aaaf651bfee13d1572cbd8c62c --- /dev/null +++ b/statistics/Dockerfile @@ -0,0 +1,11 @@ +FROM maven:3.8.3-openjdk-17 AS build + +WORKDIR /app +COPY ./.. /app +RUN mvn clean install + +WORKDIR ./statistics +RUN mvn clean install + +EXPOSE 8090 +CMD ["mvn", "spring-boot:run"] \ No newline at end of file diff --git a/statistics/docker-compose.yaml b/statistics/docker-compose.yaml new file mode 100644 index 0000000000000000000000000000000000000000..45f81c9f6f4b89a2fec16dc5e876ddd818365e05 --- /dev/null +++ b/statistics/docker-compose.yaml @@ -0,0 +1,17 @@ +version: '3' +services: + statistics-database: + image: postgres:latest + restart: always + environment: + POSTGRES_USER: postgres2 + POSTGRES_PASSWORD: password2 + POSTGRES_DB: postgres + ports: + - "5431:5432" + + adminer: + image: adminer + restart: always + ports: + - 8095:8080 diff --git a/statistics/pom.xml b/statistics/pom.xml index 22106e989ce3a8cda9dc63ec3e1cefead28ce569..faa287f76a95a1988228283821b2e489842244ae 100644 --- a/statistics/pom.xml +++ b/statistics/pom.xml @@ -9,9 +9,9 @@ </parent> <dependencies> <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>runtime</scope> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>42.5.4</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> diff --git a/statistics/src/main/resources/application.properties b/statistics/src/main/resources/application.properties new file mode 100644 index 0000000000000000000000000000000000000000..ffdc5b2b2bba3c5cc465740588d5ea9db16015b9 --- /dev/null +++ b/statistics/src/main/resources/application.properties @@ -0,0 +1,5 @@ +#spring.h2.console.enabled=true +spring.datasource.url=jdbc:postgresql://localhost:5431/postgres +spring.datasource.username=postgres2 +spring.datasource.password=password2 +spring.jpa.hibernate.ddl-auto=create \ No newline at end of file