blob: 010e2067b816b0f501ec37d859531b8cdb0e61ce [file] [log] [blame]
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +01001#!/usr/bin/env ruby
Jan Tattermusch7897ae92017-06-07 22:57:36 +02002# Copyright 2016 gRPC authors.
Nicolas "Pixel" Noblefb2d8f52016-02-01 01:24:44 +01003#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02004# 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
Nicolas "Pixel" Noblefb2d8f52016-02-01 01:24:44 +01007#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02008# http://www.apache.org/licenses/LICENSE-2.0
Nicolas "Pixel" Noblefb2d8f52016-02-01 01:24:44 +01009#
Jan Tattermusch7897ae92017-06-07 22:57:36 +020010# 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.
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010015
16def grpc_root()
17 File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
18end
19
20def docker_for_windows_image()
21 require 'digest'
22
23 dockerfile = File.join(grpc_root, 'third_party', 'rake-compiler-dock', 'Dockerfile')
24 dockerpath = File.dirname(dockerfile)
25 version = Digest::SHA1.file(dockerfile).hexdigest
Jan Tattermusch27af5b12017-08-31 16:45:33 +020026 image_name = 'rake-compiler-dock_' + version
27 # if "DOCKERHUB_ORGANIZATION" env is set, we try to pull the pre-built
28 # rake-compiler-dock image from dockerhub rather then building from scratch.
29 if ENV.has_key?('DOCKERHUB_ORGANIZATION')
30 image_name = ENV['DOCKERHUB_ORGANIZATION'] + '/' + image_name
31 cmd = "docker pull #{image_name}"
32 puts cmd
33 system cmd
34 raise "Failed to pull the docker image." unless $? == 0
35 else
36 cmd = "docker build -t #{image_name} --file #{dockerfile} #{dockerpath}"
37 puts cmd
38 system cmd
39 raise "Failed to build the docker image." unless $? == 0
40 end
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010041 image_name
42end
43
44def docker_for_windows(args)
45 require 'rake_compiler_dock'
46
47 args = 'bash -l' if args.empty?
48
49 ENV['RAKE_COMPILER_DOCK_IMAGE'] = docker_for_windows_image
50
51 RakeCompilerDock.sh args
52end
53
54if __FILE__ == $0
55 docker_for_windows $*.join(' ')
56end