Skip to content
Snippets Groups Projects
Commit df897e37 authored by Dominik Pilár's avatar Dominik Pilár
Browse files

Optimize size of the docker image by creating multistage docker build and removing postgre db.

parent a4c09b4c
No related branches found
No related tags found
1 merge request!73Optimize size of the docker image by creating multistage docker build and removing postgre db.
Pipeline #126289 passed with stages
in 3 minutes and 6 seconds
......@@ -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
......
############ 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"]
......@@ -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
......@@ -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
......
; 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment