diff --git a/build.gradle.kts b/build.gradle.kts index 32b10f4..02f871c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,7 +39,6 @@ dependencies { compileOnly("org.jetbrains:annotations:26.0.2-1") implementation("com.r35157.nenjim:hubd-api:0.1-dev") - implementation("org.apache.poi:poi-ooxml:5.5.1") } java { diff --git a/build.sh b/build.sh index c84c032..8f2d22f 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash set -euo pipefail +JREVERSION=25.0.2-0 + export VERSION=$(git describe --tags --exact-match 2>/dev/null \ || git symbolic-ref --short -q HEAD \ || git rev-parse --short HEAD) @@ -12,19 +14,32 @@ export VERSION_LONG=${VERSION}_${GITHASH} # Build this artifact echo "Building 'NenjimHub v${VERSION_LONG}'..." ./gradlew -Pversion=$VERSION jar prepareDockerLibs - # Prepare container dependencies mkdir -p build/docker/conf cd build/docker -sed -e 's/_VERSION_/'"${VERSION}"'/g' ../../src/main/docker/Dockerfile_template > Dockerfile cp ../../src/main/docker/start.sh start.sh cp ../libs/hubd-impl-ref-*.jar libs cp ../../conf/* conf +sed -e "s|_VERSION_|${VERSION}|g" \ + -e "s|_JREVERSION_|${JREVERSION}|g" \ + ../../src/main/docker/Dockerfile_template > Dockerfile # Build the container -docker build -t r35157/nenjimhub:${VERSION}_amd64 . +GROUP=r35157 +NAME=nenjimhub +BASETAG=dockerreg.r35157.com/${GROUP}/${NAME} +HASHTAG=${BASETAG}:${GITHASH}_amd64 +VERSIONTAG=${BASETAG}:${VERSION}_amd64 +LATESTTAG=${BASETAG}:latest_amd64 +CANONICALNAME=${HASHTAG} + +docker build -t ${CANONICALNAME} . +docker tag ${CANONICALNAME} ${VERSIONTAG} +docker tag ${CANONICALNAME} ${LATESTTAG} # Prepare publishing script -docker tag r35157/nenjimhub:${VERSION}_amd64 r35157/nenjimhub:latest -sed -e 's/_VERSION_/'"${VERSION}"'/g' ../../src/main/docker/publish_template > publish.sh +sed -e "s|_HASHTAG_|${HASHTAG}|g" \ + -e "s|_VERSIONTAG_|${VERSIONTAG}|g" \ + -e "s|_LATESTTAG_|${LATESTTAG}|g" \ + ../../src/main/docker/publish_template.sh > publish.sh chmod 755 publish.sh diff --git a/run.sh b/run.sh index 618b789..2120374 100755 --- a/run.sh +++ b/run.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -euo pipefail -export LOG4J_CONFIGURATION_FILE="$PWD/conf/log4j2.xml" -./gradlew run --args="foo bar baz" +./gradlew run \ + -Dlog4j.configurationFile="$PWD/config/log4j2.xml" \ + --args="foo bar baz" diff --git a/src/main/docker/Dockerfile_template b/src/main/docker/Dockerfile_template index 96ecb0c..57afb5d 100644 --- a/src/main/docker/Dockerfile_template +++ b/src/main/docker/Dockerfile_template @@ -1,39 +1,42 @@ -FROM dockerreg.r35157.com/r35157/jre:24.0.1-4_amd64 +FROM dockerreg.r35157.com/r35157/jre:_JREVERSION__amd64 LABEL maintainer="Minimons " # Setup environment -ENV NENJIMHUB_HOME=/usr/local/software/nenjimhub +ENV APP_HOME=/usr/local/software/nenjimhub WORKDIR /usr/local/software USER root -RUN mkdir nenjimhub-_VERSION_ -RUN ln -s nenjimhub-_VERSION_ nenjimhub + +RUN mkdir nenjimhub-_VERSION_ \ + && ln -s nenjimhub-_VERSION_ nenjimhub WORKDIR nenjimhub RUN mkdir libs # These dirs are expected to be overshadowed by host mounts -RUN mkdir conf logs in out archive - -# Install basic tools -RUN apt-get update -RUN apt-get install -y procps +RUN mkdir conf logs # Set timezone ENV TZ=Europe/Copenhagen +RUN apt-get update RUN apt-get install -y tzdata \ && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \ && echo $TZ > /etc/timezone \ && dpkg-reconfigure -f noninteractive tzdata # Clean-up -RUN apt-get autoremove \ +RUN apt-get autoremove -y \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Install application and configuration (Do this as late as possible to be able to reuse layers between builds) COPY start.sh . -COPY conf/* conf -COPY libs/*.jar libs +COPY conf/* conf/ +COPY libs/*.jar libs/ + +RUN chmod 755 ./start.sh \ + && chmod -R a+rX /usr/local/software/nenjimhub-_VERSION_ + +USER user:user CMD ["./start.sh"] diff --git a/src/main/docker/publish_template b/src/main/docker/publish_template deleted file mode 100644 index 3459999..0000000 --- a/src/main/docker/publish_template +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -set -e - -NAME=nenjimhub -VERSION=_VERSION__amd64 - -VTAG=dockerreg.r35157.com/r35157/${NAME}:${VERSION} -LTAG=dockerreg.r35157.com/r35157/${NAME}:latest - -docker tag r35157/${NAME}:${VERSION} ${VTAG} -docker tag r35157/${NAME}:${VERSION} ${LTAG} - -echo "Publishing of '${VTAG}' and '${LTAG}'..." -docker push ${VTAG} -docker push ${LTAG} - -echo "Publishing completed!" diff --git a/src/main/docker/publish_template.sh b/src/main/docker/publish_template.sh new file mode 100644 index 0000000..5ac51fe --- /dev/null +++ b/src/main/docker/publish_template.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "Publishing '_HASHTAG_', '_VERSIONTAG_' and '_LATESTTAG_'..." +docker push _HASHTAG_ +docker push _VERSIONTAG_ +docker push _LATESTTAG_ + +echo "Publishing completed!" diff --git a/src/main/docker/start.sh b/src/main/docker/start.sh index 08ba75c..87e5c32 100755 --- a/src/main/docker/start.sh +++ b/src/main/docker/start.sh @@ -1,6 +1,17 @@ #!/usr/bin/env bash +set -euo pipefail -CLASSPATH=$(echo libs/*.jar | tr ' ' ':') +shopt -s nullglob -java -Dlog4j.configurationFile=conf/log4j2.xml -cp "$CLASSPATH" com.r35157.nenjim.hubd.impl.ref.Main -sleep 100000 +jars=(libs/*.jar) +if (( ${#jars[@]} == 0 )); then + echo "ERROR: No JARs found in libs/" >&2 + exit 1 +fi + +CLASSPATH=$(IFS=:; echo "${jars[*]}") + +exec java \ + -Dlog4j.configurationFile=/usr/local/software/nenjimhub/conf/log4j2.xml \ + -cp "$CLASSPATH" \ + com.r35157.nenjim.hubd.impl.ref.Main diff --git a/src/main/java/com/r35157/nenjim/hubd/impl/ref/Main.java b/src/main/java/com/r35157/nenjim/hubd/impl/ref/Main.java index 4c94ea5..0480d2d 100644 --- a/src/main/java/com/r35157/nenjim/hubd/impl/ref/Main.java +++ b/src/main/java/com/r35157/nenjim/hubd/impl/ref/Main.java @@ -5,17 +5,27 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class Main { - static void main() throws Exception { - new Main(); + static void main(String[] args) throws Exception { + try { + new Main(args).service(); + } catch(Throwable t) { + log.error("Error initializing NenjimHub - " + t.getMessage()); + } } - public Main() throws Exception { + public Main(String[] args) throws Exception { + hub = new NenjimHubImpl(); log.info("Initializing NenjimHub..."); log.info("Ready!"); - nenjimHub.noop(); + + hub.noop(); Thread.sleep(Long.MAX_VALUE); } + private void service() throws Exception { + } + private static final Logger log = LogManager.getLogger(Main.class); - private static final NenjimHub nenjimHub = new NenjimHubImpl(); + + private final NenjimHub hub; }