Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 2 | # Copyright 2016 gRPC authors. |
Nicolas "Pixel" Noble | fb2d8f5 | 2016-02-01 01:24:44 +0100 | [diff] [blame] | 3 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Nicolas "Pixel" Noble | fb2d8f5 | 2016-02-01 01:24:44 +0100 | [diff] [blame] | 7 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
Nicolas "Pixel" Noble | fb2d8f5 | 2016-02-01 01:24:44 +0100 | [diff] [blame] | 9 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 15 | |
| 16 | def grpc_root() |
| 17 | File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) |
| 18 | end |
| 19 | |
| 20 | def 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 Tattermusch | 27af5b1 | 2017-08-31 16:45:33 +0200 | [diff] [blame] | 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 |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 41 | image_name |
| 42 | end |
| 43 | |
| 44 | def 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 |
| 52 | end |
| 53 | |
| 54 | if __FILE__ == $0 |
| 55 | docker_for_windows $*.join(' ') |
| 56 | end |