7
import lxc
8
import subprocess
9
import os
10
+import sys
11
+import tempfile
12
+import shutil
13
14
def fetch_version(orig_build_version):
15
tag = None
56
if command_result != 0:
57
raise Exception("Command failed with exit code %d" % command_result)
58
56
-def run_command_in_host(cmd):
57
- print("Issue command in host: %s" % str(cmd))
59
+def run_command_in_host(cmd, cwd=None):
60
+ print("Issue command in host: %s, cwd:%s" % (str(cmd), str(cwd)))
61
59
- proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
62
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd)
63
o, e = proc.communicate()
64
print('Output: ' + o.decode('ascii'))
65
print('Error: ' + e.decode('ascii'))
136
print(".0 Preparing local implementation tarball for version %s" % pkg_friendly_version)
137
tar_file = os.environ['LXC_CONTAINER_ROOT'] + dest_archive
138
139
+ print(".0 Copy repo to prepare it for tarball generation")
140
+ tmp_src = tempfile.mkdtemp(prefix='netdata-source-')
141
+ run_command_in_host(['cp', '-r', '.', tmp_src])
142
+
143
if tag is not None:
144
print(".1 Checking out tag %s" % tag)
138
- run_command_in_host(['git', 'fetch', '--all'])
145
+ run_command_in_host(['git', 'fetch', '--all'], tmp_src)
146
147
# TODO: Keep in mind that tricky 'v' there, needs to be removed once we clear our versioning scheme
141
- run_command_in_host(['git', 'checkout', 'v%s' % pkg_friendly_version])
148
+ run_command_in_host(['git', 'checkout', 'v%s' % pkg_friendly_version], tmp_src)
149
150
print(".2 Tagging the code with version: %s" % pkg_friendly_version)
144
- run_command_in_host(['git', 'tag', '-a', pkg_friendly_version, '-m', 'Tagging while packaging on %s' % os.environ["CONTAINER_NAME"]])
151
+ run_command_in_host(['git', 'tag', '-a', pkg_friendly_version, '-m', 'Tagging while packaging on %s' % os.environ["CONTAINER_NAME"]], tmp_src)
152
153
print(".3 Run autoreconf -ivf")
147
- run_command_in_host(['autoreconf', '-ivf'])
154
+ run_command_in_host(['autoreconf', '-ivf'], tmp_src)
155
156
print(".4 Run configure")
150
- run_command_in_host(['./configure', '--prefix=/usr', '--sysconfdir=/etc', '--localstatedir=/var', '--libdir=/usr/lib', '--libexecdir=/usr/libexec', '--with-math', '--with-zlib', '--with-user=netdata'])
157
+ run_command_in_host(['./configure', '--prefix=/usr', '--sysconfdir=/etc', '--localstatedir=/var', '--libdir=/usr/lib', '--libexecdir=/usr/libexec', '--with-math', '--with-zlib', '--with-user=netdata'], tmp_src)
158
159
print(".5 Run make dist")
153
- run_command_in_host(['make', 'dist'])
160
+ run_command_in_host(['make', 'dist'], tmp_src)
161
162
print(".6 Copy generated tarbal to desired path")
156
- if os.path.exists('netdata-%s.tar.gz' % pkg_friendly_version):
157
- run_command_in_host(['sudo', 'cp', 'netdata-%s.tar.gz' % pkg_friendly_version, tar_file])
163
+ generated_tarball = '%snetdata-%s.tar.gz' % (tmp_src, pkg_friendly_version)
164
+
165
+ if os.path.exists(generated_tarball):
166
+ run_command_in_host(['sudo', 'cp', generated_tarball, tar_file])
167
168
print(".7 Fixing permissions on tarball")
169
run_command_in_host(['sudo', 'chmod', '777', tar_file])
170
+
171
+ print(".8 Returning to original directory, removing temp");
172
+ shutil.rmtree(tmp_src)
173
else:
162
- print("I could not find (%s) on the disk, stopping the build. Kindly check the logs and try again" % 'netdata-%s.tar.gz' % pkg_friendly_version)
174
+ print("I could not find (%s) on the disk, stopping the build. Kindly check the logs and try again" % generated_tarball)
175
sys.exit(1)