@cryptotaxi247 / netdata-1 / commits / dd6703219

netdata/packaging: Ensure that we do not mess with CI tooling, when building stable (#6838)

* netdata/packaging: Dont mess with the CI code when playing with the repo Sadly, we need to run consistently the same code for the CI side. When doing checkouts to build stable code, we move the whole repo thus resulting on changing the ci code too. This is usually fine when building nightlies, on stable though is a completely different story. To mitigate this, copy the repo into a temporary folder. Then do whatever you need to prepare and copy the tarball. Once you are done, just go back to the original repo folder and remove the temp. That should work fine for both nightlies and stable, with a little overhead of copying over the repository, but we have to. We want to be able to run with latest CI code, when trying to build a stable release. * [Package amd64 DEB] Package build stable test * netdata/packaging: allow me to test on my repo the build process (dont care for deploy) * [Package amd64 DEB] Package build stable test * netdata/packaging: [ci skip] copy under tmp * [Package amd64 DEB] Package build stable test * netdata/packaging:[ci skip] play with CWD of the command, thats cleaner and well, the right thing * [Package amd64 DEB] Package build stable test * netdata/packaging: [ci skip] cd did not fall for cwd, provide full path and move on * netdata/packaging: a few nits like dont use cwd for some commands, import sys, simplify some variable usage * netdata/packaging: [ci skip] focus, missed a reference to the tarballen * netdata/packaging: [ci skip] remove test branch * netdata/packaging: Thanks for taking note Codacy, here's a better temp file for the job

Paul Emm. Katsoulakis committed Sep 13, 2019 at 10:27 UTC dd6703219a99ff44842f1460503afbad64cb73f9
2 files changed +24 -12
.travis/package_management/common.py
+24 -12
@@ -7,6 +7,9 @@
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
@@ -53,10 +56,10 @@ def run_command(container, command):
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'))
@@ -133,31 +136,40 @@ def prepare_version_source(dest_archive, pkg_friendly_version, tag=None):
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)
lala