diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 80d3537efb62f920a6140073d8a574bc23be4156..9a43a1de1dc7391a92b7ca00366ac6dd31f2f316 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,7 +28,7 @@ create_tag: - /app/prepare-git.sh - /app/set-version-java.sh # generate swagger documentation - - mvn clean compile $MAVEN_CLI_OPTS -DskipTests -Dswagger.skip=false -Dproprietary-repo-url=$PROPRIETARY_REPO_URL + - mvn clean package $MAVEN_CLI_OPTS -DskipTests -Dswagger.skip=false -Dproprietary-repo-url=$PROPRIETARY_REPO_URL - git add doc-files/kypo-adaptive-training-swagger-open-api.yaml - git commit -m "Updated Swagger documentation generated" - /app/tag-and-push.sh @@ -42,6 +42,10 @@ build: script: - mvn clean install $MAVEN_CLI_OPTS -DskipTests -Dproprietary-repo-url=$PROPRIETARY_REPO_URL rules: + - if: '$CI_COMMIT_BRANCH == "master"' + changes: + - $DEPLOYMENT_INFO_VERSION_FILE + when: never - if: '$CI_COMMIT_TAG' changes: - pom.xml diff --git a/Dockerfile b/Dockerfile index f2e954b3bc458bd689e5a221b44bc0be9a133220..f414f0ebb135b6e4c740088f00f56ef440bfd445 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,40 +1,25 @@ +############ BUILD STAGE ############ FROM maven:3.6.2-jdk-11-slim AS build - -## default environment variables for database settings -ARG USERNAME=postgres -ARG PASSWORD=postgres -ARG POSTGRES_DB=kypo-adaptive-training -## rename the artifact id to something else, e.g. kypo-adaptive-training +WORKDIR /app ARG PROJECT_ARTIFACT_ID=kypo-adaptive-training - ## default link to proprietary repository, e.g., Gitlab repository ARG PROPRIETARY_REPO_URL=YOUR-PATH-TO-PROPRIETARY_REPO - -# install -RUN apt-get update && apt-get install -y supervisor postgresql rsyslog netcat - -# configure supervisor -RUN mkdir -p /var/log/supervisor - -# configure postgres -RUN /etc/init.d/postgresql start && \ - su postgres -c "createdb -O \"$USERNAME\" $POSTGRES_DB" && \ - su postgres -c "psql -c \"ALTER USER $USERNAME PASSWORD '$PASSWORD';\"" && \ - /etc/init.d/postgresql stop - -# copy only essential parts -COPY /etc/kypo-adaptive-training.properties /app/etc/kypo-adaptive-training.properties -COPY entrypoint.sh /app/entrypoint.sh -COPY supervisord.conf /app/supervisord.conf COPY pom.xml /app/pom.xml COPY src /app/src +# Build JAR file +RUN mvn clean install -DskipTests -Dproprietary-repo-url=$PROPRIETARY_REPO_URL && \ + cp /app/target/$PROJECT_ARTIFACT_ID-*.jar /app/kypo-adaptive-training.jar +############ RUNNABLE STAGE ############ +FROM openjdk:11-jre-slim WORKDIR /app - -# build adaptive training service -RUN mvn clean install -DskipTests -Dproprietary-repo-url=$PROPRIETARY_REPO_URL && \ - cp /app/target/$PROJECT_ARTIFACT_ID-*.jar /app/kypo-adaptive-training.jar && \ +COPY /etc/kypo-adaptive-training.properties /app/etc/kypo-adaptive-training.properties +COPY entrypoint.sh /app/entrypoint.sh +COPY --from=build /app/kypo-adaptive-training.jar ./ +RUN apt-get update && \ + # Required to use nc command in the wait for it function, see entrypoint.sh + apt-get install -y netcat && \ + # Make a file executable chmod a+x entrypoint.sh - EXPOSE 8082 ENTRYPOINT ["./entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh index 21bd4fff6b8593ff29658db5822b515c8931fa13..a4036cb03288b8f16e0a3a2f3e32968f926455e4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -37,4 +37,4 @@ do wait_for_it ${i} done -exec /usr/bin/supervisord -c /app/supervisord.conf \ No newline at end of file +exec java -Dspring.config.location=/app/etc/kypo-adaptive-training.properties -jar /app/kypo-adaptive-training.jar \ No newline at end of file diff --git a/etc/kypo-adaptive-training.properties b/etc/kypo-adaptive-training.properties index 0d44257e97d9b693788c8bf32d2248790f18ee77..17507d2c6e07802bd97cb935fbefe64d40e7f530 100644 --- a/etc/kypo-adaptive-training.properties +++ b/etc/kypo-adaptive-training.properties @@ -5,15 +5,20 @@ server.port=8082 microservice.name=kypo-adaptive-training # calling user-and-group project -user-and-group-server.uri=http://localhost:8084/kypo2-rest-user-and-group/api/v1 +user-and-group-server.uri=http://localhost:8084/kypo-rest-user-and-group/api/v1 # calling kypo2-openstack openstack-server.uri=http://localhost:8080/kypo-openstack/api/v1 # DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) -spring.datasource.url=jdbc:postgresql://localhost:5432/kypo-adaptive-training -spring.datasource.username=postgres -spring.datasource.password=postgres -spring.datasource.driver-class-name=org.postgresql.Driver +spring.datasource.url=jdbc:h2:mem:training +spring.datasource.username=sa +spring.datasource.password= +spring.datasource.driverClassName=org.h2.Driver + +# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration) +spring.data.jpa.repositories.enabled=true +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.show-sql=false # Jackson (e.g. converting Java 8 dates to ISO format spring.jackson.serialization.write_dates_as_timestamps=false diff --git a/supervisord.conf b/supervisord.conf deleted file mode 100644 index d3d14256dd1ca78e914a406fb0f63c86e5257527..0000000000000000000000000000000000000000 --- a/supervisord.conf +++ /dev/null @@ -1,49 +0,0 @@ -; supervisor config file -[unix_http_server] -file=/var/run/supervisor.sock ; (the path to the socket file) -chmod=0700 ; sockef file mode (default 0700) - -[supervisord] -logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) -pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) -childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP) -nodaemon = true - -; the below section must remain in the config file for RPC -; (supervisorctl/web interface) to work, additional interfaces may be -; added by defining them in separate rpcinterface: sections -[rpcinterface:supervisor] -supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface - -[supervisorctl] -serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket - -; The [include] section can just contain the "files" setting. This -; setting can list multiple files (separated by whitespace or -; newlines). It can also contain wildcards. The filenames are -; interpreted as relative to this file. Included files *cannot* -; include files themselves. - -[program:postgresql] -command=/etc/init.d/postgresql start -startsecs=5 -priority=1 -autostart=true -autorestart=unexpected -exitcodes=0 -startretries=5 -process_name=%(program_name)s-%(process_num)s -stopsignal=TERM - -[program:kypo-adaptive-training-worker] -command=/usr/local/openjdk-11/bin/java -Dspring.config.location=/app/etc/kypo-adaptive-training.properties -jar /app/kypo-adaptive-training.jar -process_name=%(program_name)s-%(process_num)s -startsecs=15 -priority=999 -autostart=true -autorestart=unexpected -exitcodes=0 -startretries=10 -stopsignal=TERM -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0