From 22a909e94e8dd9a4a040a738798f7ea6dcb2f42f Mon Sep 17 00:00:00 2001 From: MarrMika Date: Fri, 5 Jun 2020 17:52:57 +0300 Subject: [PATCH 01/11] Specify a default schema for migration. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 3c0d399..048fc23 100644 --- a/build.gradle +++ b/build.gradle @@ -108,7 +108,7 @@ liquibase { //hibernate entities referenceUrl 'hibernate:spring:org.speech4j.contentservice.entity?dialect=org.hibernate.dialect.PostgreSQL82Dialect' //current db schema - url 'jdbc:postgresql://' + System.getenv('DB_HOST') + ':' + System.getenv('DB_PORT') + '/' + System.getenv('DB_NAME') + url 'jdbc:postgresql://' + System.getenv('DB_HOST') + ':' + System.getenv('DB_PORT') + '/' + System.getenv('DB_NAME') + '?currentSchema=speech4j' username System.getenv('DB_USERNAME') password System.getenv('DB_PASSWORD') referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver' From 8e8706a056005567fe8ab72c88b929eaeff52ab4 Mon Sep 17 00:00:00 2001 From: MarrMika Date: Fri, 5 Jun 2020 22:36:55 +0300 Subject: [PATCH 02/11] Configure jib plugin. Use the latest images in docker-compose.yml --- .travis.yml | 5 ----- build.gradle | 17 +++++++++++++++++ docker-compose.yml | 19 +++++++++++-------- .../controller/AbstractContainer.java | 4 ++-- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index ce0412b..677bb7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,11 +14,6 @@ script: - ./gradlew build --stacktrace - ./gradlew sonarqube --stacktrace -after_success: - - docker build -t speech4j/content-service -f Dockerfile . - - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin - - docker push speech4j/content-service - cache: directories: - '$HOME/.m2/repository' diff --git a/build.gradle b/build.gradle index 048fc23..6786504 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,7 @@ plugins { id 'jacoco' id "org.sonarqube" version "2.8" id 'org.liquibase.gradle' version '2.0.1' + id 'com.google.cloud.tools.jib' version '2.3.0' } group = 'com.speech4j' @@ -87,6 +88,22 @@ jacocoTestReport { project.tasks["sonarqube"].dependsOn "jacocoTestReport" +jib { + from { + image = 'openjdk:11' + } + to { + image = "speech4j/${name}" + auth { + username = System.getenv('DOCKER_ID') + password = System.getenv('DOCKER_PASSWORD') + } + } + container { + ports = ['8080'] + volumes = ["/tmp"] + } +} //Liquibase configurations def changeLogFilePath = "$projectDir/src/main/resources/db/changelog/migrations" diff --git a/docker-compose.yml b/docker-compose.yml index 564934c..5a0317e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,13 +9,16 @@ services: POSTGRES_PASSWORD: postgres POSTGRES_USER: postgres POSTGRES_DB: tenant_db - - app: - image: openjdk:11 - ports: - - "8080:8080" - volumes: - - ./build/libs:/content-service - command: ["java", "--enable-preview", "-jar", "/content-service/content-service-2.2.7 (SNAPSHOT).jar"] + content-service: + image: speech4j/content-service:latest + depends_on: + - db + tenant-service: + image: speech4j/tenant-service:latest + environment: + AWS_SECRET_KEY: ${AWS_SECRET_KEY} + AWS_ACCESS_KEY: ${AWS_ACCESS_KEY} + AWS_BUCKET_NAME: ${AWS_BUCKET_NAME} + AWS_ENDPOINT_URL: ${AWS_ENDPOINT_URL} depends_on: - db \ No newline at end of file diff --git a/src/test/java/org/speech4j/contentservice/controller/AbstractContainer.java b/src/test/java/org/speech4j/contentservice/controller/AbstractContainer.java index d838d11..36f7466 100644 --- a/src/test/java/org/speech4j/contentservice/controller/AbstractContainer.java +++ b/src/test/java/org/speech4j/contentservice/controller/AbstractContainer.java @@ -40,8 +40,8 @@ private void mockRemoteService() { //Setting of default credentials to aws S3 Map credentials = new HashMap<>(); credentials.put("bucket_name", System.getenv("TEST_AWS_BUCKET_NAME")); - credentials.put("access_key", System.getenv("TEST_AWS_ACCESS_KEY")); - credentials.put("secret_key", System.getenv("TEST_AWS_SECRET_KEY")); + credentials.put("access_key", System.getenv("AWS_ACCESS_KEY")); + credentials.put("secret_key", System.getenv("AWS_SECRET_KEY")); credentials.put("endpoint_url", System.getenv("TEST_AWS_ENDPOINT_URL")); ConfigDto config = new ConfigDto(); From c7045efcc6d2fadca6472fc8b5183f09856e7559 Mon Sep 17 00:00:00 2001 From: MarrMika Date: Fri, 5 Jun 2020 22:47:51 +0300 Subject: [PATCH 03/11] Run jib by attaching it to the build task. --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index 6786504..7e69687 100644 --- a/build.gradle +++ b/build.gradle @@ -105,6 +105,8 @@ jib { } } +tasks.build.dependsOn tasks.jib + //Liquibase configurations def changeLogFilePath = "$projectDir/src/main/resources/db/changelog/migrations" def fileCounter = new File(changeLogFilePath).list().length + 1 From af341bba192f98583fee9ea05ede61e53a64af83 Mon Sep 17 00:00:00 2001 From: MarrMika Date: Fri, 5 Jun 2020 23:20:28 +0300 Subject: [PATCH 04/11] Delete Dockerfile. --- Dockerfile | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index b6974de..0000000 --- a/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM openjdk:11 - -ARG JAR_FILE=build/libs/*.jar -COPY ${JAR_FILE} app.jar - -ENTRYPOINT ["java", "--enable-preview", "-jar", "/app.jar"] \ No newline at end of file From aa2ed75f75e0fcad150223a550baba85bea85edd Mon Sep 17 00:00:00 2001 From: MarrMika Date: Tue, 9 Jun 2020 18:18:28 +0300 Subject: [PATCH 05/11] Configure docker-compose.yml by env variables. --- docker-compose.yml | 31 ++++++++++++++++++----------- src/main/resources/application.yaml | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5a0317e..f45a7d3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,19 +6,26 @@ services: ports: - "5432:5432" environment: - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - POSTGRES_DB: tenant_db - content-service: - image: speech4j/content-service:latest - depends_on: - - db + - POSTGRES_PASSWORD=postgres + - POSTGRES_USER=postgres + - POSTGRES_DB=tenant_db tenant-service: image: speech4j/tenant-service:latest environment: - AWS_SECRET_KEY: ${AWS_SECRET_KEY} - AWS_ACCESS_KEY: ${AWS_ACCESS_KEY} - AWS_BUCKET_NAME: ${AWS_BUCKET_NAME} - AWS_ENDPOINT_URL: ${AWS_ENDPOINT_URL} + - DB_URL=jdbc:postgresql://db:5432/tenant_db + - DB_PASSWORD=postgres + - DB_USER=postgres + - AWS_SECRET_KEY=${AWS_SECRET_KEY} + - AWS_ACCESS_KEY=${AWS_ACCESS_KEY} + - AWS_BUCKET_NAME=${AWS_BUCKET_NAME} + - AWS_ENDPOINT_URL=${AWS_ENDPOINT_URL} + depends_on: + - db + content-service: + image: speech4j/content-service:latest + environment: + - DB_URL=jdbc:postgresql://db:5432/tenant_db + - DB_PASSWORD=postgres + - DB_USER=postgres depends_on: - - db \ No newline at end of file + - tenant-service diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 2a1b551..e065a9f 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -21,7 +21,7 @@ db: spring: datasource: driver: org.postgresql.Driver - url: jdbc:postgresql://${db.host}:${db.port}/${db.name} + url: ${DB_URL:jdbc:postgresql://${db.host}:${db.port}/${db.name}} username: ${DB_USERNAME:postgres} password: ${DB_PASSWORD:postgres} liquibase: From 4d226bfcb5e1b5b6d2802b61019da74929157f05 Mon Sep 17 00:00:00 2001 From: MarrMika Date: Tue, 9 Jun 2020 19:05:53 +0300 Subject: [PATCH 06/11] Add tags. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7e69687..14e5c37 100644 --- a/build.gradle +++ b/build.gradle @@ -94,6 +94,7 @@ jib { } to { image = "speech4j/${name}" + tags = ['1.0.0', 'latest'] auth { username = System.getenv('DOCKER_ID') password = System.getenv('DOCKER_PASSWORD') @@ -104,7 +105,6 @@ jib { volumes = ["/tmp"] } } - tasks.build.dependsOn tasks.jib //Liquibase configurations From 57a603414789caf79acc190397cb0017e343dc08 Mon Sep 17 00:00:00 2001 From: MarrMika Date: Wed, 10 Jun 2020 18:24:01 +0300 Subject: [PATCH 07/11] Add spring boot actuator. Configure healthcheck. --- build.gradle | 1 + docker-compose.yml | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 14e5c37..9089d79 100644 --- a/build.gradle +++ b/build.gradle @@ -43,6 +43,7 @@ dependencies { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springdoc:springdoc-openapi-ui:1.3.0' implementation 'io.vavr:vavr:0.10.2' implementation 'com.amazonaws:aws-java-sdk:1.11.762' diff --git a/docker-compose.yml b/docker-compose.yml index f45a7d3..9713c30 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ -version: '3' +version: '2.1' services: - db: + tenant_db: image: postgres restart: always ports: @@ -9,23 +9,42 @@ services: - POSTGRES_PASSWORD=postgres - POSTGRES_USER=postgres - POSTGRES_DB=tenant_db + healthcheck: + test: [ "CMD", "pg_isready", "-d", "tenant_db", "-U", "postgres" ] + timeout: 2s + interval: 1s + retries: 10 + tenant-service: image: speech4j/tenant-service:latest environment: - - DB_URL=jdbc:postgresql://db:5432/tenant_db + - DB_URL=jdbc:postgresql://0.0.0.0:5432/tenant_db - DB_PASSWORD=postgres - DB_USER=postgres - AWS_SECRET_KEY=${AWS_SECRET_KEY} - AWS_ACCESS_KEY=${AWS_ACCESS_KEY} - AWS_BUCKET_NAME=${AWS_BUCKET_NAME} - AWS_ENDPOINT_URL=${AWS_ENDPOINT_URL} + healthcheck: + test: ["CMD", "curl", "--fail", "--silent", "0.0.0.0:8082/actuator/health 2>&1 | grep UP || exit 1"] + timeout: 2s + interval: 1s + retries: 10 depends_on: - - db + db: + condition: service_healthy + content-service: image: speech4j/content-service:latest environment: - - DB_URL=jdbc:postgresql://db:5432/tenant_db + - DB_URL=jdbc:postgresql://tenant_db:5432/tenant_db - DB_PASSWORD=postgres - DB_USER=postgres + healthcheck: + test: ["CMD", "curl", "--fail", "--silent", "0.0.0.0:8080/actuator/health 2>&1 | grep UP || exit 1"] + timeout: 2s + interval: 1s + retries: 10 depends_on: - - tenant-service + tenant_db: + condition: service_healthy \ No newline at end of file From 68ca8ac50878a4e856756ce8218c5d898239a591 Mon Sep 17 00:00:00 2001 From: MarrMika Date: Wed, 10 Jun 2020 20:09:45 +0300 Subject: [PATCH 08/11] Specify ports for images. --- build.gradle | 1 - docker-compose.yml | 16 +++++++++++----- src/main/resources/application.yaml | 2 +- .../controller/AbstractContainer.java | 3 ++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 9089d79..c5fc612 100644 --- a/build.gradle +++ b/build.gradle @@ -102,7 +102,6 @@ jib { } } container { - ports = ['8080'] volumes = ["/tmp"] } } diff --git a/docker-compose.yml b/docker-compose.yml index 9713c30..fcd5ed6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ version: '2.1' services: - tenant_db: + db: image: postgres restart: always ports: @@ -17,8 +17,10 @@ services: tenant-service: image: speech4j/tenant-service:latest + ports: + - "8082:8080" environment: - - DB_URL=jdbc:postgresql://0.0.0.0:5432/tenant_db + - DB_URL=jdbc:postgresql://db:5432/tenant_db - DB_PASSWORD=postgres - DB_USER=postgres - AWS_SECRET_KEY=${AWS_SECRET_KEY} @@ -26,7 +28,7 @@ services: - AWS_BUCKET_NAME=${AWS_BUCKET_NAME} - AWS_ENDPOINT_URL=${AWS_ENDPOINT_URL} healthcheck: - test: ["CMD", "curl", "--fail", "--silent", "0.0.0.0:8082/actuator/health 2>&1 | grep UP || exit 1"] + test: ["CMD", "curl", "--fail", "--silent", "localhost:8082/actuator/health 2>&1 | grep UP || exit 1"] timeout: 2s interval: 1s retries: 10 @@ -36,15 +38,19 @@ services: content-service: image: speech4j/content-service:latest + ports: + - "8080:8080" environment: - DB_URL=jdbc:postgresql://tenant_db:5432/tenant_db - DB_PASSWORD=postgres - DB_USER=postgres + - TENANT-SERVICE_HOST=localhost + - TENANT-SERVICE_PORT=8082 healthcheck: - test: ["CMD", "curl", "--fail", "--silent", "0.0.0.0:8080/actuator/health 2>&1 | grep UP || exit 1"] + test: ["CMD", "curl", "--fail", "--silent", "localhost:8080/actuator/health 2>&1 | grep UP || exit 1"] timeout: 2s interval: 1s retries: 10 depends_on: - tenant_db: + tenant-service: condition: service_healthy \ No newline at end of file diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index e065a9f..d02f59b 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -59,7 +59,7 @@ springdoc: remote: tenant-service: - url: http://localhost:8082/tenants/ + url: http://${TENANT-SERVICE_HOST:localhost}:${TENANT-SERVICE_PORT:8082}/tenants/ # =============================== # S3 diff --git a/src/test/java/org/speech4j/contentservice/controller/AbstractContainer.java b/src/test/java/org/speech4j/contentservice/controller/AbstractContainer.java index 36f7466..28d6955 100644 --- a/src/test/java/org/speech4j/contentservice/controller/AbstractContainer.java +++ b/src/test/java/org/speech4j/contentservice/controller/AbstractContainer.java @@ -51,7 +51,8 @@ private void mockRemoteService() { JsonNode node = new ObjectMapper() .convertValue(Arrays.asList(config), JsonNode.class); //Mocking remote service - wireMockServer = new WireMockServer(WireMockConfiguration.options().port(8082)); + wireMockServer = new WireMockServer(WireMockConfiguration.options() + .port(Integer.parseInt(System.getenv("TENANT-SERVICE_PORT")))); wireMockServer.start(); wireMockServer.stubFor(get(urlEqualTo("/tenants/speech4j/configs")) .willReturn(aResponse() From 3793269566c48527beb56dcdb888fe267e360535 Mon Sep 17 00:00:00 2001 From: MarrMika Date: Wed, 10 Jun 2020 20:45:43 +0300 Subject: [PATCH 09/11] Fix naming of env variables. --- docker-compose.yml | 4 ++-- src/main/resources/application.yaml | 2 +- .../speech4j/contentservice/controller/AbstractContainer.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index fcd5ed6..fb500c9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,8 +44,8 @@ services: - DB_URL=jdbc:postgresql://tenant_db:5432/tenant_db - DB_PASSWORD=postgres - DB_USER=postgres - - TENANT-SERVICE_HOST=localhost - - TENANT-SERVICE_PORT=8082 + - TENANT_SERVICE_HOST=localhost + - TENANT_SERVICE_PORT=8082 healthcheck: test: ["CMD", "curl", "--fail", "--silent", "localhost:8080/actuator/health 2>&1 | grep UP || exit 1"] timeout: 2s diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index d02f59b..81a1be6 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -59,7 +59,7 @@ springdoc: remote: tenant-service: - url: http://${TENANT-SERVICE_HOST:localhost}:${TENANT-SERVICE_PORT:8082}/tenants/ + url: http://${TENANT_SERVICE_HOST:localhost}:${TENANT_SERVICE_PORT:8082}/tenants/ # =============================== # S3 diff --git a/src/test/java/org/speech4j/contentservice/controller/AbstractContainer.java b/src/test/java/org/speech4j/contentservice/controller/AbstractContainer.java index 28d6955..4070ee0 100644 --- a/src/test/java/org/speech4j/contentservice/controller/AbstractContainer.java +++ b/src/test/java/org/speech4j/contentservice/controller/AbstractContainer.java @@ -52,7 +52,7 @@ private void mockRemoteService() { .convertValue(Arrays.asList(config), JsonNode.class); //Mocking remote service wireMockServer = new WireMockServer(WireMockConfiguration.options() - .port(Integer.parseInt(System.getenv("TENANT-SERVICE_PORT")))); + .port(Integer.parseInt(System.getenv("TENANT_SERVICE_PORT")))); wireMockServer.start(); wireMockServer.stubFor(get(urlEqualTo("/tenants/speech4j/configs")) .willReturn(aResponse() From f956b39df859e48a1c76873263abebbf97b9df44 Mon Sep 17 00:00:00 2001 From: MarrMika Date: Thu, 11 Jun 2020 16:21:36 +0300 Subject: [PATCH 10/11] Specify the running tenant-service image on 8082 port in container. Set debug level. --- docker-compose.yml | 2 +- src/main/resources/log4j2.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index fb500c9..c782c5b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,7 +18,7 @@ services: tenant-service: image: speech4j/tenant-service:latest ports: - - "8082:8080" + - "8082:8082" environment: - DB_URL=jdbc:postgresql://db:5432/tenant_db - DB_PASSWORD=postgres diff --git a/src/main/resources/log4j2.yml b/src/main/resources/log4j2.yml index 786f32b..14b1250 100644 --- a/src/main/resources/log4j2.yml +++ b/src/main/resources/log4j2.yml @@ -8,6 +8,6 @@ Configuration: Pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" Loggers: Root: - level: error + level: debug AppenderRef: ref: Console \ No newline at end of file From a4fbed37a8ecd2a4ecb2724ebd85f82c48d40f98 Mon Sep 17 00:00:00 2001 From: MarrMika Date: Mon, 29 Jun 2020 20:13:02 +0300 Subject: [PATCH 11/11] Added dependencies for liquibase runtime to fix problem with logs. --- build.gradle | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index c5fc612..df1ca0b 100644 --- a/build.gradle +++ b/build.gradle @@ -61,9 +61,15 @@ dependencies { testImplementation 'org.testcontainers:postgresql' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' testImplementation "com.github.tomakehurst:wiremock-jre8:2.26.3" - +//Liquibase + liquibaseRuntime 'org.liquibase:liquibase-core:3.8.4' + liquibaseRuntime 'org.postgresql:postgresql:42.2.9' + liquibaseRuntime 'org.springframework.data:spring-data-jpa:2.2.1.RELEASE' + liquibaseRuntime 'org.hibernate:hibernate-core:5.4.10.Final' liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:3.8' - liquibaseRuntime sourceSets.main.runtimeClasspath + liquibaseRuntime 'ch.qos.logback:logback-core:1.2.3' + liquibaseRuntime 'ch.qos.logback:logback-classic:1.2.3' + liquibaseRuntime sourceSets.main.output } test {