Skip to content

Commit

Permalink
Rpm package (#13)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
StrongestNumber9 authored Nov 11, 2024
1 parent a314ce8 commit 506a142
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 2 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
target/
rpm/target/
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,15 @@
<exclude>eclipse-java-formatter.xml</exclude>
<exclude>src/main/assembly/jar-with-dependencies.xml</exclude>
<!-- test properties -->
<exclude>etc/*.properties</exclude>
<exclude>src/test/resources/*.properties</exclude>
<!-- logging configuration -->
<exclude>src/main/resources/log4j2.xml</exclude>
<exclude>src/test/resources/log4j2-test.xml</exclude>
<!-- readme -->
<exclude>README.adoc</exclude>
<!-- packaging -->
<exclude>rpm/rpm.pom.xml</exclude>
<exclude>rpm/src/**</exclude>
</excludes>
</configuration>
<executions>
Expand Down
173 changes: 173 additions & 0 deletions rpm/rpm.pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<packaging>rpm</packaging>
<modelVersion>4.0.0</modelVersion>
<artifactId>rlp_11</artifactId>
<version>${revision}${sha1}${changelist}</version>
<name>rlp_11</name>
<description>rlp_11</description>
<groupId>com.teragrep</groupId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>0.0.1</revision>
<changelist>-SNAPSHOT</changelist>
<sha1/>
</properties>
<build>
<directory>${project.basedir}/target</directory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>enforce</id>
<phase>none</phase>
</execution>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.6.3</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.3.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>default-rpm</id>
<goals>
<goal>rpm</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<summary>${project.groupId}-${project.artifactId}</summary>
<name>${project.groupId}-${project.artifactId}</name>
<version>${project.version}</version>
<release>${env.BUILD_ID}</release>
<license>AGPL</license>
<distribution>Teragrep rlp_11</distribution>
<vendor>https://teragrep.com/</vendor>
<packager>Teragrep &lt;servicedesk@teragrep.com&gt;</packager>
<group>Teragrep/rlp_11</group>
<description>${project.groupId}-${project.artifactId}</description>
<needarch>false</needarch>
<defaultUsername>srv-rlp_11</defaultUsername>
<defaultGroupname>srv-rlp_11</defaultGroupname>
<defaultFilemode>0644</defaultFilemode>
<defaultDirmode>0755</defaultDirmode>
<mappings>
<mapping>
<directory>/usr/lib/systemd/system</directory>
<directoryIncluded>false</directoryIncluded>
<sources>
<source>
<location>src/usr/lib/systemd/system</location>
</source>
</sources>
</mapping>
<mapping>
<directory>/opt/teragrep/${project.artifactId}/etc</directory>
<directoryIncluded>true</directoryIncluded>
<filemode>755</filemode>
</mapping>
<mapping>
<directory>/opt/teragrep/${project.artifactId}/etc</directory>
<configuration>noreplace</configuration>
<directoryIncluded>false</directoryIncluded>
<username>srv-rlp_11</username>
<groupname>srv-rlp_11</groupname>
<recurseDirectories>false</recurseDirectories>
<sources>
<source>
<location>${project.basedir}/src/opt/teragrep/rlp_11/etc/log4j2.xml</location>
</source>
<source>
<location>${project.basedir}/src/opt/teragrep/rlp_11/etc/rlp_11.properties</location>
</source>
</sources>
</mapping>
<mapping>
<directory>/opt/teragrep/${project.artifactId}/lib</directory>
<directoryIncluded>true</directoryIncluded>
<filemode>755</filemode>
</mapping>
<mapping>
<directory>/opt/teragrep/${project.artifactId}/lib</directory>
<directoryIncluded>false</directoryIncluded>
<filemode>755</filemode>
<dirmode>755</dirmode>
<username>srv-rlp_11</username>
<groupname>srv-rlp_11</groupname>
<recurseDirectories>false</recurseDirectories>
<sources>
<source>
<location>${project.basedir}/../target/rlp_11-jar-with-dependencies.jar</location>
<destination>rlp_11.jar</destination>
</source>
</sources>
</mapping>
</mappings>
<requires>
<require>java-11-openjdk-headless</require>
</requires>
<preinstallScriptlet>
<script>
getent group srv-rlp_11 > /dev/null || groupadd -r srv-rlp_11;
getent passwd srv-rlp_11 > /dev/null || useradd -r -g srv-rlp_11 -d /opt/teragrep/${project.artifactId} -s /sbin/nologin -c "Service User" srv-rlp_11;
exit 0;
</script>
</preinstallScriptlet>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.3</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<skipMain>true</skipMain>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
16 changes: 16 additions & 0 deletions rpm/src/opt/teragrep/rlp_11/etc/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration>
<Appenders>
<Console name="STDOUT">
<PatternLayout pattern="%d{dd.MM.yyyy HH:mm:ss.SSS} [%level] [%logger] [%thread] %msg%ex%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="com.teragrep.rlp_11" level="info" additivity="false">
<AppenderRef ref="STDOUT"/>
</Logger>
<Root level="INFO">
<AppenderRef ref="STDOUT" />
</Root>
</Loggers>
</Configuration>
File renamed without changes.
15 changes: 15 additions & 0 deletions rpm/src/usr/lib/systemd/system/rlp_11.service
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions rpm/src/usr/lib/systemd/system/rlp_11@.service
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/test/java/com/teragrep/rlp_11/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void stopServer() {
@Test
public void connectToServerTest() {
Map<String, String> 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);
Expand Down
24 changes: 24 additions & 0 deletions src/test/resources/connect.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 506a142

Please sign in to comment.