Skip to content

Commit fa5f719

Browse files
bajacondorerainnlopezgi
committed
Remote docker host (#1228)
* Bump httplib2 library to 0.11.3 for DigiCert Per httplib2/httplib2#91 Which adds the DigiCert Global Root G2 serial to cacert.txt Without this push_image() fails to registries trusted by the DigiCert CA. * added email for cla * added email for cla * added travis.ci * local puller * no label * use docker_tool_path in util * docker command * docker command * docker command * docker command * docker command * docker command * docker command * docker commands use quotes * docker commands use quotes * move flags to toolchain config * misplaced arguments * ran buildifier * more buildifier bs * added tests * added tests * proper linting * test confusion * tests for incremental_load and run_and_commit. * tests for incremental_load and run_and_commit. * making other tests run again after my changes * add docker flag docs * use symlink to test incremental_load template * attempt at tests with image.bzl coverage * add .executable to test scripts * pushed wrong workspace * fix compare test * changes per PR * reverted e2e test with executable * template was in run.bzl too! * fix dict order * do docker cp rather than vm * buildifier lint * fix non merging files * duplicate client_config * fix lint and duplicate client_config * checkout unmerged files * fix tests with double outs * fix e2e style tests for new executable. * correct executable names for test * fix executable in loop test Co-authored-by: Yu YI <yiyu@google.com> Co-authored-by: Nicolas Lopez <nlopezgi@gmail.com>
1 parent 5a6965f commit fa5f719

File tree

34 files changed

+339
-63
lines changed

34 files changed

+339
-63
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
testing/examples
44
testing/java_image
55
testing/download_pkgs_at_root
6+
testing/custom_toolchain_flags

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# Names should be added to this file as:
1010
# Name <email address>
1111

12+
David Schile <david.v.schile@nordstrom.com>
1213
Matthew Moore <mattmoor@google.com>
1314
Nathan Herring <nherring@google.com>
1415
Nicolas Lopez <ngiraldo@google.com>

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ docker_toolchain_configure(
150150
# OPTIONAL: Path to the xz binary.
151151
# Should be set explcitly for remote execution.
152152
xz_path="<enter absolute path to the xz binary (in the remote exec env) here>",
153+
# OPTIONAL: List of additional flags to pass to the docker command.
154+
docker_flags = [
155+
"--tls",
156+
"--log-level=info",
157+
],
158+
153159
)
154160
# End of OPTIONAL segment.
155161

@@ -2294,6 +2300,7 @@ Here's a (non-exhaustive) list of companies that use `rules_docker` in productio
22942300
* [Evertz](https://evertz.com/)
22952301
* [Jetstack](https://www.jetstack.io/)
22962302
* [Kubernetes Container Image Promoter](https://github.com/kubernetes-sigs/k8s-container-image-promoter)
2303+
* [Nordstrom](https://nordstrom.com)
22972304
* [Prow](https://github.com/kubernetes/test-infra/tree/master/prow)
22982305
* [Tink](https://www.tink.com)
22992306
* [Wix](https://www.wix.com)

WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,9 @@ rbe_exec_properties(
419419
name = "exec_properties",
420420
)
421421

422+
load("@bazel_skylib//lib:dicts.bzl", "dicts")
422423
load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig")
423424
load("@exec_properties//:constants.bzl", "DOCKER_SIBLINGS_CONTAINERS", "NETWORK_ON")
424-
load("@bazel_skylib//lib:dicts.bzl", "dicts")
425425

426426
rbe_autoconfig(
427427
name = "buildkite_config",

container/image.bzl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,12 @@ def _impl(
330330
cmd = cmd or ctx.attr.cmd
331331
operating_system = operating_system or ctx.attr.operating_system
332332
creation_time = creation_time or ctx.attr.creation_time
333-
output_executable = output_executable or ctx.outputs.executable
333+
build_executable = output_executable or ctx.outputs.build_script
334334
output_tarball = output_tarball or ctx.outputs.out
335335
output_digest = output_digest or ctx.outputs.digest
336336
output_config = output_config or ctx.outputs.config
337337
output_layer = output_layer or ctx.outputs.layer
338+
build_script = ctx.outputs.build_script
338339
null_cmd = null_cmd or ctx.attr.null_cmd
339340
null_entrypoint = null_entrypoint or ctx.attr.null_entrypoint
340341

@@ -465,10 +466,11 @@ def _impl(
465466
_incr_load(
466467
ctx,
467468
images,
468-
output_executable,
469+
build_executable,
469470
run = not ctx.attr.legacy_run_behavior,
470471
run_flags = docker_run_flags,
471472
)
473+
472474
_assemble_image(
473475
ctx,
474476
images,
@@ -496,7 +498,7 @@ def _impl(
496498
docker_run_flags = docker_run_flags,
497499
),
498500
DefaultInfo(
499-
executable = output_executable,
501+
executable = build_executable,
500502
files = depset([output_layer]),
501503
runfiles = runfiles,
502504
),
@@ -559,6 +561,8 @@ _outputs["digest"] = "%{name}.digest"
559561

560562
_outputs["config"] = "%{name}.json"
561563

564+
_outputs["build_script"] = "%{name}.executable"
565+
562566
image = struct(
563567
attrs = _attrs,
564568
outputs = _outputs,

container/incremental_load.sh.tpl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function guess_runfiles() {
3232
RUNFILES="${PYTHON_RUNFILES:-$(guess_runfiles)}"
3333

3434
DOCKER="%{docker_tool_path}"
35+
DOCKER_FLAGS="%{docker_flags}"
3536

3637
if [[ -z "${DOCKER}" ]]; then
3738
echo >&2 "error: docker not found; do you need to manually configure the docker toolchain?"
@@ -43,7 +44,7 @@ TEMP_FILES="$(mktemp -t 2>/dev/null || mktemp -t 'rules_docker_files')"
4344
TEMP_IMAGES="$(mktemp -t 2>/dev/null || mktemp -t 'rules_docker_images')"
4445
function cleanup() {
4546
cat "${TEMP_FILES}" | xargs rm -rf> /dev/null 2>&1 || true
46-
cat "${TEMP_IMAGES}" | xargs "${DOCKER}" rmi > /dev/null 2>&1 || true
47+
cat "${TEMP_IMAGES}" | xargs "${DOCKER}" ${DOCKER_FLAGS} rmi > /dev/null 2>&1 || true
4748

4849
rm -rf "${TEMP_FILES}"
4950
rm -rf "${TEMP_IMAGES}"
@@ -56,7 +57,7 @@ function load_legacy() {
5657

5758
# docker load has elision of preloaded layers built in.
5859
echo "Loading legacy tarball base $1..."
59-
"${DOCKER}" load -i "${tarball}"
60+
"${DOCKER}" ${DOCKER_FLAGS} load -i "${tarball}"
6061
}
6162

6263
function join_by() {
@@ -97,7 +98,7 @@ EOF
9798
EOF
9899

99100
set -o pipefail
100-
tar c config.json manifest.json | "${DOCKER}" load 2>/dev/null | cut -d':' -f 2- >> "${TEMP_IMAGES}"
101+
tar c config.json manifest.json | "${DOCKER}" ${DOCKER_FLAGS} load 2>/dev/null | cut -d':' -f 2- >> "${TEMP_IMAGES}"
101102
}
102103

103104
function find_diffbase() {
@@ -204,15 +205,15 @@ EOF
204205
# We minimize reads / writes by symlinking the layers above
205206
# and then streaming exactly the layers we've established are
206207
# needed into the Docker daemon.
207-
tar cPh "${MISSING[@]}" | tee image.tar | "${DOCKER}" load
208+
tar cPh "${MISSING[@]}" | tee image.tar | "${DOCKER}" ${DOCKER_FLAGS} load
208209
}
209210

210211
function tag_layer() {
211212
local name="$(cat "${RUNFILES}/$2")"
212213

213214
local TAG="$1"
214215
echo "Tagging ${name} as ${TAG}"
215-
"${DOCKER}" tag sha256:${name} ${TAG}
216+
"${DOCKER}" ${DOCKER_FLAGS} tag sha256:${name} ${TAG}
216217
}
217218

218219
function read_variables() {

container/layer_tools.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,13 @@ def incremental_load(
261261
if run:
262262
# Args are embedded into the image, so omitted here.
263263
run_statements += [
264-
"\"${DOCKER}\" run %s %s" % (run_flags, tag_reference),
264+
"\"${DOCKER}\" ${DOCKER_FLAGS} run %s %s" % (run_flags, tag_reference),
265265
]
266266

267267
ctx.actions.expand_template(
268268
template = ctx.file.incremental_load_template,
269269
substitutions = {
270+
"%{docker_flags}": " ".join(toolchain_info.docker_flags),
270271
"%{docker_tool_path}": toolchain_info.tool_path,
271272
"%{load_statements}": "\n".join(load_statements),
272273
"%{run_statements}": "\n".join(run_statements),

contrib/automatic_container_release/configs_test.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def _impl(ctx):
6969
template = ctx.file._tpl,
7070
substitutions = {
7171
"%{cmd_args}": " ".join(cmd_args),
72+
"%{docker_flags}": " ".join(toolchain_info.docker_flags),
7273
"%{docker_path}": toolchain_info.tool_path,
7374
"%{image_name}": ctx.attr._checker + ":" + ctx.attr.checker_tag,
7475
"%{spec_container_paths}": " ".join(spec_container_paths),

contrib/automatic_container_release/run_checker.sh.tpl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ RUNFILES="${PYTHON_RUNFILES:-$(guess_runfiles)}"
3939

4040
# Resolve the docker tool path.
4141
DOCKER="%{docker_path}"
42+
DOCKER_FLAGS="%{docker_flags}"
4243

4344
if [[ -z "$DOCKER" ]]; then
4445
echo >&2 "error: docker not found; do you need to manually configure the docker toolchain?"
4546
exit 1
4647
fi
4748

4849
# Create a new docker container that will run the checker.
49-
container_id=$($DOCKER create %{image_name} %{cmd_args})
50+
container_id=$($DOCKER $DOCKER_FLAGS create %{image_name} %{cmd_args})
5051

5152
specs=(%{specs})
5253
spec_container_paths=(%{spec_container_paths})
@@ -59,20 +60,20 @@ if [ ${#specs[@]} -ne ${#spec_container_paths[@]} ]; then
5960
exit 1
6061
fi
6162
for ((i=0;i<${#specs[@]};i++)); do
62-
$DOCKER cp -L ${specs[$i]} $container_id:${spec_container_paths[$i]}
63+
$DOCKER $DOCKER_FLAGS cp -L ${specs[$i]} $container_id:${spec_container_paths[$i]}
6364
done
6465

6566
# Start the container that will run the checker logic.
66-
$DOCKER start $container_id
67+
$DOCKER $DOCKER_FLAGS start $container_id
6768

6869
# Wait for the checker to finish running.
69-
retcode=$($DOCKER wait $container_id)
70+
retcode=$($DOCKER $DOCKER_FLAGS wait $container_id)
7071

7172
# Print all logs generated by the container.
72-
$DOCKER logs $container_id
73+
$DOCKER $DOCKER_FLAGS logs $container_id
7374

7475
# Delete the container.
75-
$DOCKER rm $container_id
76+
$DOCKER $DOCKER_FLAGS rm $container_id
7677

7778
exit $retcode
7879

contrib/compare_ids_test.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ compare_ids_test(
4040

4141
# Implementation of compare_ids_test
4242
def _compare_ids_test_impl(ctx):
43-
tar_files = ctx.files.images
43+
tar_files = []
44+
for file in ctx.files.images:
45+
if file.short_path.endswith("tar"):
46+
tar_files += [file]
4447

4548
if (len(tar_files) == 0):
4649
fail("No images provided for test.")

0 commit comments

Comments
 (0)