-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.py
executable file
·79 lines (61 loc) · 2.15 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
from pathlib import Path
from ksconf.builder import QUIET, VERBOSE, BuildManager, BuildStep, default_cli
from ksconf.builder.steps import clean_build, copy_files, pip_install
manager = BuildManager()
APP_FOLDER = "jmespath"
SPL_NAME = "jmespath-for-splunk-{{version}}.tgz"
SOURCE_DIR = "."
REQUIREMENTS = "requirements.txt"
# Files needed to support the build process (but not in the final package)
BUILD_FILES = [
REQUIREMENTS,
]
COPY_FILES = [
"*.md",
"appserver/",
"bin.d/",
"default.d/",
"lookups/*.csv",
"metadata.d/",
"README/",
"static/",
] + BUILD_FILES
@manager.cache([REQUIREMENTS], ["lib/"], timeout=7200)
def python_packages(step: BuildStep):
# Sticking with the defaults
pip_install(step, REQUIREMENTS, "lib",
handle_dist_info="remove" # vs 'rename'
)
def package_spl(step: BuildStep):
top_dir = step.dist_path.parent
release_path = top_dir / ".release_path"
release_name = top_dir / ".release_name"
step.run_ksconf(
"package",
"--file", step.dist_path / SPL_NAME, # Path to created tarball
"--app-name", APP_FOLDER, # Top-level directory name
"--block-local", # Build from version control should have no 'local' folder
"--layer-method", "dir.d",
"--blocklist", REQUIREMENTS, # No need to distribute this
"--release-file", str(release_path),
".")
# Provide the dist file as a short name too (useful for some CI/CD tools)
path = release_path.read_text()
short_name = Path(path).name
release_name.write_text(short_name)
def build(step: BuildStep, args):
""" Build process """
# Step 1: Clean/create build folder
clean_build(step)
# Step 2: Copy files from source to build folder
copy_files(step, COPY_FILES)
# Step 3: Install Python package dependencies
python_packages(step)
# Step 4: Build tarball
package_spl(step)
if __name__ == '__main__':
# Tell build manager where stuff lives
manager.set_folders(SOURCE_DIR, "build", "dist")
# Launch build CLI
default_cli(manager, build)