|
| 1 | +/* |
| 2 | +Copyright 2017 The Kubernetes 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 | +*/ |
| 16 | + |
| 17 | +package main |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "os/exec" |
| 22 | +) |
| 23 | + |
| 24 | +const ( |
| 25 | + buildDefault = "quick" |
| 26 | +) |
| 27 | + |
| 28 | +type buildStrategy string |
| 29 | + |
| 30 | +// Support both --build and --build=foo |
| 31 | +func (b *buildStrategy) IsBoolFlag() bool { |
| 32 | + return true |
| 33 | +} |
| 34 | + |
| 35 | +// Return b as a string |
| 36 | +func (b *buildStrategy) String() string { |
| 37 | + return string(*b) |
| 38 | +} |
| 39 | + |
| 40 | +// Set to --build=B or buildDefault if just --build |
| 41 | +func (b *buildStrategy) Set(value string) error { |
| 42 | + if value == "true" { // just --build, choose default |
| 43 | + value = buildDefault |
| 44 | + } |
| 45 | + switch value { |
| 46 | + case "bazel", "quick", "release": |
| 47 | + *b = buildStrategy(value) |
| 48 | + return nil |
| 49 | + } |
| 50 | + return fmt.Errorf("Bad build strategy: %v (use: bash, quick, release)", value) |
| 51 | +} |
| 52 | + |
| 53 | +// True when this kubetest invocation wants to build a release |
| 54 | +func (b *buildStrategy) Enabled() bool { |
| 55 | + return *b != "" |
| 56 | +} |
| 57 | + |
| 58 | +// Build kubernetes according to specified strategy. |
| 59 | +// This may be a bazel, quick or full release build depending on --build=B. |
| 60 | +func (b *buildStrategy) Build() error { |
| 61 | + var target string |
| 62 | + switch *b { |
| 63 | + case "bazel": |
| 64 | + target = "bazel-build" |
| 65 | + case "quick": |
| 66 | + target = "quick-release" |
| 67 | + case "release": |
| 68 | + target = "release" |
| 69 | + default: |
| 70 | + return fmt.Errorf("Unknown build strategy: %v", b) |
| 71 | + } |
| 72 | + |
| 73 | + // TODO(fejta): FIX ME |
| 74 | + // The build-release script needs stdin to ask the user whether |
| 75 | + // it's OK to download the docker image. |
| 76 | + return finishRunning(exec.Command("make", target)) |
| 77 | +} |
0 commit comments