Skip to content

Commit 3ecfde1

Browse files
committed
Added build script to create rpm
1 parent 9ed94cd commit 3ecfde1

7 files changed

+322
-0
lines changed

build.groovy

+229
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
import org.freecompany.redline.Builder
2+
import org.freecompany.redline.header.Architecture
3+
import org.freecompany.redline.header.Os
4+
import org.freecompany.redline.header.RpmType
5+
import org.freecompany.redline.payload.Directive
6+
import tablesaw.*
7+
import tablesaw.addons.GZipRule
8+
import tablesaw.addons.TarRule
9+
import tablesaw.addons.ivy.IvyAddon
10+
import tablesaw.addons.ivy.PomRule
11+
import tablesaw.addons.ivy.PublishRule
12+
import tablesaw.addons.java.Classpath
13+
import tablesaw.addons.java.JarRule
14+
import tablesaw.addons.java.JavaCRule
15+
import tablesaw.addons.java.JavaProgram
16+
import tablesaw.addons.junit.JUnitRule
17+
import tablesaw.definitions.Definition
18+
import tablesaw.rules.CopyRule
19+
import tablesaw.rules.DirectoryRule
20+
import tablesaw.rules.Rule
21+
import tablesaw.rules.SimpleRule
22+
23+
import javax.swing.*
24+
25+
println("===============================================")
26+
27+
saw.setProperty(Tablesaw.PROP_MULTI_THREAD_OUTPUT, Tablesaw.PROP_VALUE_ON)
28+
29+
programName = "kairos-kafka-monitor"
30+
//Do not use '-' in version string, it breaks rpm uninstall.
31+
version = "1.3.0"
32+
release = saw.getProperty("KAIROS_RELEASE_NUMBER", "0.1beta") //package release number
33+
summary = "KairosDB"
34+
description = """\
35+
KairosDB is a time series database that stores numeric values along
36+
with key/value tags to a nosql data store. Currently supported
37+
backends are Cassandra and H2. An H2 implementation is provided
38+
for development work.
39+
"""
40+
41+
42+
saw = Tablesaw.getCurrentTablesaw()
43+
saw.includeDefinitionFile("definitions.xml")
44+
45+
46+
rpmDir = "build/rpm"
47+
new DirectoryRule("build")
48+
rpmDirRule = new DirectoryRule(rpmDir)
49+
50+
//Read pom file to get version out
51+
def pom = new XmlSlurper().parseText(new File("pom.xml").text)
52+
version = pom.version.text()
53+
54+
mvnRule = new SimpleRule("maven-package")
55+
.setDescription("Run maven package build")
56+
.setMakeAction("doMavenBuild")
57+
58+
def doMavenBuild(Rule rule)
59+
{
60+
saw.exec("mvn clean package")
61+
}
62+
63+
//------------------------------------------------------------------------------
64+
//Build zip deployable application
65+
rpmFile = "$programName-$version-${release}.rpm"
66+
srcRpmFile = "$programName-$version-${release}.src.rpm"
67+
ivyFileSet = new SimpleFileSet()
68+
69+
70+
libFileSets = [
71+
new RegExFileSet("build/jar", ".*\\.jar"),
72+
new RegExFileSet("lib", ".*\\.jar"),
73+
ivyFileSet
74+
]
75+
76+
scriptsFileSet = new RegExFileSet("src/scripts", ".*").addExcludeFile("kairosdb-env.sh")
77+
webrootFileSet = new RegExFileSet("webroot", ".*").recurse()
78+
79+
zipLibDir = "$programName/lib"
80+
zipBinDir = "$programName/bin"
81+
zipConfDir = "$programName/conf"
82+
zipConfLoggingDir = "$zipConfDir/logging"
83+
zipWebRootDir = "$programName/webroot"
84+
tarRule = new TarRule("build/${programName}-${version}-${release}.tar")
85+
.addDepend(mvnRule)
86+
.addFileSetTo(zipBinDir, scriptsFileSet)
87+
.addFileSetTo(zipWebRootDir, webrootFileSet)
88+
.addFileTo(zipConfDir, "src/main/resources", "kairosdb.conf")
89+
.addFileTo(zipConfLoggingDir, "src/main/resources", "logback.xml")
90+
.setFilePermission(".*\\.sh", 0755)
91+
92+
for (AbstractFileSet fs in libFileSets)
93+
tarRule.addFileSetTo(zipLibDir, fs)
94+
95+
96+
gzipRule = new GZipRule("package").setSource(tarRule.getTarget())
97+
.setDescription("Create deployable tar file")
98+
.setTarget("build/${programName}-${version}-${release}.tar.gz")
99+
.addDepend(tarRule)
100+
101+
//------------------------------------------------------------------------------
102+
//Build rpm file
103+
rpmBaseInstallDir = "/opt/kairosdb"
104+
rpmRule = new SimpleRule("package-rpm").setDescription("Build RPM Package")
105+
.addDepend(mvnRule)
106+
.addDepend(rpmDirRule)
107+
.addTarget("$rpmDir/$rpmFile")
108+
.setMakeAction("doRPM")
109+
.setProperty("dependency", "on")
110+
111+
112+
def doRPM(Rule rule)
113+
{
114+
//Build rpm using redline rpm library
115+
host = InetAddress.getLocalHost().getHostName()
116+
rpmBuilder = new Builder()
117+
rpmBuilder.with
118+
{
119+
description = description
120+
group = "System Environment/Daemons"
121+
license = "license"
122+
setPackage(programName, version, release)
123+
setPlatform(Architecture.NOARCH, Os.LINUX)
124+
summary = summary
125+
type = RpmType.BINARY
126+
url = "http://kairosdb.org"
127+
vendor = "KairosDB"
128+
provides = programName
129+
//prefixes = rpmBaseInstallDir
130+
buildHost = host
131+
sourceRpm = srcRpmFile
132+
}
133+
134+
rpmBuilder.addDependencyMore("kairosdb", "1.2.0")
135+
136+
addFileSetToRPM(rpmBuilder, "$rpmBaseInstallDir/lib/kafka-monitor", new RegExFileSet("target", ".*\\.jar"))
137+
addFileSetToRPM(rpmBuilder, "$rpmBaseInstallDir/lib/kafka-monitor", new RegExFileSet("target/dependency", ".*\\.jar"))
138+
139+
140+
rpmBuilder.addFile("$rpmBaseInstallDir/conf/kafka-monitor.properties",
141+
new File("src/main/resources/kafka-monitor.properties"), 0644, new Directive(Directive.RPMFILE_CONFIG | Directive.RPMFILE_NOREPLACE))
142+
143+
144+
println("Building RPM "+rule.getTarget())
145+
outputFile = new FileOutputStream(rule.getTarget())
146+
rpmBuilder.build(outputFile.channel)
147+
outputFile.close()
148+
}
149+
150+
def addFileSetToRPM(Builder builder, String destination, AbstractFileSet files)
151+
{
152+
153+
for (AbstractFileSet.File file : files.getFiles())
154+
{
155+
File f = new File(file.getBaseDir(), file.getFile())
156+
if (f.getName().endsWith(".sh"))
157+
builder.addFile(destination + "/" +file.getFile(), f, 0755)
158+
else
159+
builder.addFile(destination + "/" + file.getFile(), f)
160+
}
161+
}
162+
163+
debRule = new SimpleRule("package-deb").setDescription("Build Deb Package")
164+
.addDepend(rpmRule)
165+
.setMakeAction("doDeb")
166+
167+
def doDeb(Rule rule)
168+
{
169+
//Prompt the user for the sudo password
170+
//TODO: package using jdeb
171+
def jpf = new JPasswordField()
172+
def password = saw.getProperty("sudo")
173+
174+
if (password == null)
175+
{
176+
def resp = JOptionPane.showConfirmDialog(null,
177+
jpf, "Enter sudo password:",
178+
JOptionPane.OK_CANCEL_OPTION)
179+
180+
if (resp == 0)
181+
password = jpf.getPassword()
182+
}
183+
184+
if (password != null)
185+
{
186+
sudo = saw.createAsyncProcess(rpmDir, "sudo -S alien --bump=0 --to-deb $rpmFile")
187+
sudo.run()
188+
//pass the password to the process on stdin
189+
sudo.sendMessage("$password\n")
190+
sudo.waitForProcess()
191+
if (sudo.getExitCode() != 0)
192+
throw new TablesawException("Unable to run alien application")
193+
}
194+
}
195+
196+
197+
198+
//------------------------------------------------------------------------------
199+
//Build notification
200+
def printMessage(String title, String message) {
201+
osName = saw.getProperty("os.name")
202+
203+
Definition notifyDef
204+
if (osName.startsWith("Linux"))
205+
{
206+
notifyDef = saw.getDefinition("linux-notify")
207+
}
208+
else if (osName.startsWith("Mac"))
209+
{
210+
notifyDef = saw.getDefinition("mac-notify")
211+
}
212+
213+
if (notifyDef != null)
214+
{
215+
notifyDef.set("title", title)
216+
notifyDef.set("message", message)
217+
saw.exec(notifyDef.getCommand())
218+
}
219+
}
220+
221+
def buildFailure(Exception e)
222+
{
223+
printMessage("Build Failure", e.getMessage())
224+
}
225+
226+
def buildSuccess(String target)
227+
{
228+
printMessage("Build Success", target)
229+
}

definitions.xml

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" ?>
2+
3+
<definitions xmlns="http://www.cpmake.org">
4+
5+
<definition name="sun_javac" command="javac">
6+
7+
<mode>debug</mode>
8+
<mode>release</mode>
9+
10+
<property name="compiler">Sun Java</property>
11+
12+
<option name="deprecation">-deprecation</option>
13+
<option name="unchecked">-Xlint:unchecked</option>
14+
<option name="fallthrough">-Xlint:fallthrough</option>
15+
<option name="path" >-Xlint:path</option>
16+
<option name="serial" >-Xlint:serial</option>
17+
<option name="finally">-Xlint:finally</option>
18+
<option name="lintall">-Xlint:all</option>
19+
<option name="verbose">-verbose</option>
20+
21+
<option name="source" pattern="(.+)">-source $1</option>
22+
<option name="target" pattern="(.+)">-target $1</option>
23+
24+
<option name="classpath"
25+
pattern="(.+)">-classpath $1</option>
26+
27+
<option name="class_dir" pattern="(.+)">-d $1</option>
28+
29+
<option name="sourcepath" pattern="(.+)">-sourcepath $1</option>
30+
31+
<option name="encoding" pattern="(.+)">-encoding $1</option>
32+
33+
<option mode="debug">-g</option>
34+
<option mode="release">-g:none</option>
35+
36+
<option name="sourcefile" pattern="(.+)">$1</option>
37+
38+
</definition>
39+
40+
<definition name="genormous" command="java">
41+
<!-- <command name="genorm">java</command>
42+
<command name="genquery">java</command> -->
43+
44+
<option name="classpath" pattern="(.+)">-cp $1</option>
45+
<option name="genorm">org.agileclick.genorm.Genormous</option>
46+
<option name="genquery">org.agileclick.genorm.QueryGen</option>
47+
48+
<option name="source" pattern="(.+)">-s $1</option>
49+
</definition>
50+
51+
<!-- We are overriding the tablesaw defintion for junit so we can increase
52+
memory needed for running tests -->
53+
<definition name="junit4" command="java -Xmx500M">
54+
<option name="jvm_arg" pattern="(.*)">$1</option>
55+
<option name="debug" pattern="(.+)">-Xdebug
56+
-Xrunjdwp:transport=dt_socket,server=y,address=$1
57+
</option>
58+
<option name="classpath" pattern="(.+)">-cp $1</option>
59+
<option>org.junit.runner.JUnitCore</option>
60+
<option name="test_class" pattern="(.+)">$1</option>
61+
</definition>
62+
63+
<!-- ======================================================================= -->
64+
<definition name="testng" command="java">
65+
<option name="classpath" pattern="(.+)">-cp $1</option>
66+
</definition>
67+
68+
<!-- ======================================================================= -->
69+
<definition name="linux-notify" command="notify-send">
70+
<option name="title" pattern="(.+)">"$1"</option>
71+
<option name="message" pattern="(.+)">"$1"</option>
72+
</definition>
73+
74+
<definition name="mac-notify" command="osascript">
75+
<option>-e "display notification</option>
76+
<option name="message" pattern="(.+)">\\"$1\\"</option>
77+
<option name="title" pattern="(.+)">with title \\"$1\\"</option>
78+
<option>"</option>
79+
</definition>
80+
81+
<definition name="kairos" command="java">
82+
<option name="debug">-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005</option>
83+
<option name="profile" pattern="(.+)">$1</option>
84+
<option>-Dio.netty.epollBugWorkaround=true</option>
85+
<option name="classpath" pattern="(.+)">-cp $1</option>
86+
<option>org.kairosdb.core.Main</option>
87+
<option name="command" pattern="(.+)">-c $1</option>
88+
<option name="export_metric" pattern="(.+)">-n $1</option>
89+
<option name="import_export_file" pattern="(.+)">-f $1</option>
90+
<option name="properties" pattern="(.+)">-p $1</option>
91+
</definition>
92+
93+
</definitions>

tools/commons-compress-1.4.1.jar

236 KB
Binary file not shown.

tools/groovy-all-1.6.3.jar

4.26 MB
Binary file not shown.

tools/ivy-2.3.0.jar

1.17 MB
Binary file not shown.

tools/redline-1.1.10.jar

103 KB
Binary file not shown.

tools/tablesaw-1.2.6.jar

254 KB
Binary file not shown.

0 commit comments

Comments
 (0)