-
Notifications
You must be signed in to change notification settings - Fork 69
/
def.bzl
72 lines (67 loc) · 2.33 KB
/
def.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("@io_bazel_rules_docker//container:image.bzl", "container_image")
load("@io_bazel_rules_docker//container:bundle.bzl", "container_bundle")
load("@io_bazel_rules_docker//contrib:push-all.bzl", "container_push")
load("@io_bazel_rules_docker//go:image.bzl", _go_image = "go_image")
## make_image is a macro for creating :app and :image targets
def go_image(
name, # use "image"
base = None,
stamp = "@io_bazel_rules_docker//stamp:always", # stamp by default, but allow overrides
app_name = "app",
**kwargs):
_go_image(
name = app_name,
base = base,
embed = [":go_default_library"],
goarch = "amd64",
goos = "linux",
pure = "on",
)
container_image(
name = name,
base = ":" + app_name,
stamp = stamp,
**kwargs
)
# push_image creates a bundle of container images, and a target to push them.
def push_image(
name,
bundle_name = "bundle",
images = None):
container_bundle(
name = bundle_name,
images = images,
)
container_push(
name = name,
bundle = ":" + bundle_name,
format = "Docker", # TODO(fejta): consider OCI?
)
# tags appends default tags to name
#
# In particular, names is a {image_prefix: image_target} mapping, which gets
# expanded into three full image paths:
# image_prefix:latest
# image_prefix:latest-{BUILD_USER}
# image_prefix:{DOCKER_TAG}
# (See hack/print-workspace-status.sh for how BUILD_USER and DOCKER_TAG are created.
def tags(targets):
outs = {}
for img, target in targets.items():
outs["%s:{DOCKER_TAG}" % img] = target
outs["%s:latest-{BUILD_USER}" % img] = target
outs["%s:latest" % img] = target
return outs