trigger_deb_lxc_build.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env python3
  2. #
  3. # This script is responsible for running the RPM build on the running container
  4. #
  5. # Copyright: SPDX-License-Identifier: GPL-3.0-or-later
  6. #
  7. # Author : Pavlos Emm. Katsoulakis <paul@netdata.cloud>
  8. import common
  9. import os
  10. import sys
  11. import lxc
  12. if len(sys.argv) != 2:
  13. print('You need to provide a container name to get things started')
  14. sys.exit(1)
  15. container_name=sys.argv[1]
  16. # Load the container, break if its not there
  17. print("Starting up container %s" % container_name)
  18. container = lxc.Container(container_name)
  19. if not container.defined:
  20. raise Exception("Container %s does not exist!" % container_name)
  21. # Check if the container is running, attempt to start it up in case its not running
  22. if not container.running or not container.state == "RUNNING":
  23. print('Container %s is not running, attempt to start it up' % container_name)
  24. # Start the container
  25. if not container.start():
  26. raise Exception("Failed to start the container")
  27. if not container.running or not container.state == "RUNNING":
  28. raise Exception('Container %s is not running, configuration process aborted ' % container_name)
  29. # Wait for connectivity
  30. if not container.get_ips(timeout=30):
  31. raise Exception("Timeout while waiting for container")
  32. build_path = "/home/%s" % os.environ['BUILDER_NAME']
  33. print("Setting up EMAIL and DEBFULLNAME variables required by the build tools")
  34. os.environ["EMAIL"] = "bot@netdata.cloud"
  35. os.environ["DEBFULLNAME"] = "Netdata builder"
  36. # Run the build process on the container
  37. new_version, tag = common.fetch_version(os.environ['BUILD_VERSION'])
  38. print("Starting DEB build process for version %s" % new_version)
  39. netdata_tarball = "%s/netdata-%s.tar.gz" % (build_path, new_version)
  40. unpacked_netdata = netdata_tarball.replace(".tar.gz", "")
  41. print("Extracting tarball %s" % netdata_tarball)
  42. common.run_command(container, ["sudo", "-u", os.environ['BUILDER_NAME'], "tar", "xf", netdata_tarball, "-C", build_path])
  43. print("Fixing changelog tags")
  44. changelog_in_host = "contrib/debian/changelog"
  45. common.run_command_in_host(['sed', '-i', 's/PREVIOUS_PACKAGE_VERSION/%s-1/g' % os.environ["LATEST_RELEASE_VERSION"].replace("v", ""), changelog_in_host])
  46. common.run_command_in_host(['sed', '-i', 's/PREVIOUS_PACKAGE_DATE/%s/g' % os.environ["LATEST_RELEASE_DATE"], changelog_in_host])
  47. print("Executing gbp dch command..")
  48. common.run_command_in_host(['gbp', 'dch', '--release', '--ignore-branch', '--spawn-editor=snapshot', '--since=%s' % os.environ["LATEST_RELEASE_VERSION"], '--new-version=%s' % new_version])
  49. print("Copying over changelog to the destination machine")
  50. common.run_command_in_host(['sudo', 'cp', 'debian/changelog', "%s/%s/netdata-%s/contrib/debian/" % (os.environ['LXC_CONTAINER_ROOT'], build_path, new_version)])
  51. print("Running debian build script since %s" % os.environ["LATEST_RELEASE_VERSION"])
  52. common.run_command(container, ["sudo", "-u", os.environ['BUILDER_NAME'], "%s/build.sh" % build_path, unpacked_netdata, new_version])
  53. print("Listing contents on build path")
  54. common.run_command(container, ["sudo", "-u", os.environ['BUILDER_NAME'], "ls", "-ltr", build_path])
  55. print('Done!')