configure_deb_lxc_environment.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env python3
  2. #
  3. # Prepare the build environment within the container
  4. # The script attaches to the running container and does the following:
  5. # 1) Create the container
  6. # 2) Start the container up
  7. # 3) Create the builder user
  8. # 4) Prepare the environment for DEB build
  9. #
  10. # Copyright: SPDX-License-Identifier: GPL-3.0-or-later
  11. #
  12. # Author : Pavlos Emm. Katsoulakis <paul@netdata.cloud>
  13. import common
  14. import os
  15. import sys
  16. import lxc
  17. if len(sys.argv) != 2:
  18. print('You need to provide a container name to get things started')
  19. sys.exit(1)
  20. container_name=sys.argv[1]
  21. # Setup the container object
  22. print("Defining container %s" % container_name)
  23. container = lxc.Container(container_name)
  24. if not container.defined:
  25. raise Exception("Container %s not defined!" % container_name)
  26. # Start the container
  27. if not container.start():
  28. raise Exception("Failed to start the container")
  29. if not container.running or not container.state == "RUNNING":
  30. raise Exception('Container %s is not running, configuration process aborted ' % container_name)
  31. # Wait for connectivity
  32. print("Waiting for container connectivity to start configuration sequence")
  33. if not container.get_ips(timeout=30):
  34. raise Exception("Timeout while waiting for container")
  35. build_path = "/home/%s" % os.environ['BUILDER_NAME']
  36. # Run the required activities now
  37. # 1. Create the builder user
  38. print("1. Adding user %s" % os.environ['BUILDER_NAME'])
  39. common.run_command(container, ["useradd", "-m", os.environ['BUILDER_NAME']])
  40. # Fetch package dependencies for the build
  41. print("2. Preparing repo on LXC container")
  42. common.prepare_repo(container)
  43. print("2.1 Install .DEB build support packages")
  44. common.run_command(container, [os.environ["REPO_TOOL"], "install", "-y", "dpkg-dev"])
  45. common.run_command(container, [os.environ["REPO_TOOL"], "install", "-y", "libdistro-info-perl"])
  46. common.run_command(container, [os.environ["REPO_TOOL"], "install", "-y", "dh-make"])
  47. common.run_command(container, [os.environ["REPO_TOOL"], "install", "-y", "dh-systemd"])
  48. common.run_command(container, [os.environ["REPO_TOOL"], "install", "-y", "dh-autoreconf"])
  49. common.run_command(container, [os.environ["REPO_TOOL"], "install", "-y", "git-buildpackage"])
  50. print("2.2 Add more dependencies")
  51. common.run_command(container, [os.environ["REPO_TOOL"], "install", "-y", "libnetfilter-acct-dev"])
  52. common.run_command(container, [os.environ["REPO_TOOL"], "install", "-y", "libcups2-dev"])
  53. print ("3.1 Run install-required-packages scriptlet")
  54. common.run_command(container, ["wget", "-T", "15", "-O", "%s/.install-required-packages.sh" % build_path, "https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/install-required-packages.sh"])
  55. common.run_command(container, ["bash", "%s/.install-required-packages.sh" % build_path, "netdata", "--dont-wait", "--non-interactive"])
  56. print("3.2 Installing package dependencies within LXC container")
  57. common.install_common_dependendencies(container)
  58. friendly_version=""
  59. dest_archive=""
  60. download_url=""
  61. tag = None
  62. friendly_version, tag = common.fetch_version(os.environ['BUILD_VERSION'])
  63. tar_file="%s/netdata-%s.tar.gz" % (os.path.dirname(dest_archive), friendly_version)
  64. print("5. I will be building version '%s' of netdata." % os.environ['BUILD_VERSION'])
  65. dest_archive="%s/netdata-%s.tar.gz" % (build_path, friendly_version)
  66. ### Debian
  67. if str(os.environ["BUILD_STRING"]).count("debian/jessie") == 1:
  68. print("5.1 We are building for Jessie, adjusting control file")
  69. common.run_command_in_host(['sudo', 'rm', 'contrib/debian/control'])
  70. common.run_command_in_host(['sudo', 'cp', 'contrib/debian/control.jessie', 'contrib/debian/control'])
  71. if str(os.environ["BUILD_STRING"]).count("debian/buster") == 1:
  72. print("5.1 We are building for Buster, adjusting control file")
  73. common.run_command_in_host(['sudo', 'rm', 'contrib/debian/control'])
  74. common.run_command_in_host(['sudo', 'cp', 'contrib/debian/control.buster', 'contrib/debian/control'])
  75. ### Ubuntu
  76. if str(os.environ["BUILD_STRING"]).count("ubuntu/focal") == 1:
  77. print("5.1 We are building for Focal, adjusting control file")
  78. common.run_command_in_host(['sudo', 'rm', 'contrib/debian/control'])
  79. common.run_command_in_host(['sudo', 'cp', 'contrib/debian/control.focal', 'contrib/debian/control'])
  80. if str(os.environ["BUILD_STRING"]).count("ubuntu/xenial") == 1:
  81. print("5.1 We are building for Xenial, adjusting control file")
  82. common.run_command_in_host(['sudo', 'rm', 'contrib/debian/control'])
  83. common.run_command_in_host(['sudo', 'cp', 'contrib/debian/control.xenial', 'contrib/debian/control'])
  84. if str(os.environ["BUILD_STRING"]).count("ubuntu/eoan") == 1:
  85. print("5.1 We are building for Eoan, adjusting control file")
  86. common.run_command_in_host(['sudo', 'rm', 'contrib/debian/control'])
  87. common.run_command_in_host(['sudo', 'cp', 'contrib/debian/control.eoan', 'contrib/debian/control'])
  88. common.prepare_version_source(dest_archive, friendly_version, tag=tag)
  89. print("6. Installing build.sh script to build path")
  90. common.run_command_in_host(['sudo', 'cp', '.travis/package_management/build.sh', "%s/%s/build.sh" % (os.environ['LXC_CONTAINER_ROOT'], build_path)])
  91. common.run_command_in_host(['sudo', 'chmod', '777', "%s/%s/build.sh" % (os.environ['LXC_CONTAINER_ROOT'], build_path)])
  92. common.run_command_in_host(['sudo', 'ln', '-sf', 'contrib/debian', 'debian'])
  93. print("Done!")