Skip to content

Commit

Permalink
Add build with GCB support to notebook controller (kubeflow#2486)
Browse files Browse the repository at this point in the history
* fix

* fix

* ignore
  • Loading branch information
lluunn authored and k8s-ci-robot committed Feb 15, 2019
1 parent ac7a7ae commit 67c9a4d
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/notebook-controller/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ bin
*.swp
*.swo
*~

gcb_build/**
20 changes: 20 additions & 0 deletions components/notebook-controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ IMG ?= gcr.io/kubeflow-images-public/notebook-controller
TAG ?= $(eval TAG := $(shell date +v%Y%m%d)-$(shell git describe --tags --always --dirty)-$(shell git diff | shasum -a256 | cut -c -6))$(TAG)
GOLANG_VERSION ?= 1.11.2

# Whether to use cached images with GCB
USE_IMAGE_CACHE ?= true

all: test manager

# Run tests
Expand Down Expand Up @@ -60,3 +63,20 @@ build-gcr: test
push-gcr: build-gcr
docker push $(IMG):$(TAG)
@echo Pushed $(IMG):$(TAG)

# Build the GCB workflow
build-gcb-spec:
rm -rf ./gcb_build
mkdir -p gcb_build
jsonnet ./gcb_build.jsonnet --ext-str imageBase=$(IMG) \
--ext-str gitVersion=$(GIT_VERSION) --ext-str tag=$(TAG) \
--ext-str useImageCache=$(USE_IMAGE_CACHE) \
> ./gcb_build/image_build.json

# Build using GCB. This is useful if we are on a slow internet connection
# and don't want to pull images locally.
# Its also used to build from our CI system.
build-gcb: build-gcb-spec
gcloud builds submit --machine-type=n1-highcpu-32 --project=kubeflow-ci \
--config=./gcb_build/image_build.json \
--timeout=3600 .
23 changes: 23 additions & 0 deletions components/notebook-controller/gcb_build.jsonnet
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,
}
74 changes: 74 additions & 0 deletions tools/gcb/template.libsonnet
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,
}

0 comments on commit 67c9a4d

Please sign in to comment.