package_targets.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/usr/bin/env python
  2. # Copyright 2016 gRPC authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """Definition of targets to build distribution packages."""
  16. import os.path
  17. import sys
  18. sys.path.insert(0, os.path.abspath('..'))
  19. import python_utils.jobset as jobset
  20. def create_docker_jobspec(name,
  21. dockerfile_dir,
  22. shell_command,
  23. environ={},
  24. flake_retries=0,
  25. timeout_retries=0):
  26. """Creates jobspec for a task running under docker."""
  27. environ = environ.copy()
  28. docker_args = []
  29. for k, v in list(environ.items()):
  30. docker_args += ['-e', '%s=%s' % (k, v)]
  31. docker_env = {
  32. 'DOCKERFILE_DIR': dockerfile_dir,
  33. 'DOCKER_RUN_SCRIPT': 'tools/run_tests/dockerize/docker_run.sh',
  34. 'DOCKER_RUN_SCRIPT_COMMAND': shell_command,
  35. 'OUTPUT_DIR': 'artifacts'
  36. }
  37. jobspec = jobset.JobSpec(
  38. cmdline=['tools/run_tests/dockerize/build_and_run_docker.sh'] +
  39. docker_args,
  40. environ=docker_env,
  41. shortname='build_package.%s' % (name),
  42. timeout_seconds=30 * 60,
  43. flake_retries=flake_retries,
  44. timeout_retries=timeout_retries)
  45. return jobspec
  46. def create_jobspec(name,
  47. cmdline,
  48. environ=None,
  49. cwd=None,
  50. shell=False,
  51. flake_retries=0,
  52. timeout_retries=0,
  53. cpu_cost=1.0):
  54. """Creates jobspec."""
  55. jobspec = jobset.JobSpec(cmdline=cmdline,
  56. environ=environ,
  57. cwd=cwd,
  58. shortname='build_package.%s' % (name),
  59. timeout_seconds=10 * 60,
  60. flake_retries=flake_retries,
  61. timeout_retries=timeout_retries,
  62. cpu_cost=cpu_cost,
  63. shell=shell)
  64. return jobspec
  65. class CSharpPackage:
  66. """Builds C# packages."""
  67. def __init__(self, unity=False):
  68. self.unity = unity
  69. self.labels = ['package', 'csharp', 'linux']
  70. if unity:
  71. self.name = 'csharp_package_unity_linux'
  72. self.labels += ['unity']
  73. else:
  74. self.name = 'csharp_package_nuget_linux'
  75. self.labels += ['nuget']
  76. def pre_build_jobspecs(self):
  77. return []
  78. def build_jobspec(self, inner_jobs=None):
  79. del inner_jobs # arg unused as there is little opportunity for parallelizing
  80. environ = {
  81. 'GRPC_CSHARP_BUILD_SINGLE_PLATFORM_NUGET':
  82. os.getenv('GRPC_CSHARP_BUILD_SINGLE_PLATFORM_NUGET', '')
  83. }
  84. if self.unity:
  85. return create_docker_jobspec(
  86. self.name,
  87. 'tools/dockerfile/test/csharp_debian11_x64',
  88. 'src/csharp/build_unitypackage.sh',
  89. environ=environ)
  90. else:
  91. return create_docker_jobspec(
  92. self.name,
  93. 'tools/dockerfile/test/csharp_debian11_x64',
  94. 'src/csharp/build_nuget.sh',
  95. environ=environ)
  96. def __str__(self):
  97. return self.name
  98. class RubyPackage:
  99. """Collects ruby gems created in the artifact phase"""
  100. def __init__(self):
  101. self.name = 'ruby_package'
  102. self.labels = ['package', 'ruby', 'linux']
  103. def pre_build_jobspecs(self):
  104. return []
  105. def build_jobspec(self, inner_jobs=None):
  106. del inner_jobs # arg unused as this step simply collects preexisting artifacts
  107. return create_docker_jobspec(
  108. self.name, 'tools/dockerfile/grpc_artifact_centos6_x64',
  109. 'tools/run_tests/artifacts/build_package_ruby.sh')
  110. class PythonPackage:
  111. """Collects python eggs and wheels created in the artifact phase"""
  112. def __init__(self):
  113. self.name = 'python_package'
  114. self.labels = ['package', 'python', 'linux']
  115. def pre_build_jobspecs(self):
  116. return []
  117. def build_jobspec(self, inner_jobs=None):
  118. del inner_jobs # arg unused as this step simply collects preexisting artifacts
  119. # since the python package build does very little, we can use virtually
  120. # any image that has new-enough python, so reusing one of the images used
  121. # for artifact building seems natural.
  122. return create_docker_jobspec(
  123. self.name,
  124. 'tools/dockerfile/grpc_artifact_python_manylinux2014_x64',
  125. 'tools/run_tests/artifacts/build_package_python.sh',
  126. environ={'PYTHON': '/opt/python/cp39-cp39/bin/python'})
  127. class PHPPackage:
  128. """Copy PHP PECL package artifact"""
  129. def __init__(self):
  130. self.name = 'php_package'
  131. self.labels = ['package', 'php', 'linux']
  132. def pre_build_jobspecs(self):
  133. return []
  134. def build_jobspec(self, inner_jobs=None):
  135. del inner_jobs # arg unused as this step simply collects preexisting artifacts
  136. return create_docker_jobspec(
  137. self.name, 'tools/dockerfile/grpc_artifact_centos6_x64',
  138. 'tools/run_tests/artifacts/build_package_php.sh')
  139. def targets():
  140. """Gets list of supported targets"""
  141. return [
  142. CSharpPackage(),
  143. CSharpPackage(unity=True),
  144. RubyPackage(),
  145. PythonPackage(),
  146. PHPPackage()
  147. ]