NoIssue: Fix for build, run and publish

This commit is contained in:
2026-02-01 21:15:21 +01:00
parent a2fae04892
commit 8f907324ca
7 changed files with 37 additions and 30 deletions

View File

@@ -49,20 +49,25 @@ tasks.withType<JavaCompile>().configureEach {
options.release.set(25) options.release.set(25)
} }
val dockerLibsDir = layout.buildDirectory.dir("docker/libs") val libsDir = layout.buildDirectory.dir("libs")
tasks.register<Sync>("prepareDockerLibs") { tasks.register<Sync>("prepareLibs") {
group = "distribution" group = "distribution"
description = "Copies all runtime dependencies (transitive) to build/docker/libs" description = "Copies runtime deps to build/libs without deleting the app jar"
// Hvis du også vil bygge dit eget jar samtidig, så lad den stå ellers kan du fjerne den. val jarTask = tasks.named<Jar>("jar")
dependsOn(tasks.named("jar")) dependsOn(jarTask)
into(dockerLibsDir) into(libsDir)
// Kun deps (transitivt) // Kun deps (transitivt)
from(configurations.runtimeClasspath) from(configurations.runtimeClasspath)
// Bevar jar-filen som jar-tasken allerede har lagt i build/libs
preserve {
include(jarTask.get().archiveFileName.get())
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE duplicatesStrategy = DuplicatesStrategy.EXCLUDE
} }

View File

@@ -13,13 +13,14 @@ export VERSION_LONG=${VERSION}_${GITHASH}
# Build this artifact # Build this artifact
echo "Building 'NenjimHub v${VERSION_LONG}'..." echo "Building 'NenjimHub v${VERSION_LONG}'..."
./gradlew -Pversion=$VERSION jar prepareDockerLibs ./gradlew -Pversion=$VERSION jar prepareLibs
# Prepare container dependencies # Prepare container dependencies
mkdir -p build/docker/conf mkdir -p build/docker/{conf,libs}
cd build/docker cd build/docker
cp ../../src/main/docker/start.sh start.sh cp ../../src/main/docker/run.sh run.sh
cp ../libs/hubd-impl-ref-*.jar libs cp ../libs/*.jar libs/
cp ../../conf/* conf cp ../../conf/* conf/
sed -e "s|_VERSION_|${VERSION}|g" \ sed -e "s|_VERSION_|${VERSION}|g" \
-e "s|_JREVERSION_|${JREVERSION}|g" \ -e "s|_JREVERSION_|${JREVERSION}|g" \
../../src/main/docker/Dockerfile_template > Dockerfile ../../src/main/docker/Dockerfile_template > Dockerfile

1
libs Symbolic link
View File

@@ -0,0 +1 @@
build/libs

View File

@@ -1,12 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
export VERSION=$(git describe --tags --exact-match 2>/dev/null \
|| git symbolic-ref --short -q HEAD \
|| git rev-parse --short HEAD)
echo "Publishing artifact ($VERSION)..."
./gradlew -Pversion=$VERSION publish
echo "Publishing docker container ($VERSION)..."
./build/docker/publish.sh

1
publishCICD.sh Symbolic link
View File

@@ -0,0 +1 @@
publish.sh

17
run.sh
View File

@@ -1,6 +1,17 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
./gradlew run \ shopt -s nullglob
-Dlog4j.configurationFile="$PWD/config/log4j2.xml" \
--args="foo bar baz" 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=conf/log4j2.xml \
-cp "$CLASSPATH" \
com.r35157.nenjim.hubd.impl.ref.Main

View File

@@ -13,7 +13,7 @@ WORKDIR nenjimhub
RUN mkdir libs RUN mkdir libs
# These dirs are expected to be overshadowed by host mounts # These dirs are expected to be overshadowed by host mounts
RUN mkdir conf logs RUN mkdir conf logs && chown user:user logs
# Set timezone # Set timezone
ENV TZ=Europe/Copenhagen ENV TZ=Europe/Copenhagen
@@ -29,14 +29,14 @@ RUN apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Install application and configuration (Do this as late as possible to be able to reuse layers between builds) # Install application and configuration (Do this as late as possible to be able to reuse layers between builds)
COPY start.sh . COPY run.sh .
COPY conf/* conf/ COPY conf/* conf/
COPY libs/*.jar libs/ COPY libs/*.jar libs/
RUN chmod 755 ./start.sh \ RUN chmod 755 ./run.sh \
&& chmod -R a+rX /usr/local/software/nenjimhub-_VERSION_ && chmod -R a+rX /usr/local/software/nenjimhub-_VERSION_
USER user:user USER user:user
CMD ["./start.sh"] CMD ["./run.sh"]