Compare commits
17 Commits
| Author | SHA256 | Date | |
|---|---|---|---|
| 214a9b7322 | |||
| ce76ce8977 | |||
| bc661c9e54 | |||
| f9a6183ad1 | |||
| 77121d7251 | |||
| e93f06784c | |||
| 8f907324ca | |||
| a2fae04892 | |||
| d3e859a094 | |||
| cd8d00bd8d | |||
| f7c9cf908e | |||
| 12e9571b2d | |||
| 861310d7b4 | |||
|
|
8788604336 | ||
|
|
3fb271e710 | ||
|
|
7db2a439bf | ||
| 3bd4708e17 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build
|
||||
/logs/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
id("java")
|
||||
id("application")
|
||||
id("maven-publish")
|
||||
}
|
||||
|
||||
@@ -9,6 +10,10 @@ if (version == "UNSET" && gradle.startParameter.taskNames.any { it.startsWith("p
|
||||
throw GradleException("You must set -Pversion=... (use publish.sh / publishCICD.sh)")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set("com.r35157.nenjim.hubd.impl.ref.Main")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
|
||||
@@ -28,17 +33,42 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains:annotations:26.0.1")
|
||||
implementation("log4j:log4j:1.2.17")
|
||||
implementation("com.r35157.nenjim:hubd-api:0.0.0")
|
||||
implementation(platform("org.apache.logging.log4j:log4j-bom:2.25.2"))
|
||||
implementation("org.apache.logging.log4j:log4j-api")
|
||||
runtimeOnly("org.apache.logging.log4j:log4j-core")
|
||||
compileOnly("org.jetbrains:annotations:26.0.2-1")
|
||||
|
||||
implementation("com.r35157.nenjim:hubd-api:0.1-dev")
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain { languageVersion.set(JavaLanguageVersion.of(24)) }
|
||||
toolchain { languageVersion.set(JavaLanguageVersion.of(25)) }
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
options.release.set(24)
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release.set(25)
|
||||
}
|
||||
|
||||
val libsDir = layout.buildDirectory.dir("libs")
|
||||
|
||||
tasks.register<Sync>("prepareLibs") {
|
||||
group = "distribution"
|
||||
description = "Copies runtime deps to build/libs without deleting the app jar"
|
||||
|
||||
val jarTask = tasks.named<Jar>("jar")
|
||||
dependsOn(jarTask)
|
||||
|
||||
into(libsDir)
|
||||
|
||||
// Kun deps (transitivt)
|
||||
from(configurations.runtimeClasspath)
|
||||
|
||||
// Bevar jar-filen som jar-tasken allerede har lagt i build/libs
|
||||
preserve {
|
||||
include(jarTask.get().archiveFileName.get())
|
||||
}
|
||||
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
||||
44
build.sh
44
build.sh
@@ -1,6 +1,46 @@
|
||||
#!/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)
|
||||
|
||||
echo "Building $VERSION..."
|
||||
./gradlew -Pversion=$VERSION jar
|
||||
GITHASH=$(git rev-parse --short=8 HEAD)
|
||||
|
||||
export VERSION_LONG=${VERSION}_${GITHASH}
|
||||
|
||||
# Build this artifact
|
||||
echo "Building 'NenjimHub v${VERSION_LONG}'..."
|
||||
./gradlew -Pversion=$VERSION jar prepareLibs
|
||||
|
||||
# Prepare container dependencies
|
||||
mkdir -p build/docker/{conf,libs}
|
||||
cd build/docker
|
||||
cp ../../src/main/docker/run.sh run.sh
|
||||
cp ../libs/*.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
|
||||
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
|
||||
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
|
||||
|
||||
3
clean.sh
3
clean.sh
@@ -1 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
./gradlew clean ; rm -rf build
|
||||
|
||||
23
conf/log4j2.xml
Normal file
23
conf/log4j2.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<RollingFile name="File"
|
||||
fileName="logs/NenjimHub.log"
|
||||
filePattern="logs/NenjimHub-%d{yyyy-MM-dd}-%i.log.gz">
|
||||
<PatternLayout pattern="%d{ISO8601} %-5p %c - %m%n"/>
|
||||
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
|
||||
<SizeBasedTriggeringPolicy size="50 MB"/>
|
||||
</Policies>
|
||||
|
||||
<DefaultRolloverStrategy max="14"/>
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<Root level="info">
|
||||
<AppenderRef ref="File"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -1,5 +1,5 @@
|
||||
org.gradle.java.installations.auto-detect=true
|
||||
org.gradle.java.installations.fromEnv=JAVA_HOME
|
||||
org.gradle.java.installations.paths=/usr/local/software/java/jfx-24
|
||||
org.gradle.java.installations.paths=/usr/local/software/java/jfx-25
|
||||
org.gradle.java.installations.auto-download=false
|
||||
org.gradle.configuration-cache=true
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-all.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
#!/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 "Building and publishing $VERSION..."
|
||||
echo "Publishing artifact to local Maven repo ($VERSION)..."
|
||||
./gradlew -Pversion=$VERSION publishToMavenLocal
|
||||
|
||||
echo "Publishing docker container to public 'dockerreg.r35157.com' ($VERSION)..."
|
||||
./build/docker/publish.sh
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
export VERSION=$(git describe --tags --exact-match 2>/dev/null \
|
||||
|| git symbolic-ref --short -q HEAD \
|
||||
|| git rev-parse --short HEAD)
|
||||
|
||||
echo "Building and publishing (CI/CD) $VERSION..."
|
||||
./gradlew -Pversion=$VERSION publish
|
||||
1
publishCICD.sh
Symbolic link
1
publishCICD.sh
Symbolic link
@@ -0,0 +1 @@
|
||||
publish.sh
|
||||
@@ -1 +1 @@
|
||||
rootProject.name = "hubd-impl-ref"
|
||||
rootProject.name = "hubd-impl_ref"
|
||||
|
||||
43
src/main/docker/Dockerfile_template
Normal file
43
src/main/docker/Dockerfile_template
Normal file
@@ -0,0 +1,43 @@
|
||||
FROM dockerreg.r35157.com/r35157/jre:_JREVERSION__amd64
|
||||
|
||||
LABEL maintainer="Minimons <minimons@r35157.com>"
|
||||
|
||||
# Setup environment
|
||||
ENV APP_HOME=/usr/local/software/nenjimhub
|
||||
WORKDIR /usr/local/software
|
||||
USER root
|
||||
|
||||
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 && chown user:user 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 -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 run.sh .
|
||||
COPY conf/* conf/
|
||||
COPY libs/*.jar libs/
|
||||
|
||||
RUN chown root:root -R conf
|
||||
RUN chmod 755 ./run.sh \
|
||||
&& chmod -R a+rX /usr/local/software/nenjimhub-_VERSION_
|
||||
|
||||
USER user:user
|
||||
|
||||
CMD ["./run.sh"]
|
||||
|
||||
9
src/main/docker/publish_template.sh
Normal file
9
src/main/docker/publish_template.sh
Normal file
@@ -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!"
|
||||
17
src/main/docker/run.sh
Executable file
17
src/main/docker/run.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
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
|
||||
19
src/main/docker/stack.yml
Normal file
19
src/main/docker/stack.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
version: '3.9'
|
||||
|
||||
services:
|
||||
nenjimhub:
|
||||
hostname: nenjimhub
|
||||
image: dockerreg.r35157.com/r35157/nenjimhub:latest
|
||||
deploy:
|
||||
replicas: 1
|
||||
resources:
|
||||
limits:
|
||||
memory: 128m
|
||||
restart_policy:
|
||||
condition: any
|
||||
delay: 5s
|
||||
max_attempts: 3
|
||||
window: 120s
|
||||
volumes:
|
||||
- /home/op/nenjimhub/conf:/usr/local/software/nenjimhub/conf
|
||||
- /home/op/nenjimhub/logs:/usr/local/software/nenjimhub/logs
|
||||
3
src/main/docker/up_stack
Executable file
3
src/main/docker/up_stack
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
docker stack deploy --compose-file /home/op/stack.yml stack --detach=true
|
||||
31
src/main/java/com/r35157/nenjim/hubd/impl/ref/Main.java
Normal file
31
src/main/java/com/r35157/nenjim/hubd/impl/ref/Main.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.nenjim.hubd.NenjimHub;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class 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(String[] args) throws Exception {
|
||||
hub = new NenjimHubImpl();
|
||||
log.info("Initializing NenjimHub...");
|
||||
log.info("Ready!");
|
||||
|
||||
hub.noop();
|
||||
Thread.sleep(Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
private void service() throws Exception {
|
||||
}
|
||||
|
||||
private static final Logger log = LogManager.getLogger(Main.class);
|
||||
|
||||
private final NenjimHub hub;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.nenjim.hubd.NenjimHub;
|
||||
import com.r35157.nenjim.hubd.NenjimJournal;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NenjimHubImpl implements NenjimHub {
|
||||
@Override
|
||||
public void noop() {
|
||||
log.debug("NOOP executed.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void monitorJournal(@NotNull NenjimJournal nenjimJournal) {
|
||||
log.warn("monitorJournal IS NOT IMPLEMENTED!");
|
||||
}
|
||||
|
||||
|
||||
private static final Logger log = LogManager.getLogger(NenjimHubImpl.class);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.nenjim.hubd.SomeInterface;
|
||||
|
||||
public class SomeImpl implements SomeInterface {
|
||||
public String concat(String x, String y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
public void divideByZero() throws ArithmeticException {
|
||||
int a = 0/0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user