Project

General

Profile

Build script » History » Version 4

Luke Murphey, 02/15/2017 07:22 AM

1 1 Luke Murphey
h1. Build script
2 1 Luke Murphey
3 4 Luke Murphey
Here are some benefits of using this build script:
4 3 Luke Murphey
5 4 Luke Murphey
# Creates a Splunk app package easily (without having to run a bunch of CLI tools manually). It will also populate the build file with things like the build date and perform minification.
6 1 Luke Murphey
# Deploys your changes to a local Splunk install for testing your changes (avoids manually copying the files over).
7 4 Luke Murphey
# Works with Continuous Integration tools to enable automated on-going tests
8 1 Luke Murphey
9 4 Luke Murphey
h2. Getting started with the build script
10 1 Luke Murphey
11 4 Luke Murphey
h3. Step 1: add build script
12 1 Luke Murphey
13 4 Luke Murphey
Copy the file "basebuild.xml" to the root of your app's directory from here: https://gist.github.com/LukeMurphey/8fd02337805ae8762afb
14 1 Luke Murphey
15 4 Luke Murphey
Then, run the following to start a new project:
16 1 Luke Murphey
17 4 Luke Murphey
<pre>
18 4 Luke Murphey
ant -f basebuild start_project
19 4 Luke Murphey
</pre>
20 1 Luke Murphey
21 4 Luke Murphey
This will ask you for the name of your app. The name it is asking for is the name app ID which is the folder name of the app (e.g. "website_monitoring"). This build target will make a customized build script for your app and properties files where you can declare custom parameters to change the behavior of the build script.
22 4 Luke Murphey
23 4 Luke Murphey
Now that a new build script was created, you can test it by typing:
24 4 Luke Murphey
25 4 Luke Murphey
<pre>
26 4 Luke Murphey
ant
27 4 Luke Murphey
</pre>
28 4 Luke Murphey
29 4 Luke Murphey
This should produce a package in the tmp/packages directory.
30 4 Luke Murphey
31 4 Luke Murphey
h3. Step 2: Deploy your app to a local Splunk install
32 4 Luke Murphey
33 4 Luke Murphey
The build script provides some tools to help you send your code to a local Splunk install for testing. This allows you to send the code from the
34 4 Luke Murphey
app you are writing to a live Splunk install to see the running changes. To do this, edit the "local.properties" file and declare the location of your
35 4 Luke Murphey
Splunk install, like this:
36 4 Luke Murphey
37 4 Luke Murphey
<pre>
38 4 Luke Murphey
value.deploy.splunk_home=/Users/luke_murphey/Applications/Splunk
39 4 Luke Murphey
</pre>
40 4 Luke Murphey
    
41 4 Luke Murphey
Once you do that, run the following build target to have your code sent to your Splunk install:
42 4 Luke Murphey
43 4 Luke Murphey
<pre>
44 4 Luke Murphey
ant deploy
45 4 Luke Murphey
</pre>
46 4 Luke Murphey
47 4 Luke Murphey
Restart your Splunk install in order to see that your app is now recognized by Splunk (it should appear in the list of apps even though the app is just an empty directory).
48 4 Luke Murphey
49 4 Luke Murphey
h3. Step3: Place your source code in the /src directory
50 4 Luke Murphey
51 4 Luke Murphey
At this point, you can out your app's source-code in the "src" directory. The code in the "src" directory will the be the code that makes up your app. Run "ant deploy" to send the new code to your running Splunk install so that you preview the changes.
52 4 Luke Murphey
53 4 Luke Murphey
h2. File structure that the build script expects
54 4 Luke Murphey
55 4 Luke Murphey
By default, the build script will assume that the source-code is under the src directory. To work with the build script, put your code in the following directory structure. The only directory you must create is the src directory; everything else is optional or will be created for you.
56 4 Luke Murphey
57 4 Luke Murphey
* *src/* (this is where you app code will go)
58 4 Luke Murphey
* *lib/* (this directory will be created by the build script, this is where build dependencies will go)
59 4 Luke Murphey
* *tests/* (optional, this is the directory that contains tests for your app)
60 4 Luke Murphey
** *unit.py* (optional, this is a script where the unit tests should go)
61 4 Luke Murphey
62 4 Luke Murphey
h2. Editing build script properties
63 4 Luke Murphey
64 4 Luke Murphey
h2. Build script targets
65 1 Luke Murphey
66 1 Luke Murphey
Targets for publishing the Splunk app (the main one):
67 1 Luke Murphey
* package
68 1 Luke Murphey
69 1 Luke Murphey
Targets that help you while developing Splunk apps:
70 1 Luke Murphey
* splunk.deploy
71 1 Luke Murphey
* splunk.start, splunk.restart, splunk.stop, splunk.restart_web
72 1 Luke Murphey
* splunk.deploy_and_refresh
73 1 Luke Murphey
74 1 Luke Murphey
Targets for testing:
75 1 Luke Murphey
* test.run_unit