Skip to content

Commit 770e67f

Browse files
authored
Revert to using gflags but use it from a pips package instead of Bazel Tools (#1535)
* Migrate to use absl from gflags * buildifier * Revert to using gflags but use it from pip instead Bazel tools no longer provides gflags #1533 * Remove unused absl import * use gflags properly * declaring more deps * fix more deps * fixing more deps * Fix one more dep
1 parent ddb67ed commit 770e67f

12 files changed

Lines changed: 91 additions & 50 deletions

File tree

container/BUILD

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
16+
load("@pip_deps//:requirements.bzl", "requirement")
1617

1718
package(default_visibility = ["//visibility:public"])
1819

@@ -43,7 +44,8 @@ py_library(
4344
srcs_version = "PY2AND3",
4445
visibility = ["//visibility:public"],
4546
deps = [
46-
"@io_abseil_py//absl/flags",
47+
requirement("python-gflags"),
48+
requirement("six"),
4749
"@rules_pkg//:archive",
4850
],
4951
)

container/build_tar.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""This tool build tar files from a list of inputs."""
1515

1616
from contextlib import contextmanager
17+
import gflags
1718
import gzip
1819
import io
1920
import json
@@ -25,86 +26,84 @@
2526
import tarfile
2627
import tempfile
2728

28-
from absl import flags
2929
from rules_pkg import archive
3030

31+
gflags.DEFINE_string('output', None, 'The output file, mandatory')
32+
gflags.MarkFlagAsRequired('output')
3133

32-
flags.DEFINE_string('output', None, 'The output file, mandatory')
33-
flags.mark_flag_as_required('output')
34+
gflags.DEFINE_multistring('file', [], 'A file to add to the layer')
3435

35-
flags.DEFINE_multi_string('file', [], 'A file to add to the layer')
36+
gflags.DEFINE_string('manifest', None, 'JSON manifest of contents to add to the layer')
3637

37-
flags.DEFINE_string('manifest', None, 'JSON manifest of contents to add to the layer')
38+
gflags.DEFINE_multistring('empty_file', [], 'An empty file to add to the layer')
3839

39-
flags.DEFINE_multi_string('empty_file', [], 'An empty file to add to the layer')
40+
gflags.DEFINE_multistring('empty_dir', [], 'An empty dir to add to the layer')
4041

41-
flags.DEFINE_multi_string('empty_dir', [], 'An empty dir to add to the layer')
42-
43-
flags.DEFINE_string(
42+
gflags.DEFINE_string(
4443
'mode', None, 'Force the mode on the added files (in octal).')
4544

46-
flags.DEFINE_string(
45+
gflags.DEFINE_string(
4746
'mtime', None, 'Set mtime on tar file entries. May be an integer or the'
4847
' value "portable", to get the value 2000-01-01, which is'
4948
' usable with non *nix OSes.')
5049

51-
flags.DEFINE_bool(
50+
gflags.DEFINE_bool(
5251
'enable_mtime_preservation', False, 'Preserve file mtimes from input tar file.')
5352

54-
flags.DEFINE_multi_string(
53+
gflags.DEFINE_multistring(
5554
'empty_root_dir',
5655
[],
5756
'An empty root directory to add to the layer. This will create a directory that'
5857
'is a peer of "root_directory". "empty_dir" creates an empty directory inside of'
5958
'"root_directory"')
6059

61-
flags.DEFINE_multi_string('tar', [], 'A tar file to add to the layer')
60+
gflags.DEFINE_multistring('tar', [], 'A tar file to add to the layer')
6261

63-
flags.DEFINE_multi_string('deb', [], 'A debian package to add to the layer')
62+
gflags.DEFINE_multistring('deb', [], 'A debian package to add to the layer')
6463

65-
flags.DEFINE_multi_string(
64+
gflags.DEFINE_multistring(
6665
'link', [],
6766
'Add a symlink a inside the layer ponting to b if a:b is specified')
68-
flags.register_validator(
67+
gflags.RegisterValidator(
6968
'link',
7069
lambda l: all(value.find(':') > 0 for value in l),
7170
message='--link value should contains a : separator')
7271

73-
flags.DEFINE_string(
72+
gflags.DEFINE_string(
7473
'directory', None, 'Directory in which to store the file inside the layer')
7574

76-
flags.DEFINE_string(
75+
gflags.DEFINE_string(
7776
'compression', None, 'Compression (`gz` or `bz2`), default is none.')
7877

79-
flags.DEFINE_multi_string(
78+
gflags.DEFINE_multistring(
8079
'modes', None,
8180
'Specific mode to apply to specific file (from the file argument),'
8281
' e.g., path/to/file=0o455.')
8382

84-
flags.DEFINE_multi_string('owners', None,
83+
gflags.DEFINE_multistring('owners', None,
8584
'Specify the numeric owners of individual files, '
8685
'e.g. path/to/file=0.0.')
8786

88-
flags.DEFINE_string('owner', '0.0',
87+
gflags.DEFINE_string('owner', '0.0',
8988
'Specify the numeric default owner of all files,'
9089
' e.g., 0.0')
9190

92-
flags.DEFINE_string('owner_name', None,
91+
gflags.DEFINE_string('owner_name', None,
9392
'Specify the owner name of all files, e.g. root.root.')
9493

95-
flags.DEFINE_multi_string('owner_names', None,
94+
gflags.DEFINE_multistring('owner_names', None,
9695
'Specify the owner names of individual files, e.g. '
9796
'path/to/file=root.root.')
9897

99-
flags.DEFINE_string(
98+
gflags.DEFINE_string(
10099
'root_directory', './', 'Default root directory is named "."'
101100
'Windows docker images require this be named "Files" instead of "."')
102101

103-
flags.DEFINE_string('xz_path', None,
102+
gflags.DEFINE_string('xz_path', None,
104103
'Specify the path to xz as a fallback when the Python '
105104
'lzma module is unavailable.')
106105

107-
FLAGS = flags.FLAGS
106+
FLAGS = gflags.FLAGS
108107

109108

110109
class TarFile(object):

repositories/requirements-pip.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ six==1.11.0
33
addict==2.1.2
44
# required by docker/security & deps
55
PyYAML==5.1
6-
6+
# Required by //container/build_tar.py
7+
python-gflags==3.1.2

testing/custom_toolchain_auth/WORKSPACE

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ load(
4545
container_repositories()
4646

4747
load(
48-
"@io_bazel_rules_docker//repositories:go_repositories.bzl",
49-
container_go_deps = "go_deps",
48+
"@io_bazel_rules_docker//repositories:deps.bzl",
49+
container_deps = "deps",
5050
)
5151

52-
container_go_deps()
52+
container_deps()
53+
54+
load("@io_bazel_rules_docker//repositories:pip_repositories.bzl", "pip_deps")
55+
56+
pip_deps()
5357

5458
load(
5559
"@io_bazel_rules_docker//container:container.bzl",

testing/custom_toolchain_flags/WORKSPACE

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ load(
4141
container_repositories()
4242

4343
load(
44-
"@io_bazel_rules_docker//repositories:go_repositories.bzl",
45-
container_go_deps = "go_deps",
44+
"@io_bazel_rules_docker//repositories:deps.bzl",
45+
container_deps = "deps",
4646
)
4747

48-
container_go_deps()
48+
container_deps()
49+
50+
load("@io_bazel_rules_docker//repositories:pip_repositories.bzl", "pip_deps")
51+
52+
pip_deps()
4953

5054
load("@io_bazel_rules_docker//container:container.bzl", "container_pull")
5155

testing/default_toolchain/WORKSPACE

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ load(
4848
container_repositories()
4949

5050
load(
51-
"@io_bazel_rules_docker//repositories:go_repositories.bzl",
52-
container_go_deps = "go_deps",
51+
"@io_bazel_rules_docker//repositories:deps.bzl",
52+
container_deps = "deps",
5353
)
5454

55-
container_go_deps()
55+
container_deps()
56+
57+
load("@io_bazel_rules_docker//repositories:pip_repositories.bzl", "pip_deps")
58+
59+
pip_deps()
5660

5761
load(
5862
"@io_bazel_rules_docker//container:container.bzl",

testing/download_pkgs_at_root/WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ load(
3434

3535
container_deps()
3636

37+
load("@io_bazel_rules_docker//repositories:pip_repositories.bzl", "pip_deps")
38+
39+
pip_deps()
40+
3741
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
3842

3943
# base_images_docker is needed to build ubuntu1604

testing/e2e.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ function test_container_push_with_auth() {
304304
# Run the container_push test in the Bazel workspace that configured
305305
# the docker toolchain rule to use authentication.
306306
cd "${ROOT}/testing/custom_toolchain_auth"
307-
bazel_opts=" --override_repository=io_bazel_rules_docker=${ROOT} --host_force_python=PY2"
307+
bazel_opts=" --override_repository=io_bazel_rules_docker=${ROOT}"
308308
echo "Attempting authenticated container_push..."
309309
EXPECT_CONTAINS "$(bazel run $bazel_opts @io_bazel_rules_docker//tests/container:push_test 2>&1)" "Successfully pushed Docker image to localhost:5000/docker/test:test"
310310
bazel clean
@@ -313,7 +313,7 @@ function test_container_push_with_auth() {
313313
# configured docker toolchain. The default configuration doesn't setup
314314
# authentication and this should fail.
315315
cd "${ROOT}/testing/default_toolchain"
316-
bazel_opts=" --override_repository=io_bazel_rules_docker=${ROOT} --host_force_python=PY2"
316+
bazel_opts=" --override_repository=io_bazel_rules_docker=${ROOT}"
317317
echo "Attempting unauthenticated container_push..."
318318
EXPECT_CONTAINS "$(bazel run $bazel_opts @io_bazel_rules_docker//tests/container:push_test 2>&1)" "unable to push image to localhost:5000/docker/test:test"
319319
bazel clean
@@ -350,7 +350,7 @@ function test_container_pull_with_auth() {
350350
launch_private_registry_with_auth
351351

352352
cd "${ROOT}/testing/custom_toolchain_auth"
353-
bazel_opts=" --override_repository=io_bazel_rules_docker=${ROOT} --host_force_python=PY2"
353+
bazel_opts=" --override_repository=io_bazel_rules_docker=${ROOT}"
354354
# Remove the old image if it exists
355355
docker rmi bazel/image:image || true
356356
# Push the locally built container to the private repo
@@ -362,7 +362,7 @@ function test_container_pull_with_auth() {
362362
# configured docker toolchain. The default configuration doesn't setup
363363
# authentication and this should fail.
364364
cd "${ROOT}/testing/default_toolchain"
365-
bazel_opts=" --override_repository=io_bazel_rules_docker=${ROOT} --host_force_python=PY2"
365+
bazel_opts=" --override_repository=io_bazel_rules_docker=${ROOT}"
366366
echo "Attempting unauthenticated container_pull..."
367367
EXPECT_CONTAINS "$(bazel run $bazel_opts @local_pull//image 2>&1)" "Image pull was unsuccessful: reading image \"localhost:5000/docker/test:test\""
368368
}

testing/e2e/top_level.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ load(
5151
container_repositories()
5252
5353
load(
54-
"@io_bazel_rules_docker//repositories:go_repositories.bzl",
55-
container_go_deps = "go_deps",
54+
"@io_bazel_rules_docker//repositories:deps.bzl",
55+
container_deps = "deps",
5656
)
5757
58-
container_go_deps()
58+
container_deps()
59+
60+
load("@io_bazel_rules_docker//repositories:pip_repositories.bzl", "pip_deps")
61+
62+
pip_deps()
5963
6064
load(
6165
"@io_bazel_rules_docker//docker:docker.bzl",

testing/examples/WORKSPACE

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ load(
2929
container_repositories()
3030

3131
load(
32-
"@io_bazel_rules_docker//repositories:go_repositories.bzl",
33-
container_go_deps = "go_deps",
32+
"@io_bazel_rules_docker//repositories:deps.bzl",
33+
container_deps = "deps",
3434
)
3535

36-
container_go_deps()
36+
container_deps()
37+
38+
load("@io_bazel_rules_docker//repositories:pip_repositories.bzl", "pip_deps")
39+
40+
pip_deps()
3741

3842
load("@io_bazel_rules_docker//container:pull.bzl", "container_pull")
3943
load("@io_bazel_rules_docker//contrib:dockerfile_build.bzl", "dockerfile_image")

0 commit comments

Comments
 (0)