From 74be6d4cb74b68fd594babfd608187b36dcd11a9 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 28 Feb 2022 19:31:27 +0100 Subject: [PATCH 1/5] initial data is now loaded using liquibase changelog --- .docker/application.properties.tpl | 3 ++- Dockerfile | 23 +++++++++++++++++++++-- pom.xml | 7 +++++++ src/main/resources/application.properties | 8 +++++--- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/.docker/application.properties.tpl b/.docker/application.properties.tpl index 724438d..75b4f08 100644 --- a/.docker/application.properties.tpl +++ b/.docker/application.properties.tpl @@ -14,4 +14,5 @@ spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true spring.jpa.properties.hibernate.show_sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.use_sql_comments=true -spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true \ No newline at end of file +spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true +spring.liquibase.enabled={{default .Env.PATTERN_ATLAS_FETCH_INITIAL_DATA "false"}} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 57e4a9b..1c28b7e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,16 +7,32 @@ RUN mv target/patternatlas.api-1.2.0-SNAPSHOT.jar target/patternatlas.api-1.2.0- RUN mvn package -DskipTests -PHAL_EXPLORER +#liquibase initial data +ENV PATTERN_ATLAS_FETCH_INITIAL_DATA false +ENV PATTERN_ATLAS_CONTENT_REPOSITORY_URL "https://github.com/PatternAtlas/pattern-atlas-content.git" +ENV PATTERN_ATLAS_PRIVATE_CONTENT_REPOSITORY_URL "git@github.com:PatternAtlas/internal-pattern-atlas-content.git" +ENV PATTERN_ATLAS_CONTENT_REPOSITORY_BRANCH "liquibase_content" + +# install dependencies (git) +RUN apt-get update \ + && apt-get update -qq && apt-get install -qqy \ + git \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN mkdir /tmp/pattern-atlas-content +RUN git clone --single-branch --branch ${PATTERN_ATLAS_CONTENT_REPOSITORY_BRANCH} ${PATTERN_ATLAS_CONTENT_REPOSITORY_URL} /tmp/pattern-atlas-content + FROM openjdk:8 ARG DOCKERIZE_VERSION=v0.6.1 ENV API_PORT 1977 -ENV JDBC_DATABASE_URL localhost +ENV JDBC_DATABASE_URL host.docker.internal ENV JDBC_DATABASE_USERNAME postgres ENV JDBC_DATABASE_PASSWORD postgres ENV JDBC_DATABASE_NAME postgres -ENV JDBC_DATABASE_PORT 5060 +ENV JDBC_DATABASE_PORT 5432 ENV HAL_EXPLORER true RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ @@ -29,6 +45,9 @@ COPY --from=builder /tmp/pattern-atlas-api/target/patternatlas.api-1.2.0-SNAPSHO ADD .docker/application.properties.tpl /var/www/java/application.properties.tpl + +COPY --from=builder /tmp/pattern-atlas-content/liquibase_changelog/*.xml /var/www/java/ + CMD dockerize -template /var/www/java/application.properties.tpl:/var/www/java/application.properties \ && cd /var/www/java/ \ && if [ "$HAL_EXPLORER" = "true" ]; then java -jar api.jar; else java -jar api_no_hal_explorer.jar; fi diff --git a/pom.xml b/pom.xml index 2d5dddc..0c4906d 100644 --- a/pom.xml +++ b/pom.xml @@ -105,6 +105,13 @@ runtime + + + org.liquibase + liquibase-core + 4.8.0 + + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0a91769..5e5540a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,7 @@ server.port=1977 -spring.datasource.url=jdbc:postgresql://localhost:5060/patternatlas -spring.datasource.username=patternatlas -spring.datasource.password=patternatlas +spring.datasource.url=jdbc:postgresql://localhost:5432/patternatlas +spring.datasource.username=postgres +spring.datasource.password=postgres spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true spring.jpa.hibernate.ddl-auto=update @@ -23,3 +23,5 @@ io.github.patternatlas.api.latexrenderer.hostname=localhost io.github.patternatlas.api.latexrenderer.port=5030 # Embedded Tomcat server.servlet.contextPath=/patternatlas +# liquibase file +spring.liquibase.change-log=file:patternatlas_cl.xml From 797ded32f623e88b8c361eebc9042bd00647b5fd Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 1 Mar 2022 10:35:05 +0100 Subject: [PATCH 2/5] initial data is now read on startup from fragmented files --- .docker/copy_initial_data.sh | 12 ++++++++++++ Dockerfile | 15 ++++++--------- src/main/resources/application.properties | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 .docker/copy_initial_data.sh diff --git a/.docker/copy_initial_data.sh b/.docker/copy_initial_data.sh new file mode 100644 index 0000000..679512c --- /dev/null +++ b/.docker/copy_initial_data.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +mkdir /tmp/pattern-atlas-content +git clone --single-branch --branch ${PATTERN_ATLAS_CONTENT_REPOSITORY_BRANCH} ${PATTERN_ATLAS_CONTENT_REPOSITORY_URL} /tmp/pattern-atlas-content + +cp /tmp/pattern-atlas-content/liquibase_changelog/*.xml /var/www/java/ + +if [ "$PATTERN_ATLAS_FETCH_INITIAL_DATA" = "true" ] +then + rm /var/www/java/patternatlas.xml + mv /var/www/java/patternatlas_full.xml /var/www/java/patternatlas.xml +fi diff --git a/Dockerfile b/Dockerfile index 1c28b7e..9988209 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,9 @@ RUN mvn package -DskipTests RUN mv target/patternatlas.api-1.2.0-SNAPSHOT.jar target/patternatlas.api-1.2.0-SNAPSHOT-no-hal-explorer.jar RUN mvn package -DskipTests -PHAL_EXPLORER +FROM openjdk:8 + +ARG DOCKERIZE_VERSION=v0.6.1 #liquibase initial data ENV PATTERN_ATLAS_FETCH_INITIAL_DATA false @@ -20,13 +23,6 @@ RUN apt-get update \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -RUN mkdir /tmp/pattern-atlas-content -RUN git clone --single-branch --branch ${PATTERN_ATLAS_CONTENT_REPOSITORY_BRANCH} ${PATTERN_ATLAS_CONTENT_REPOSITORY_URL} /tmp/pattern-atlas-content - -FROM openjdk:8 - -ARG DOCKERIZE_VERSION=v0.6.1 - ENV API_PORT 1977 ENV JDBC_DATABASE_URL host.docker.internal ENV JDBC_DATABASE_USERNAME postgres @@ -45,10 +41,11 @@ COPY --from=builder /tmp/pattern-atlas-api/target/patternatlas.api-1.2.0-SNAPSHO ADD .docker/application.properties.tpl /var/www/java/application.properties.tpl - -COPY --from=builder /tmp/pattern-atlas-content/liquibase_changelog/*.xml /var/www/java/ +ADD .docker/copy_initial_data.sh /var/www/java/copy_initial_data.sh CMD dockerize -template /var/www/java/application.properties.tpl:/var/www/java/application.properties \ + && chmod +x /var/www/java/copy_initial_data.sh \ + && /var/www/java/copy_initial_data.sh \ && cd /var/www/java/ \ && if [ "$HAL_EXPLORER" = "true" ]; then java -jar api.jar; else java -jar api_no_hal_explorer.jar; fi diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 5e5540a..ee366db 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -24,4 +24,4 @@ io.github.patternatlas.api.latexrenderer.port=5030 # Embedded Tomcat server.servlet.contextPath=/patternatlas # liquibase file -spring.liquibase.change-log=file:patternatlas_cl.xml +spring.liquibase.change-log=file:patternatlas.xml From e31afcb4e2b588b5c2a48285b1873fefa04eeb83 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 1 Mar 2022 12:53:52 +0100 Subject: [PATCH 3/5] changed liquibase conf to support automatic content loading --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9988209..3363ee6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,7 @@ ENV JDBC_DATABASE_URL host.docker.internal ENV JDBC_DATABASE_USERNAME postgres ENV JDBC_DATABASE_PASSWORD postgres ENV JDBC_DATABASE_NAME postgres -ENV JDBC_DATABASE_PORT 5432 +ENV JDBC_DATABASE_PORT 5060 ENV HAL_EXPLORER true RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ From 119062895fb248693e5bd53986463c0d300562f7 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 1 Mar 2022 12:56:52 +0100 Subject: [PATCH 4/5] changed back local configuration --- src/main/resources/application.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ee366db..400ffe5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,7 @@ server.port=1977 -spring.datasource.url=jdbc:postgresql://localhost:5432/patternatlas -spring.datasource.username=postgres -spring.datasource.password=postgres +spring.datasource.url=jdbc:postgresql://localhost:5060/patternatlas +spring.datasource.username=patternatlas +spring.datasource.password=patternatlas spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true spring.jpa.hibernate.ddl-auto=update From 9792add57cb079a29d48954f74721efc111956df Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 1 Mar 2022 14:18:40 +0100 Subject: [PATCH 5/5] API now pulls data from main branch --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3363ee6..e8b2c80 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ ARG DOCKERIZE_VERSION=v0.6.1 ENV PATTERN_ATLAS_FETCH_INITIAL_DATA false ENV PATTERN_ATLAS_CONTENT_REPOSITORY_URL "https://github.com/PatternAtlas/pattern-atlas-content.git" ENV PATTERN_ATLAS_PRIVATE_CONTENT_REPOSITORY_URL "git@github.com:PatternAtlas/internal-pattern-atlas-content.git" -ENV PATTERN_ATLAS_CONTENT_REPOSITORY_BRANCH "liquibase_content" +ENV PATTERN_ATLAS_CONTENT_REPOSITORY_BRANCH "main" # install dependencies (git) RUN apt-get update \