From 506a142fb2dcc98941e799a6b04052bdac248f50 Mon Sep 17 00:00:00 2001
From: Strongest Number 9 <16169054+StrongestNumber9@users.noreply.github.com>
Date: Mon, 11 Nov 2024 14:54:50 +0200
Subject: [PATCH] Rpm package (#13)
* Create rpm packaging workflow
* Depend on java headless
* Do explicit mappings, move files around a bit
* Fixes RAT mapping
* Check for log4j2.xml as well before starting
* Fixes license
---
.github/workflows/release.yaml | 43 +++++
.gitignore | 1 +
pom.xml | 5 +-
rpm/rpm.pom.xml | 173 ++++++++++++++++++
rpm/src/opt/teragrep/rlp_11/etc/log4j2.xml | 16 ++
.../teragrep/rlp_11/etc}/rlp_11.properties | 0
rpm/src/usr/lib/systemd/system/rlp_11.service | 15 ++
.../usr/lib/systemd/system/rlp_11@.service | 15 ++
.../com/teragrep/rlp_11/ConnectionTest.java | 2 +-
src/test/resources/connect.properties | 24 +++
10 files changed, 292 insertions(+), 2 deletions(-)
create mode 100644 .github/workflows/release.yaml
create mode 100644 rpm/rpm.pom.xml
create mode 100644 rpm/src/opt/teragrep/rlp_11/etc/log4j2.xml
rename {etc => rpm/src/opt/teragrep/rlp_11/etc}/rlp_11.properties (100%)
create mode 100644 rpm/src/usr/lib/systemd/system/rlp_11.service
create mode 100644 rpm/src/usr/lib/systemd/system/rlp_11@.service
create mode 100644 src/test/resources/connect.properties
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
new file mode 100644
index 0000000..d5ee394
--- /dev/null
+++ b/.github/workflows/release.yaml
@@ -0,0 +1,43 @@
+name: Publish
+
+on:
+ release:
+ types: [published]
+
+jobs:
+ upload:
+ name: Upload
+ runs-on: ubuntu-latest
+ permissions:
+ packages: write
+ contents: write
+
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Set up JDK 11
+ uses: actions/setup-java@v4
+ with:
+ java-version: '11'
+ distribution: 'temurin'
+ server-id: github
+ settings-path: ${{ github.workspace }}
+
+ - name: Build jar
+ run: mvn --batch-mode -Drevision=${{ github.event.release.tag_name }} -Dsha1= -Dchangelist= clean package
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Build rpm
+ run: cd rpm/ && mvn --batch-mode -Drevision=${{ github.event.release.tag_name }} -Dsha1= -Dchangelist= package -f rpm.pom.xml
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Attach jar and rpm to release
+ uses: softprops/action-gh-release@v1
+ with:
+ files: |
+ rpm/target/rpm/com.teragrep-rlp_11/RPMS/noarch/com.teragrep-rlp_11-*.rpm
+ target/rlp_11-jar-with-dependencies.jar
diff --git a/.gitignore b/.gitignore
index 92322c4..3e7ba63 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
.idea/
target/
+rpm/target/
diff --git a/pom.xml b/pom.xml
index 5612e9c..f941911 100644
--- a/pom.xml
+++ b/pom.xml
@@ -510,12 +510,15 @@
eclipse-java-formatter.xml
src/main/assembly/jar-with-dependencies.xml
- etc/*.properties
+ src/test/resources/*.properties
src/main/resources/log4j2.xml
src/test/resources/log4j2-test.xml
README.adoc
+
+ rpm/rpm.pom.xml
+ rpm/src/**
diff --git a/rpm/rpm.pom.xml b/rpm/rpm.pom.xml
new file mode 100644
index 0000000..2c83a22
--- /dev/null
+++ b/rpm/rpm.pom.xml
@@ -0,0 +1,173 @@
+
+
+ rpm
+ 4.0.0
+ rlp_11
+ ${revision}${sha1}${changelist}
+ rlp_11
+ rlp_11
+ com.teragrep
+
+ UTF-8
+ 0.0.1
+ -SNAPSHOT
+
+
+
+ ${project.basedir}/target
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.5.2
+
+ true
+
+
+
+ maven-enforcer-plugin
+ 3.5.0
+
+
+ enforce
+ none
+
+
+ enforce-maven
+
+ enforce
+
+
+
+
+ 3.6.3
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ rpm-maven-plugin
+ 2.3.0
+ true
+
+
+ default-rpm
+
+ rpm
+
+ package
+
+
+
+ ${project.groupId}-${project.artifactId}
+ ${project.groupId}-${project.artifactId}
+ ${project.version}
+ ${env.BUILD_ID}
+ AGPL
+ Teragrep rlp_11
+ https://teragrep.com/
+ Teragrep <servicedesk@teragrep.com>
+ Teragrep/rlp_11
+ ${project.groupId}-${project.artifactId}
+ false
+ srv-rlp_11
+ srv-rlp_11
+ 0644
+ 0755
+
+
+ /usr/lib/systemd/system
+ false
+
+
+
+
+
+ /opt/teragrep/${project.artifactId}/etc
+ true
+ 755
+
+
+ /opt/teragrep/${project.artifactId}/etc
+ noreplace
+ false
+ srv-rlp_11
+ srv-rlp_11
+ false
+
+
+
+
+
+
+ /opt/teragrep/${project.artifactId}/lib
+ true
+ 755
+
+
+ /opt/teragrep/${project.artifactId}/lib
+ false
+ 755
+ 755
+ srv-rlp_11
+ srv-rlp_11
+ false
+
+
+
+
+
+
+ java-11-openjdk-headless
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+ 3.1.3
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+
+ default-compile
+ compile
+
+ compile
+
+
+ true
+
+
+
+
+
+
+
diff --git a/rpm/src/opt/teragrep/rlp_11/etc/log4j2.xml b/rpm/src/opt/teragrep/rlp_11/etc/log4j2.xml
new file mode 100644
index 0000000..959d7dc
--- /dev/null
+++ b/rpm/src/opt/teragrep/rlp_11/etc/log4j2.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/etc/rlp_11.properties b/rpm/src/opt/teragrep/rlp_11/etc/rlp_11.properties
similarity index 100%
rename from etc/rlp_11.properties
rename to rpm/src/opt/teragrep/rlp_11/etc/rlp_11.properties
diff --git a/rpm/src/usr/lib/systemd/system/rlp_11.service b/rpm/src/usr/lib/systemd/system/rlp_11.service
new file mode 100644
index 0000000..8330f1b
--- /dev/null
+++ b/rpm/src/usr/lib/systemd/system/rlp_11.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=com.teragrep.rlp_11
+ConditionPathExists=/opt/teragrep/rlp_11/etc/rlp_11.properties
+ConditionPathExists=/opt/teragrep/rlp_11/etc/log4j2.xml
+
+[Service]
+ExecStart=/usr/lib/jvm/jre-11-openjdk/bin/java \
+ -DconfigurationPath=/opt/teragrep/rlp_11/etc/rlp_11.properties \
+ -Dlog4j2.configurationFile=file:/opt/teragrep/rlp_11/etc/log4j2.xml \
+ -jar /opt/teragrep/rlp_11/lib/rlp_11.jar
+User=srv-rlp_11
+WorkingDirectory=/opt/teragrep/rlp_11
+
+[Install]
+WantedBy=multi-user.target
diff --git a/rpm/src/usr/lib/systemd/system/rlp_11@.service b/rpm/src/usr/lib/systemd/system/rlp_11@.service
new file mode 100644
index 0000000..2a11f2f
--- /dev/null
+++ b/rpm/src/usr/lib/systemd/system/rlp_11@.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=com.teragrep.rlp_11 instance %I
+ConditionPathExists=/opt/teragrep/rlp_11/etc/rlp_11.%I.properties
+ConditionPathExists=/opt/teragrep/rlp_11/etc/log4j2.%I.xml
+
+[Service]
+ExecStart=/usr/lib/jvm/jre-11-openjdk/bin/java \
+ -DconfigurationPath=/opt/teragrep/rlp_11/etc/rlp_11.%I.properties \
+ -Dlog4j2.configurationFile=file:/opt/teragrep/rlp_11/etc/log4j2.%I.xml \
+ -jar /opt/teragrep/rlp_11/lib/rlp_11.jar
+User=srv-rlp_11
+WorkingDirectory=/opt/teragrep/rlp_11
+
+[Install]
+WantedBy=multi-user.target
diff --git a/src/test/java/com/teragrep/rlp_11/ConnectionTest.java b/src/test/java/com/teragrep/rlp_11/ConnectionTest.java
index 86bc4d7..02621b7 100644
--- a/src/test/java/com/teragrep/rlp_11/ConnectionTest.java
+++ b/src/test/java/com/teragrep/rlp_11/ConnectionTest.java
@@ -124,7 +124,7 @@ public void stopServer() {
@Test
public void connectToServerTest() {
Map map = Assertions
- .assertDoesNotThrow(() -> new PathConfiguration("etc/rlp_11.properties").asMap());
+ .assertDoesNotThrow(() -> new PathConfiguration("src/test/resources/connect.properties").asMap());
final ProbeConfiguration probeConfiguration = new ProbeConfiguration(map);
final RecordFactory recordFactory = new RecordFactory("localhost", "rlp_11", "rlp_11");
final TargetConfiguration targetConfiguration = new TargetConfiguration(map);
diff --git a/src/test/resources/connect.properties b/src/test/resources/connect.properties
new file mode 100644
index 0000000..52a88ba
--- /dev/null
+++ b/src/test/resources/connect.properties
@@ -0,0 +1,24 @@
+# Metrics reporting name. Arbitrary string, only used for reporting purposes
+metrics.name=target
+# Metrics window size
+metrics.window=10000
+# Metrics report interval, in seconds
+metrics.interval=60
+
+# Delay between sending records, in milliseconds
+probe.interval=1000
+
+# Prometheus endpoint port
+prometheus.port=8080
+
+# Appname used in RELP record
+record.appname=rlp_11
+# Hostname used in RELP record
+record.hostname=rlp_11
+
+# RELP Server target address
+target.hostname=127.0.0.1
+# Relp Server target port
+target.port=12345
+# RELP Server reconnect interval, in milliseconds
+target.reconnectinterval=1000