• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17import os.path
18import sys
19
20sys.path.insert(0, os.path.abspath('..'))
21import python_utils.jobset as jobset
22
23
24def create_docker_jobspec(name,
25                          dockerfile_dir,
26                          shell_command,
27                          environ={},
28                          flake_retries=0,
29                          timeout_retries=0):
30    """Creates jobspec for a task running under docker."""
31    environ = environ.copy()
32    environ['RUN_COMMAND'] = shell_command
33
34    docker_args = []
35    for k, v in environ.items():
36        docker_args += ['-e', '%s=%s' % (k, v)]
37    docker_env = {
38        'DOCKERFILE_DIR': dockerfile_dir,
39        'DOCKER_RUN_SCRIPT': 'tools/run_tests/dockerize/docker_run.sh',
40        'OUTPUT_DIR': 'artifacts'
41    }
42    jobspec = jobset.JobSpec(
43        cmdline=['tools/run_tests/dockerize/build_and_run_docker.sh'] +
44        docker_args,
45        environ=docker_env,
46        shortname='build_package.%s' % (name),
47        timeout_seconds=30 * 60,
48        flake_retries=flake_retries,
49        timeout_retries=timeout_retries)
50    return jobspec
51
52
53def create_jobspec(name,
54                   cmdline,
55                   environ=None,
56                   cwd=None,
57                   shell=False,
58                   flake_retries=0,
59                   timeout_retries=0,
60                   cpu_cost=1.0):
61    """Creates jobspec."""
62    jobspec = jobset.JobSpec(cmdline=cmdline,
63                             environ=environ,
64                             cwd=cwd,
65                             shortname='build_package.%s' % (name),
66                             timeout_seconds=10 * 60,
67                             flake_retries=flake_retries,
68                             timeout_retries=timeout_retries,
69                             cpu_cost=cpu_cost,
70                             shell=shell)
71    return jobspec
72
73
74class CSharpPackage:
75    """Builds C# packages."""
76
77    def __init__(self, unity=False):
78        self.unity = unity
79        self.labels = ['package', 'csharp', 'linux']
80        if unity:
81            self.name = 'csharp_package_unity_linux'
82            self.labels += ['unity']
83        else:
84            self.name = 'csharp_package_nuget_linux'
85            self.labels += ['nuget']
86
87    def pre_build_jobspecs(self):
88        return []
89
90    def build_jobspec(self):
91        if self.unity:
92            return create_docker_jobspec(
93                self.name, 'tools/dockerfile/test/csharp_stretch_x64',
94                'src/csharp/build_unitypackage.sh')
95        else:
96            return create_docker_jobspec(
97                self.name, 'tools/dockerfile/test/csharp_stretch_x64',
98                'src/csharp/build_nuget.sh')
99
100    def __str__(self):
101        return self.name
102
103
104class RubyPackage:
105    """Collects ruby gems created in the artifact phase"""
106
107    def __init__(self):
108        self.name = 'ruby_package'
109        self.labels = ['package', 'ruby', 'linux']
110
111    def pre_build_jobspecs(self):
112        return []
113
114    def build_jobspec(self):
115        return create_docker_jobspec(
116            self.name, 'tools/dockerfile/grpc_artifact_centos6_x64',
117            'tools/run_tests/artifacts/build_package_ruby.sh')
118
119
120class PythonPackage:
121    """Collects python eggs and wheels created in the artifact phase"""
122
123    def __init__(self):
124        self.name = 'python_package'
125        self.labels = ['package', 'python', 'linux']
126
127    def pre_build_jobspecs(self):
128        return []
129
130    def build_jobspec(self):
131        # since the python package build does very little, we can use virtually
132        # any image that has new-enough python, so reusing one of the images used
133        # for artifact building seems natural.
134        return create_docker_jobspec(
135            self.name,
136            'tools/dockerfile/grpc_artifact_python_manylinux2014_x64',
137            'tools/run_tests/artifacts/build_package_python.sh',
138            environ={'PYTHON': '/opt/python/cp39-cp39/bin/python'})
139
140
141class PHPPackage:
142    """Copy PHP PECL package artifact"""
143
144    def __init__(self):
145        self.name = 'php_package'
146        self.labels = ['package', 'php', 'linux']
147
148    def pre_build_jobspecs(self):
149        return []
150
151    def build_jobspec(self):
152        return create_docker_jobspec(
153            self.name, 'tools/dockerfile/grpc_artifact_centos6_x64',
154            'tools/run_tests/artifacts/build_package_php.sh')
155
156
157def targets():
158    """Gets list of supported targets"""
159    return [
160        CSharpPackage(),
161        CSharpPackage(unity=True),
162        RubyPackage(),
163        PythonPackage(),
164        PHPPackage()
165    ]
166