NoIssue: A lot of cleanup and generalizations
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@
|
|||||||
|
|
||||||
# Ignore Gradle build output directory
|
# Ignore Gradle build output directory
|
||||||
build
|
build
|
||||||
|
/logs/
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
|
id("application")
|
||||||
id("maven-publish")
|
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)")
|
throw GradleException("You must set -Pversion=... (use publish.sh / publishCICD.sh)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
mainClass.set("com.r35157.nenjim.kicker.impl.ref.KickerImpl")
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
|
|
||||||
@@ -46,6 +51,23 @@ tasks.withType<JavaCompile> {
|
|||||||
options.compilerArgs.add("--enable-preview")
|
options.compilerArgs.add("--enable-preview")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val dockerLibsDir = layout.buildDirectory.dir("docker/libs")
|
||||||
|
|
||||||
|
tasks.register<Sync>("prepareDockerLibs") {
|
||||||
|
group = "distribution"
|
||||||
|
description = "Copies all runtime dependencies (transitive) to build/docker/libs"
|
||||||
|
|
||||||
|
// Hvis du også vil bygge dit eget jar samtidig, så lad den stå – ellers kan du fjerne den.
|
||||||
|
dependsOn(tasks.named("jar"))
|
||||||
|
|
||||||
|
into(dockerLibsDir)
|
||||||
|
|
||||||
|
// Kun deps (transitivt)
|
||||||
|
from(configurations.runtimeClasspath)
|
||||||
|
|
||||||
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
create<MavenPublication>("mavenJava") {
|
create<MavenPublication>("mavenJava") {
|
||||||
|
|||||||
43
build.sh
43
build.sh
@@ -1,6 +1,45 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
JREVERSION=25.0.2-0
|
||||||
|
|
||||||
export VERSION=$(git describe --tags --exact-match 2>/dev/null \
|
export VERSION=$(git describe --tags --exact-match 2>/dev/null \
|
||||||
|| git symbolic-ref --short -q HEAD \
|
|| git symbolic-ref --short -q HEAD \
|
||||||
|| git rev-parse --short HEAD)
|
|| git rev-parse --short HEAD)
|
||||||
|
|
||||||
echo "Building $VERSION..."
|
GITHASH=$(git rev-parse --short=8 HEAD)
|
||||||
./gradlew -Pversion=$VERSION jar
|
|
||||||
|
export VERSION_LONG=${VERSION}_${GITHASH}
|
||||||
|
|
||||||
|
# Build this artifact
|
||||||
|
echo "Building 'NenjimKicker v${VERSION_LONG}'..."
|
||||||
|
./gradlew -Pversion=$VERSION jar prepareDockerLibs
|
||||||
|
# Prepare container dependencies
|
||||||
|
mkdir -p build/docker/conf
|
||||||
|
cd build/docker
|
||||||
|
cp ../../src/main/docker/start.sh start.sh
|
||||||
|
cp ../libs/kicker-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
|
||||||
|
GROUP=r35157
|
||||||
|
NAME=nenjimkicker
|
||||||
|
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
|
./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/NenjimKicker.log"
|
||||||
|
filePattern="logs/NenjimKicker-%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,6 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
export VERSION=$(git describe --tags --exact-match 2>/dev/null \
|
export VERSION=$(git describe --tags --exact-match 2>/dev/null \
|
||||||
|| git symbolic-ref --short -q HEAD \
|
|| git symbolic-ref --short -q HEAD \
|
||||||
|| git rev-parse --short HEAD)
|
|| git rev-parse --short HEAD)
|
||||||
|
|
||||||
echo "Building and publishing $VERSION..."
|
echo "Publishing artifact to local Maven repo ($VERSION)..."
|
||||||
./gradlew -Pversion=$VERSION publishToMavenLocal
|
./gradlew -Pversion=$VERSION publishToMavenLocal
|
||||||
|
|
||||||
|
echo "Publishing docker container to public 'dockerreg.r35157.com' ($VERSION)..."
|
||||||
|
./build/docker/publish.sh
|
||||||
|
|||||||
6
run.sh
Executable file
6
run.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
./gradlew run \
|
||||||
|
-Dlog4j.configurationFile="$PWD/config/log4j2.xml" \
|
||||||
|
--args="foo bar baz"
|
||||||
42
src/main/docker/Dockerfile_template
Normal file
42
src/main/docker/Dockerfile_template
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
FROM dockerreg.r35157.com/r35157/jre:_JREVERSION__amd64
|
||||||
|
|
||||||
|
LABEL maintainer="Minimons <minimons@r35157.com>"
|
||||||
|
|
||||||
|
# Setup environment
|
||||||
|
ENV APP_HOME=/usr/local/software/nenjimkicker
|
||||||
|
WORKDIR /usr/local/software
|
||||||
|
USER root
|
||||||
|
|
||||||
|
RUN mkdir nenjimkicker-_VERSION_ \
|
||||||
|
&& ln -s nenjimkicker-_VERSION_ nenjimkicker
|
||||||
|
WORKDIR nenjimkicker
|
||||||
|
RUN mkdir libs
|
||||||
|
|
||||||
|
# These dirs are expected to be overshadowed by host mounts
|
||||||
|
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 -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/
|
||||||
|
|
||||||
|
RUN chmod 755 ./start.sh \
|
||||||
|
&& chmod -R a+rX /usr/local/software/nenjimkicker-_VERSION_
|
||||||
|
|
||||||
|
USER user:user
|
||||||
|
|
||||||
|
CMD ["./start.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/start.sh
Executable file
17
src/main/docker/start.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=/usr/local/software/nenjimkicker/conf/log4j2.xml \
|
||||||
|
-cp "$CLASSPATH" \
|
||||||
|
com.r35157.nenjim.kicker.impl.ref.Main
|
||||||
31
src/main/java/com/r35157/nenjim/kicker/impl/ref/Main.java
Normal file
31
src/main/java/com/r35157/nenjim/kicker/impl/ref/Main.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package com.r35157.nenjim.kicker.impl.ref;
|
||||||
|
|
||||||
|
import com.r35157.nenjim.kicker.NenjimKicker;
|
||||||
|
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 NenjimKicker - " + t.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Main(String[] args) throws Exception {
|
||||||
|
kicker = new NenjimKickerImpl();
|
||||||
|
log.info("Initializing NenjimKicker...");
|
||||||
|
log.info("Ready!");
|
||||||
|
|
||||||
|
kicker.noop();
|
||||||
|
Thread.sleep(Long.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void service() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Logger log = LogManager.getLogger(Main.class);
|
||||||
|
|
||||||
|
private final NenjimKicker kicker;
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.r35157.nenjim.kicker.impl.ref;
|
package com.r35157.nenjim.kicker.impl.ref;
|
||||||
|
|
||||||
import com.r35157.nenjim.kicker.Kicker;
|
|
||||||
import com.r35157.nenjim.kicker.NenjimProcess;
|
|
||||||
import com.r35157.nenjim.hubd.Context;
|
import com.r35157.nenjim.hubd.Context;
|
||||||
|
import com.r35157.nenjim.kicker.NenjimKicker;
|
||||||
|
import com.r35157.nenjim.kicker.NenjimProcess;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -11,13 +11,15 @@ import java.util.HashMap;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class KickerImpl implements Kicker {
|
public class NenjimKickerImpl implements NenjimKicker {
|
||||||
|
|
||||||
static void main() throws Exception {
|
public NenjimKickerImpl() throws InterruptedException {
|
||||||
new KickerImpl();
|
lock = new Object();
|
||||||
}
|
running = 0;
|
||||||
|
processes = new ConcurrentHashMap<>();
|
||||||
|
processThreads = new ConcurrentHashMap<>();
|
||||||
|
nextProcessId = new AtomicInteger(1);
|
||||||
|
|
||||||
public KickerImpl() throws InterruptedException {
|
|
||||||
startProcess("com.r35157.nenjim.kicker.impl.ref.Dummy");
|
startProcess("com.r35157.nenjim.kicker.impl.ref.Dummy");
|
||||||
|
|
||||||
log.info("Waiting for all processes to finish!");
|
log.info("Waiting for all processes to finish!");
|
||||||
@@ -95,11 +97,11 @@ public class KickerImpl implements Kicker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Logger log = LogManager.getLogger(KickerImpl.class);
|
private static final Logger log = LogManager.getLogger(NenjimKickerImpl.class);
|
||||||
|
|
||||||
private final Object lock = new Object();
|
private int running;
|
||||||
private int running = 0;
|
private final Object lock;
|
||||||
private final ConcurrentHashMap<Integer, NenjimProcess> processes = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<Integer, NenjimProcess> processes;
|
||||||
private final ConcurrentHashMap<Integer, Thread> processThreads = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<Integer, Thread> processThreads;
|
||||||
private final AtomicInteger nextProcessId = new AtomicInteger(1);
|
private final AtomicInteger nextProcessId;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user