• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env ruby
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
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
26  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
41  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
57