Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
1 change: 1 addition & 0 deletions docker/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ TEST_TARGETS = [
"workdir_with_tar_base",
"link_with_files_base",
"build_with_tag",
"with_passwd",
]

TEST_DATA = [
Expand Down
18 changes: 18 additions & 0 deletions docker/build_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,24 @@ function test_build_with_tag() {
"[\"gcr.io/build/with:tag\"]"
}

function test_build_with_passwd() {
# We should have a tag in our manifest containing the name
# specified via the tag kwarg.

local layer="621fe329a78d65d90d34d6dc277ccac2249bba4c8228222271418bf6b07c4dec"
check_layers "with_passwd" "${layer}"

check_eq "$(get_layer_listing "with_passwd" "${layer}")" \
'./
./etc/
./etc/passwd'

local test_data="${TEST_DATA_DIR}/with_passwd.tar"
echo $test_data
passwd_contents=$(tar xOf "${test_data}" "${layer}/layer.tar" | tar xO "./etc/passwd")
check_eq ${passwd_contents} "foobar:x:1234:2345:myusernameinfo:/myhomedir:/myshell"
}

tests=$(grep "^function test_" "${BASH_SOURCE[0]}" \
| cut -d' ' -f 2 | cut -d'(' -f 1)

Expand Down
70 changes: 70 additions & 0 deletions docker/contrib/passwd.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

def _impl(ctx):
"""Core implementation of docker_push."""

f = "%s:x:%s:%s:%s:%s:%s\n" % (
ctx.attr.username,
ctx.attr.uid,
ctx.attr.gid,
ctx.attr.info,
ctx.attr.home,
ctx.attr.shell
)
ctx.file_action(
output = ctx.outputs.out,
content = f,
executable=False
)
build_tar = ctx.executable.build_tar
args = [
"--output=" + ctx.outputs.tar.path,
"--file=%s=/etc/passwd" % ctx.outputs.out.path
]
arg_file = ctx.new_file(ctx.attr.name + ".args")
ctx.file_action(arg_file, "\n".join(args))

ctx.action(
executable = build_tar,
arguments = ["--flagfile=" + arg_file.path],
inputs = [ctx.outputs.out, arg_file],
outputs = [ctx.outputs.tar],
use_default_shell_env = True
)

passwd_file = rule(
attrs = {
"username": attr.string(mandatory = True),
"uid": attr.int(default = 1000),
"gid": attr.int(default = 1000),
"info": attr.string(default = "user"),
"home": attr.string(default = "/home"),
"shell": attr.string(default = "/bin/bash"),
"build_tar": attr.label(
default = Label("@bazel_tools//tools/build_defs/pkg:build_tar"),
cfg = "host",
executable = True,
allow_files = True,
),
},
executable = False,
outputs = {
"out": "%{name}.passwd",
"tar": "%{name}.passwd.tar",
},
implementation = _impl,
)
17 changes: 17 additions & 0 deletions docker/testdata/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,20 @@ docker_build_with_tag(
files = ["foo"],
tag = "gcr.io/build/with:tag",
)

load("//docker/contrib:passwd.bzl", "passwd_file")

passwd_file(
name = "testpasswd",
gid = 2345,
home = "/myhomedir",
info = "myusernameinfo",
shell = "/myshell",
uid = 1234,
username = "foobar",
)

docker_build(
name = "with_passwd",
tars = [":testpasswd.passwd.tar"],
)