Skip to content

Commit b202935

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

File tree

1 file changed

+73
-57
lines changed

1 file changed

+73
-57
lines changed

docker/docker.bzl

+73-57
Original file line numberDiff line numberDiff line change
@@ -30,55 +30,65 @@ 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=[], overrides={}):
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+
gcr_release = overrides.get("containerregistry", CONTAINERREGISTRY_RELEASE)
36+
if "puller" not in excludes:
37+
native.http_file(
38+
name = "puller",
39+
url = ("https://storage.googleapis.com/containerregistry-releases/" +
40+
gcr_release + "/puller.par"),
41+
sha256 = overrides.get(
42+
"puller", "90a76d01ee57a5df7353a533c96966822c9efda61636c11eac11344171556017"),
43+
executable = True,
44+
)
4245

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-
)
46+
if "pusher" not in excludes:
47+
native.http_file(
48+
name = "pusher",
49+
url = ("https://storage.googleapis.com/containerregistry-releases/" +
50+
gcr_release + "/pusher.par"),
51+
sha256 = overrides.get(
52+
"pusher", "1989ceb41144784dccb3476cea5b5f1bef112bb0aae56544b9c56572894c38ab"),
53+
executable = True,
54+
)
5055

51-
native.git_repository(
52-
name = "containerregistry",
53-
remote = "https://github.com/google/containerregistry.git",
54-
tag = CONTAINERREGISTRY_RELEASE,
55-
)
56+
if "containerregistry" not in excludes:
57+
native.git_repository(
58+
name = "containerregistry",
59+
remote = "https://github.com/google/containerregistry.git",
60+
tag = gcr_release,
61+
)
5662

5763
# TODO(mattmoor): Remove all of this (copied from google/containerregistry)
5864
# 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 = """
65+
if "httplib2" not in excludes:
66+
# TODO(mattmoor): Is there a clean way to override?
67+
native.new_http_archive(
68+
name = "httplib2",
69+
url = "https://codeload.github.com/httplib2/httplib2/tar.gz/v0.10.3",
70+
sha256 = "d1bee28a68cc665c451c83d315e3afdbeb5391f08971dcc91e060d5ba16986f1",
71+
strip_prefix = "httplib2-0.10.3/python2/httplib2/",
72+
type = "tar.gz",
73+
build_file_content = """
6674
py_library(
6775
name = "httplib2",
6876
srcs = glob(["**/*.py"]),
6977
data = ["cacerts.txt"],
7078
visibility = ["//visibility:public"]
7179
)""",
72-
)
80+
)
7381

7482
# 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 = """
83+
if "six" not in excludes:
84+
# TODO(mattmoor): Is there a clean way to override?
85+
native.new_http_archive(
86+
name = "six",
87+
url = "https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz",
88+
sha256 = "e24052411fc4fbd1f672635537c3fc2330d9481b18c0317695b46259512c91d5",
89+
strip_prefix = "six-1.9.0/",
90+
type = "tar.gz",
91+
build_file_content = """
8292
# Rename six.py to __init__.py
8393
genrule(
8494
name = "rename",
@@ -91,16 +101,18 @@ py_library(
91101
srcs = [":__init__.py"],
92102
visibility = ["//visibility:public"],
93103
)"""
94-
)
104+
)
95105

96106
# 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 = """
107+
if "oauth2client" not in excludes:
108+
# TODO(mattmoor): Is there a clean way to override?
109+
native.new_http_archive(
110+
name = "oauth2client",
111+
url = "https://codeload.github.com/google/oauth2client/tar.gz/v4.0.0",
112+
sha256 = "7230f52f7f1d4566a3f9c3aeb5ffe2ed80302843ce5605853bee1f08098ede46",
113+
strip_prefix = "oauth2client-4.0.0/oauth2client/",
114+
type = "tar.gz",
115+
build_file_content = """
104116
py_library(
105117
name = "oauth2client",
106118
srcs = glob(["**/*.py"]),
@@ -110,26 +122,30 @@ py_library(
110122
"@six//:six",
111123
]
112124
)"""
113-
)
125+
)
114126

115127
# 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 = """
128+
if "concurrent" not in excludes:
129+
# TODO(mattmoor): Is there a clean way to override?
130+
native.new_http_archive(
131+
name = "concurrent",
132+
url = "https://codeload.github.com/agronholm/pythonfutures/tar.gz/3.0.5",
133+
sha256 = "a7086ddf3c36203da7816f7e903ce43d042831f41a9705bc6b4206c574fcb765",
134+
strip_prefix = "pythonfutures-3.0.5/concurrent/",
135+
type = "tar.gz",
136+
build_file_content = """
123137
py_library(
124138
name = "concurrent",
125139
srcs = glob(["**/*.py"]),
126140
visibility = ["//visibility:public"]
127141
)"""
128-
)
142+
)
129143

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

0 commit comments

Comments
 (0)