forked from netmanagers/salt-image-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·62 lines (53 loc) · 1.77 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
#!/usr/bin/env python3
"""
usage: %prog
Build different docker images with salt-minion pre-installed to ease testing
This script allows you to build locally, pulling the images matrix from the .travis.yml file.
Check that file for details.
"""
import yaml
import os
import subprocess
travis_file = open(".travis.yml", "r")
# travis_yaml = yaml.load(travis_file, Loader=yaml.FullLoader)
travis_yaml = yaml.load(travis_file)
for job_line in travis_yaml["env"]["jobs"]:
DN, DV, PI, SIM, SV, PV, *EP = job_line.split()
DN = DN.split("=")[1]
DV = DV.split("=")[1]
PI = PI.split("=")[1]
PV = PV.split("=")[1]
SIM = SIM.split("=")[1]
SV = SV.split("=")[1]
# Extra packages lines require some extra processing
EP = " ".join(EP).split("=")[1]
build_script = (
"/tmp/salt-docker-builder-script-"
+ DN.replace("/", "-")
+ DV
+ "-"
+ PI
+ "-"
+ PV
+ "-"
+ SIM
+ "-"
+ SV
)
with open(build_script, "w") as script:
script.write("#!/bin/bash\n")
script.write('export DN="' + DN + '"\n')
script.write('export DV="' + DV + '"\n')
script.write('export SIM="' + SIM + '"\n')
script.write('export SV="' + SV + '"\n')
script.write('export PV="' + PV + '"\n')
script.write('export EP="' + EP.replace('"', "") + '"\n')
script.write('export PI="' + PI + '"\n')
for install_line in travis_yaml["before_install"]:
script.write(install_line + "\n")
for install_line in travis_yaml["install"]:
script.write(install_line + "\n")
for install_line in travis_yaml["script"]:
script.write(install_line + "\n")
os.chmod(build_script, 0o755)
subprocess.run(build_script)