blob: ce3f08dfbc98dc6925b60f7fd114aa5cecf7268f [file] [log] [blame]
Nathaniel Manistacbf21da2016-02-02 22:17:44 +00001#!/usr/bin/env python2.7
Jan Tattermuschbe538a12016-01-28 14:58:15 -08002# Copyright 2016, Google Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above
12# copyright notice, this list of conditions and the following disclaimer
13# in the documentation and/or other materials provided with the
14# distribution.
15# * Neither the name of Google Inc. nor the names of its
16# contributors may be used to endorse or promote products derived from
17# this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31"""Definition of targets to build distribution packages."""
32
33import jobset
34
murgatroid99dc3b4a42016-02-03 12:57:49 -080035def create_docker_jobspec(name, dockerfile_dir, shell_command, environ={},
36 flake_retries=0, timeout_retries=0):
37 """Creates jobspec for a task running under docker."""
38 environ = environ.copy()
39 environ['RUN_COMMAND'] = shell_command
40
41 docker_args=[]
siddharthshukla0589e532016-07-07 16:08:01 +020042 for k,v in environ.items():
murgatroid99dc3b4a42016-02-03 12:57:49 -080043 docker_args += ['-e', '%s=%s' % (k, v)]
44 docker_env = {'DOCKERFILE_DIR': dockerfile_dir,
Jan Tattermusch9835d4b2016-04-29 15:05:05 -070045 'DOCKER_RUN_SCRIPT': 'tools/run_tests/dockerize/docker_run.sh',
murgatroid99dc3b4a42016-02-03 12:57:49 -080046 'OUTPUT_DIR': 'artifacts'}
47 jobspec = jobset.JobSpec(
Jan Tattermusch9835d4b2016-04-29 15:05:05 -070048 cmdline=['tools/run_tests/dockerize/build_and_run_docker.sh'] + docker_args,
murgatroid99dc3b4a42016-02-03 12:57:49 -080049 environ=docker_env,
murgatroid993c3e58e2016-02-03 13:43:29 -080050 shortname='build_package.%s' % (name),
murgatroid99dc3b4a42016-02-03 12:57:49 -080051 timeout_seconds=30*60,
52 flake_retries=flake_retries,
53 timeout_retries=timeout_retries)
54 return jobspec
Jan Tattermuschbe538a12016-01-28 14:58:15 -080055
56def create_jobspec(name, cmdline, environ=None, cwd=None, shell=False,
57 flake_retries=0, timeout_retries=0):
58 """Creates jobspec."""
59 jobspec = jobset.JobSpec(
60 cmdline=cmdline,
61 environ=environ,
62 cwd=cwd,
63 shortname='build_package.%s' % (name),
64 timeout_seconds=10*60,
65 flake_retries=flake_retries,
66 timeout_retries=timeout_retries,
67 shell=shell)
68 return jobspec
69
70
Jan Tattermusch3c603922016-02-05 18:17:55 -080071class CSharpPackage:
Jan Tattermuschbe538a12016-01-28 14:58:15 -080072 """Builds C# nuget packages."""
73
Jan Tattermusch2c084ee2016-06-28 16:54:17 -070074 def __init__(self, use_coreclr=False):
75 self.use_coreclr = use_coreclr
76 self.name = 'csharp_package_coreclr' if use_coreclr else 'csharp_package'
77 self.labels = ['package', 'csharp']
78 if use_coreclr:
79 self.labels += ['linux']
80 else:
81 self.labels += ['windows']
Jan Tattermuschbe538a12016-01-28 14:58:15 -080082
83 def pre_build_jobspecs(self):
84 return []
85
86 def build_jobspec(self):
Jan Tattermusch2c084ee2016-06-28 16:54:17 -070087 if self.use_coreclr:
88 return create_docker_jobspec(
89 self.name,
90 'tools/dockerfile/test/csharp_coreclr_x64',
91 'tools/run_tests/build_package_csharp_coreclr.sh')
92 else:
93 return create_jobspec(self.name,
94 ['build_packages.bat'],
95 cwd='src\\csharp',
96 shell=True)
Jan Tattermuschbe538a12016-01-28 14:58:15 -080097
98 def __str__(self):
99 return self.name
100
Jan Tattermusch3c603922016-02-05 18:17:55 -0800101
102class NodePackage:
103 """Builds Node NPM package and collects precompiled binaries"""
murgatroid99dc3b4a42016-02-03 12:57:49 -0800104
105 def __init__(self):
Jan Tattermusch3c603922016-02-05 18:17:55 -0800106 self.name = 'node_package'
murgatroid993c3e58e2016-02-03 13:43:29 -0800107 self.labels = ['package', 'node', 'linux']
murgatroid99dc3b4a42016-02-03 12:57:49 -0800108
109 def pre_build_jobspecs(self):
110 return []
111
112 def build_jobspec(self):
113 return create_docker_jobspec(
114 self.name,
115 'tools/dockerfile/grpc_artifact_linux_x64',
116 'tools/run_tests/build_package_node.sh')
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800117
Jan Tattermusch3c603922016-02-05 18:17:55 -0800118
119class RubyPackage:
120 """Collects ruby gems created in the artifact phase"""
121
122 def __init__(self):
123 self.name = 'ruby_package'
124 self.labels = ['package', 'ruby', 'linux']
125
126 def pre_build_jobspecs(self):
127 return []
128
129 def build_jobspec(self):
130 return create_docker_jobspec(
131 self.name,
132 'tools/dockerfile/grpc_artifact_linux_x64',
133 'tools/run_tests/build_package_ruby.sh')
134
135
136class PythonPackage:
137 """Collects python eggs and wheels created in the artifact phase"""
138
139 def __init__(self):
140 self.name = 'python_package'
141 self.labels = ['package', 'python', 'linux']
142
143 def pre_build_jobspecs(self):
144 return []
145
146 def build_jobspec(self):
147 return create_docker_jobspec(
148 self.name,
149 'tools/dockerfile/grpc_artifact_linux_x64',
150 'tools/run_tests/build_package_python.sh')
151
152
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800153class PHPPackage:
Stanley Cheungbf74d692016-02-23 22:39:25 -0800154 """Copy PHP PECL package artifact"""
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800155
156 def __init__(self):
157 self.name = 'php_package'
158 self.labels = ['package', 'php', 'linux']
159
160 def pre_build_jobspecs(self):
161 return []
162
163 def build_jobspec(self):
164 return create_docker_jobspec(
165 self.name,
166 'tools/dockerfile/grpc_artifact_linux_x64',
167 'tools/run_tests/build_package_php.sh')
168
169
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800170def targets():
171 """Gets list of supported targets"""
Jan Tattermusch3c603922016-02-05 18:17:55 -0800172 return [CSharpPackage(),
Jan Tattermusch2c084ee2016-06-28 16:54:17 -0700173 CSharpPackage(use_coreclr=True),
Jan Tattermusch3c603922016-02-05 18:17:55 -0800174 NodePackage(),
175 RubyPackage(),
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800176 PythonPackage(),
177 PHPPackage()]