Skip to content

Commit 5687779

Browse files
committed
Add limited support for overriding and excluding dependencies.
Fixes: bazelbuild#55 Fixes: bazelbuild#77
1 parent 48a438c commit 5687779

File tree

1 file changed

+76
-57
lines changed

1 file changed

+76
-57
lines changed

docker/docker.bzl

+76-57
Original file line numberDiff line numberDiff line change
@@ -30,55 +30,68 @@ load(":push.bzl", "docker_push")
3030
# The release of the github.com/google/containerregistry to consume.
3131
CONTAINERREGISTRY_RELEASE = "v0.0.11"
3232

33-
def docker_repositories():
33+
def docker_repositories(excludes=None, overrides=None):
3434
"""Download dependencies of docker rules."""
35-
native.http_file(
36-
name = "puller",
37-
url = ("https://storage.googleapis.com/containerregistry-releases/" +
38-
CONTAINERREGISTRY_RELEASE + "/puller.par"),
39-
sha256 = "90a76d01ee57a5df7353a533c96966822c9efda61636c11eac11344171556017",
40-
executable = True,
41-
)
35+
excludes = excludes or []
36+
overrides = overrides or {}
4237

43-
native.http_file(
44-
name = "pusher",
45-
url = ("https://storage.googleapis.com/containerregistry-releases/" +
46-
CONTAINERREGISTRY_RELEASE + "/pusher.par"),
47-
sha256 = "1989ceb41144784dccb3476cea5b5f1bef112bb0aae56544b9c56572894c38ab",
48-
executable = True,
49-
)
38+
gcr_release = overrides.get("containerregistry", CONTAINERREGISTRY_RELEASE)
39+
if "puller" not in excludes:
40+
native.http_file(
41+
name = "puller",
42+
url = ("https://storage.googleapis.com/containerregistry-releases/" +
43+
gcr_release + "/puller.par"),
44+
sha256 = overrides.get(
45+
"puller", "90a76d01ee57a5df7353a533c96966822c9efda61636c11eac11344171556017"),
46+
executable = True,
47+
)
5048

51-
native.git_repository(
52-
name = "containerregistry",
53-
remote = "https://github.com/google/containerregistry.git",
54-
tag = CONTAINERREGISTRY_RELEASE,
55-
)
49+
if "pusher" not in excludes:
50+
native.http_file(
51+
name = "pusher",
52+
url = ("https://storage.googleapis.com/containerregistry-releases/" +
53+
gcr_release + "/pusher.par"),
54+
sha256 = overrides.get(
55+
"pusher", "1989ceb41144784dccb3476cea5b5f1bef112bb0aae56544b9c56572894c38ab"),
56+
executable = True,
57+
)
58+
59+
if "containerregistry" not in excludes:
60+
native.git_repository(
61+
name = "containerregistry",
62+
remote = "https://github.com/google/containerregistry.git",
63+
tag = gcr_release,
64+
)
5665

5766
# TODO(mattmoor): Remove all of this (copied from google/containerregistry)
5867
# once transitive workspace instantiation lands.
59-
native.new_http_archive(
60-
name = "httplib2",
61-
url = "https://codeload.github.com/httplib2/httplib2/tar.gz/v0.10.3",
62-
sha256 = "d1bee28a68cc665c451c83d315e3afdbeb5391f08971dcc91e060d5ba16986f1",
63-
strip_prefix = "httplib2-0.10.3/python2/httplib2/",
64-
type = "tar.gz",
65-
build_file_content = """
68+
if "httplib2" not in excludes:
69+
# TODO(mattmoor): Is there a clean way to override?
70+
native.new_http_archive(
71+
name = "httplib2",
72+
url = "https://codeload.github.com/httplib2/httplib2/tar.gz/v0.10.3",
73+
sha256 = "d1bee28a68cc665c451c83d315e3afdbeb5391f08971dcc91e060d5ba16986f1",
74+
strip_prefix = "httplib2-0.10.3/python2/httplib2/",
75+
type = "tar.gz",
76+
build_file_content = """
6677
py_library(
6778
name = "httplib2",
6879
srcs = glob(["**/*.py"]),
6980
data = ["cacerts.txt"],
7081
visibility = ["//visibility:public"]
7182
)""",
72-
)
83+
)
7384

7485
# Used by oauth2client
75-
native.new_http_archive(
76-
name = "six",
77-
url = "https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz",
78-
sha256 = "e24052411fc4fbd1f672635537c3fc2330d9481b18c0317695b46259512c91d5",
79-
strip_prefix = "six-1.9.0/",
80-
type = "tar.gz",
81-
build_file_content = """
86+
if "six" not in excludes:
87+
# TODO(mattmoor): Is there a clean way to override?
88+
native.new_http_archive(
89+
name = "six",
90+
url = "https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz",
91+
sha256 = "e24052411fc4fbd1f672635537c3fc2330d9481b18c0317695b46259512c91d5",
92+
strip_prefix = "six-1.9.0/",
93+
type = "tar.gz",
94+
build_file_content = """
8295
# Rename six.py to __init__.py
8396
genrule(
8497
name = "rename",
@@ -91,16 +104,18 @@ py_library(
91104
srcs = [":__init__.py"],
92105
visibility = ["//visibility:public"],
93106
)"""
94-
)
107+
)
95108

96109
# Used for authentication in containerregistry
97-
native.new_http_archive(
98-
name = "oauth2client",
99-
url = "https://codeload.github.com/google/oauth2client/tar.gz/v4.0.0",
100-
sha256 = "7230f52f7f1d4566a3f9c3aeb5ffe2ed80302843ce5605853bee1f08098ede46",
101-
strip_prefix = "oauth2client-4.0.0/oauth2client/",
102-
type = "tar.gz",
103-
build_file_content = """
110+
if "oauth2client" not in excludes:
111+
# TODO(mattmoor): Is there a clean way to override?
112+
native.new_http_archive(
113+
name = "oauth2client",
114+
url = "https://codeload.github.com/google/oauth2client/tar.gz/v4.0.0",
115+
sha256 = "7230f52f7f1d4566a3f9c3aeb5ffe2ed80302843ce5605853bee1f08098ede46",
116+
strip_prefix = "oauth2client-4.0.0/oauth2client/",
117+
type = "tar.gz",
118+
build_file_content = """
104119
py_library(
105120
name = "oauth2client",
106121
srcs = glob(["**/*.py"]),
@@ -110,26 +125,30 @@ py_library(
110125
"@six//:six",
111126
]
112127
)"""
113-
)
128+
)
114129

115130
# Used for parallel execution in containerregistry
116-
native.new_http_archive(
117-
name = "concurrent",
118-
url = "https://codeload.github.com/agronholm/pythonfutures/tar.gz/3.0.5",
119-
sha256 = "a7086ddf3c36203da7816f7e903ce43d042831f41a9705bc6b4206c574fcb765",
120-
strip_prefix = "pythonfutures-3.0.5/concurrent/",
121-
type = "tar.gz",
122-
build_file_content = """
131+
if "concurrent" not in excludes:
132+
# TODO(mattmoor): Is there a clean way to override?
133+
native.new_http_archive(
134+
name = "concurrent",
135+
url = "https://codeload.github.com/agronholm/pythonfutures/tar.gz/3.0.5",
136+
sha256 = "a7086ddf3c36203da7816f7e903ce43d042831f41a9705bc6b4206c574fcb765",
137+
strip_prefix = "pythonfutures-3.0.5/concurrent/",
138+
type = "tar.gz",
139+
build_file_content = """
123140
py_library(
124141
name = "concurrent",
125142
srcs = glob(["**/*.py"]),
126143
visibility = ["//visibility:public"]
127144
)"""
128-
)
145+
)
129146

130147
# For packaging python tools.
131-
native.git_repository(
132-
name = "subpar",
133-
remote = "https://github.com/google/subpar",
134-
commit = "7e12cc130eb8f09c8cb02c3585a91a4043753c56",
135-
)
148+
if "subpar" not in excludes:
149+
native.git_repository(
150+
name = "subpar",
151+
remote = "https://github.com/google/subpar",
152+
commit = overrides.get(
153+
"subpar", "7e12cc130eb8f09c8cb02c3585a91a4043753c56"),
154+
)

0 commit comments

Comments
 (0)