forked from kubeflow/kubeflow
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build with GCB support to notebook controller (kubeflow#2486)
* fix * fix * ignore
- Loading branch information
1 parent
ac7a7ae
commit 67c9a4d
Showing
4 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ bin | |
*.swp | ||
*.swo | ||
*~ | ||
|
||
gcb_build/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
|
||
local util = import "../../tools/gcb/template.libsonnet"; | ||
|
||
local useImageCache = util.toBool(std.extVar("useImageCache")); | ||
local image = std.extVar("imageBase") + ":" + std.extVar("tag"); | ||
local imageLatest = std.extVar("imageBase") + ":latest"; | ||
local gitVersion = std.extVar("gitVersion"); | ||
|
||
local workerSteps = util.subGraphTemplate { | ||
name: "notebook-controller-image", | ||
dockerFile: "./Dockerfile", | ||
contextDir: ".", | ||
useImageCache: useImageCache, | ||
image: image, | ||
imageLatest: imageLatest, | ||
gitVersion: gitVersion, | ||
}; | ||
|
||
{ | ||
steps: workerSteps.steps, | ||
images: workerSteps.images, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
|
||
// Convert non-boolean types like string,number to a boolean. | ||
// This is primarily intended for dealing with parameters that should be booleans. | ||
local toBool = function(x) { | ||
result:: | ||
if std.type(x) == "boolean" then | ||
x | ||
else if std.type(x) == "string" then | ||
std.asciiUpper(x) == "TRUE" | ||
else if std.type(x) == "number" then | ||
x != 0 | ||
else | ||
false, | ||
}.result, | ||
|
||
// A tempalte for defining the steps for building each image. | ||
local subGraphTemplate = { | ||
// following variables must be set | ||
name: null, | ||
|
||
dockerFile: null, | ||
buildArg: null, | ||
contextDir: ".", | ||
useImageCache: false, | ||
image: "", | ||
imageLatest: "", | ||
gitVersion: "", | ||
|
||
local template = self, | ||
local useImageCache = template.useImageCache, | ||
|
||
local pullStep = if useImageCache then [ | ||
{ | ||
id: "pull-" + template.name, | ||
name: "gcr.io/cloud-builders/docker", | ||
args: ["pull", template.imageLatest], | ||
waitFor: ["-"], | ||
}, | ||
] else [], | ||
|
||
images: [template.image, template.imageLatest], | ||
steps: pullStep + | ||
[ | ||
{ | ||
local buildArgList = if template.buildArg != null then ["--build-arg", template.buildArg] else [], | ||
local cacheList = if useImageCache then ["--cache-from=" + template.imageLatest] else [], | ||
|
||
id: "build-" + template.name, | ||
name: "gcr.io/cloud-builders/docker", | ||
args: [ | ||
"build", | ||
"-t", | ||
template.image, | ||
"--label=git-versions=" + template.gitVersion, | ||
] | ||
+ buildArgList | ||
+ [ | ||
"--file=" + template.dockerFile, | ||
] | ||
+ cacheList + [template.contextDir], | ||
waitFor: if useImageCache then ["pull-" + template.name] else ["-"], | ||
}, | ||
{ | ||
id: "tag-" + template.name, | ||
name: "gcr.io/cloud-builders/docker", | ||
args: ["tag", template.image, template.imageLatest], | ||
waitFor: ["build-" + template.name], | ||
}, | ||
], | ||
}, | ||
subGraphTemplate: subGraphTemplate, | ||
toBool: toBool, | ||
} |