Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerizing using Jib #2

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 0 additions & 6 deletions Dockerfile

This file was deleted.

31 changes: 28 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -42,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'
Expand All @@ -59,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 {
Expand All @@ -87,6 +95,23 @@ jacocoTestReport {

project.tasks["sonarqube"].dependsOn "jacocoTestReport"

jib {
from {
image = 'openjdk:11'
}
to {
image = "speech4j/${name}"
tags = ['1.0.0', 'latest']
auth {
username = System.getenv('DOCKER_ID')
password = System.getenv('DOCKER_PASSWORD')
}
}
container {
volumes = ["/tmp"]
}
}
tasks.build.dependsOn tasks.jib

//Liquibase configurations
def changeLogFilePath = "$projectDir/src/main/resources/db/changelog/migrations"
Expand All @@ -108,7 +133,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'
Expand Down
55 changes: 45 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,56 @@
version: '3'
version: '2.1'
services:
db:
image: postgres
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: tenant_db
- 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

app:
image: openjdk:11
tenant-service:
image: speech4j/tenant-service:latest
ports:
- "8082:8082"
environment:
- 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}
healthcheck:
test: ["CMD", "curl", "--fail", "--silent", "localhost:8082/actuator/health 2>&1 | grep UP || exit 1"]
timeout: 2s
interval: 1s
retries: 10
depends_on:
db:
condition: service_healthy

content-service:
image: speech4j/content-service:latest
ports:
- "8080:8080"
volumes:
- ./build/libs:/content-service
command: ["java", "--enable-preview", "-jar", "/content-service/content-service-2.2.7 (SNAPSHOT).jar"]
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", "localhost:8080/actuator/health 2>&1 | grep UP || exit 1"]
timeout: 2s
interval: 1s
retries: 10
depends_on:
- db
tenant-service:
condition: service_healthy
4 changes: 2 additions & 2 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/log4j2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private void mockRemoteService() {
//Setting of default credentials to aws S3
Map<String, Object> 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();
Expand All @@ -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()
Expand Down