Skip to content

Commit

Permalink
update dockerfile and entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Yinnii committed Aug 2, 2024
1 parent 4fa4073 commit ddaa62e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 49 deletions.
26 changes: 20 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
FROM gradle:jdk17-alpine AS builder

WORKDIR /tmitocar-service

COPY --chown=gradle:gradle tmitocar-service/build.gradle settings.gradle /tmitocar-service/
COPY --chown=gradle:gradle tmitocar-service/src /tmitocar-service/src
COPY --chown=gradle:gradle gradle.properties /tmitocar-service/gradle.properties

RUN gradle --no-daemon build

# Use a Java base image
FROM openjdk:17-jdk-buster

Expand Down Expand Up @@ -27,12 +37,12 @@ RUN git clone https://gitlab.com/Tech4Comp/tmitocar-tools.git/ tmitocar
RUN chmod -R 777 tmitocar
RUN dos2unix tmitocar/tmitocar.sh
RUN dos2unix tmitocar/feedback.sh
RUN dos2unix /src/gradle.properties
RUN dos2unix gradlew
RUN chmod +x gradlew && ./gradlew build --exclude-task test
# RUN dos2unix /src/gradle.properties
# RUN dos2unix gradlew
# RUN chmod +x gradlew && ./gradlew build --exclude-task test

# Copy the Spring Boot application JAR file into the Docker image
# COPY --from=builder /tmitocar-service/build/libs/*.jar /src/services.openAIService-2.0.0.jar
COPY --from=builder /tmitocar-service/build/libs/*.jar /src/services.tmitocar-3.0.0.jar

# Set environment variables
ENV SERVER_PORT=8080
Expand All @@ -45,9 +55,13 @@ ENV SPRING_DATA_MONGODB_URI=mongodb://localhost:27017/
ENV SPRING_DATA_MONGODB_DATABASE=
ENV SPRING_DATA_MONGODB_USERNAME=
ENV SPRING_DATA_MONGODB_PASSWORD=
ENV XAPI_URL=
ENV XAPI_HOMEPAGE=
ENV PUBLIC_KEY=
ENV PRIVATE_KEY=

# Expose the port that the Spring Boot application is listening on
EXPOSE 8080

# Entry point to run the Spring Boot application
ENTRYPOINT ["java","-jar","src/tmitocar-service/export/jars/services.tmitocar-3.0.0.jar", "--spring.security.oauth2.resourceserver.jwt.issuer-uri=${ISSUER_URI}", "--spring.security.oauth2.resourceserver.jwt.jwk-set-uri=${SET_URI}"]
# Set the entry point to run the docker-entrypoint.sh script
ENTRYPOINT ["/src/docker-entrypoint.sh"]
67 changes: 24 additions & 43 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,52 @@

set -e

# print all comands to console if DEBUG is set
# Print all commands to console if DEBUG is set
if [[ ! -z "${DEBUG}" ]]; then
set -x
fi

# set some helpful variables
# Set some helpful variables
export SERVICE_VERSION=$(awk -F "=" '/service.version/ {print $2}' gradle.properties)
export SERVICE_NAME=$(awk -F "=" '/service.name/ {print $2}' gradle.properties)
export SERVICE_CLASS=$(awk -F "=" '/service.class/ {print $2}' gradle.properties)
export SERVICE=${SERVICE_NAME}.${SERVICE_CLASS}@${SERVICE_VERSION}
export SERVICE_PROPERTY_FILE='etc/services.tmitocar.TmitocarService.properties'
export SERVICE_PROPERTY_FILE='tmitocar-service/build/resources/main/application.properties'


# check mandatory variables
# Check mandatory variables
[[ -z "${PRIVATE_KEY}" ]] && \
echo "Mandatory variable PRIVATE_KEY is not set. Add -e PRIVATE_KEY=privatekey to your arguments." && exit 1
[[ -z "${PUBLIC_KEY}" ]] && \
echo "Mandatory variable PUBLIC_KEY is not set. Add -e PUBLIC_KEY=publickey to your arguments." && exit 1

# optional variables
# Optional variables
[[ -z "${SERVICE_PASSPHRASE}" ]] && export SERVICE_PASSPHRASE='tmitocar'

# wait for any bootstrap host to be available
if [[ ! -z "${BOOTSTRAP}" ]]; then
echo "Waiting for any bootstrap host to become available..."
for host_port in ${BOOTSTRAP//,/ }; do
arr_host_port=(${host_port//:/ })
host=${arr_host_port[0]}
port=${arr_host_port[1]}
if { </dev/tcp/${host}/${port}; } 2>/dev/null; then
echo "${host_port} is available. Continuing..."
break
fi
done
fi

function set_in_service_config {
sed -i "s?${1}[[:blank:]]*=.*?${1}=${2}?g" ${SERVICE_PROPERTY_FILE}
sed -i "s|${1}[[:blank:]]*=.*|${1}=${2}|g" ${SERVICE_PROPERTY_FILE}
}

set_in_service_config privateKey ${PRIVATE_KEY}
set_in_service_config publicKey ${PUBLIC_KEY}
set_in_service_config lrsURL ${LRS_URL}
set_in_service_config lrsAuthTokenLeipzig ${LRS_AUTH_TOKEN_LEIPZIG}
set_in_service_config lrsAuthTokenDresden ${LRS_AUTH_TOKEN_DRESDEN}
set_in_service_config spring.security.oauth2.resourceserver.jwt.issuer-uri ${ISSUER_URI}
set_in_service_config spring.security.oauth2.resourceserver.jwt.jwk-set-uri ${SET_URI}
# set_in_service_config lrsURL ${LRS_URL}
# set_in_service_config lrsAuthTokenLeipzig ${LRS_AUTH_TOKEN_LEIPZIG}
# set_in_service_config lrsAuthTokenDresden ${LRS_AUTH_TOKEN_DRESDEN}

set_in_service_config mongoHost ${MONGO_HOST}
set_in_service_config mongoDB ${MONGO_DB}
set_in_service_config mongoUser ${MONGO_USER}
set_in_service_config mongoPassword ${MONGO_PASSWORD}
set_in_service_config mongoAuth ${MONGO_AUTH}
set_in_service_config spring.data.mongodb.uri ${SPRING_DATA_MONGODB_URI}
set_in_service_config spring.data.mongodb.database ${SPRING_DATA_MONGODB_DATABASE}

set_in_service_config pgsqlHost ${PGSQL_HOST}
set_in_service_config pgsqlPort ${PGSQL_PORT}
set_in_service_config pgsqlUser ${PGSQL_USER}
set_in_service_config pgsqlPassword ${PGSQL_PASSWORD}
set_in_service_config pgsqlDB ${PGSQL_DB}
set_in_service_config spring.datasource.url ${SPRING_DATASOURCE_URL}
set_in_service_config spring.datasource.username ${SPRING_DATASOURCE_USERNAME}
set_in_service_config spring.datasource.password ${SPRING_DATASOURCE_PASSWORD}

set_in_service_config xapiUrl ${XAPI_URL}
set_in_service_config xapiHomepage ${XAPI_HOMEPAGE}
set_in_service_config xapi.url ${XAPI_URL}
set_in_service_config xapi.homepage ${XAPI_HOMEPAGE}

# prevent glob expansion in lib/*
set_in_service_config publicKey ${PUBLIC_KEY}
set_in_service_config privateKey ${PRIVATE_KEY}

# Prevent glob expansion in lib/*
set -f
LAUNCH_COMMAND='java -cp lib/* --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED -s service -p '"${SERVICE_EXTRA_ARGS}"
if [[ ! -z "${BOOTSTRAP}" ]]; then
LAUNCH_COMMAND="${LAUNCH_COMMAND} -b ${BOOTSTRAP}"
fi

# Launch the service using java -jar
exec java -jar /src/services.tmitocar-3.0.0.jar ${SERVICE_EXTRA_ARGS}

0 comments on commit ddaa62e

Please sign in to comment.