forked from prysmaticlabs/prysm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBUILD.bazel
101 lines (88 loc) · 2.56 KB
/
BUILD.bazel
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@io_bazel_rules_docker//contrib:passwd.bzl", "passwd_entry", "passwd_file")
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("//tools:build_settings.bzl", "base_image")
################################################################################
## Docker images as non-root user ##
################################################################################
# Create a passwd file with a root and nonroot user and uid.
passwd_entry(
name = "root_user",
gid = 0,
tags = ["manual"],
uid = 0,
username = "root",
)
passwd_entry(
name = "nonroot_user",
info = "nonroot",
tags = ["manual"],
uid = 1001,
username = "nonroot",
)
passwd_file(
name = "passwd",
entries = [
":root_user",
":nonroot_user",
],
tags = ["manual"],
)
# Create a tar file containing the created passwd file
pkg_tar(
name = "passwd_tar",
srcs = [":passwd"],
mode = "0o644",
package_dir = "etc",
tags = ["manual"],
)
CC_DEFAULT_BASE = select({
"@io_bazel_rules_docker//:debug": "@cc_debug_image_base//image",
"@io_bazel_rules_docker//:fastbuild": "@cc_image_base//image",
"@io_bazel_rules_docker//:optimized": "@cc_image_base//image",
"//conditions:default": "@cc_image_base//image",
})
GO_DEFAULT_BASE = select({
"@io_bazel_rules_docker//:debug": "@go_debug_image_base//image",
"@io_bazel_rules_docker//:fastbuild": "@go_image_base//image",
"@io_bazel_rules_docker//:optimized": "@go_image_base//image",
"//conditions:default": "@go_image_base//image",
})
# Include it in our base image as a tar.
container_image(
name = "cc_image",
base = CC_DEFAULT_BASE,
tags = ["manual"],
tars = [":passwd_tar"],
user = "root",
visibility = ["//visibility:public"],
)
container_image(
name = "go_image",
base = GO_DEFAULT_BASE,
tags = ["manual"],
tars = [":passwd_tar"],
user = "root",
visibility = ["//visibility:public"],
)
base_image(
name = "base_image",
build_setting_default = "cc_image",
tags = ["manual"],
)
config_setting(
name = "base_image_alpine",
flag_values = {"//tools:base_image": "alpine"},
)
config_setting(
name = "base_image_cc",
flag_values = {"//tools:base_image": "cc_image"},
)
container_image(
name = "alpine_cc_image",
base = "@alpine_cc_linux_amd64//image",
tags = ["manual"],
tars = [":passwd_tar"],
user = "root",
visibility = ["//visibility:public"],
)