Skip to content

Commit

Permalink
Rules for //:kustomize //:gcloud //:kubectl use :execpwd.
Browse files Browse the repository at this point in the history
bazelbuild/bazel#3325

Tested:

    mkdir examples/tmp
    cd examples/tmp
    bazel run @com_benchsci_rules_kustomize//:kustomize -- create

Confirm a `kustomize.yaml` file is created in the working directory.
Previously, the tool would mutate the underlying runfiles directory.
  • Loading branch information
bshi committed Apr 23, 2021
1 parent 1ff659d commit 99f02f1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
22 changes: 19 additions & 3 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,38 @@ filegroup(
srcs = ["exec.sh"],
)

filegroup(
name = "execpwd",
srcs = ["execpwd.sh"],
)

sh_binary(
name = "kustomize",
srcs = ["@kustomize//:file"],
srcs = [":execpwd"],
args = ["$(location @kustomize//:file)"],
data = ["@kustomize//:file"],
)

sh_binary(
name = "kubectl",
name = "kubectl_bin",
srcs = select({
"@bazel_tools//src/conditions:linux_x86_64": ["@kubectl_linux//file"],
"@bazel_tools//src/conditions:darwin": ["@kubectl_darwin//file"],
}),
)

sh_binary(
name = "kubectl",
srcs = [":execpwd"],
args = ["$(location :kubectl_bin)"],
data = [":kubectl_bin"],
)

sh_binary(
name = "gcloud",
srcs = ["@gcloud"],
srcs = [":execpwd"],
args = ["$(location @gcloud)"],
data = ["@gcloud"],
)

# Exported for documentation (see //tools:docs).
Expand Down
2 changes: 1 addition & 1 deletion exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

exec $@
exec "$@"
26 changes: 26 additions & 0 deletions execpwd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
# Copyright 2021 Benchsci Analytics Inc.
#
# 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.

# See https://github.com/bazelbuild/bazel/issues/3325
if [ -z "${BUILD_WORKING_DIRECTORY-}" ]; then
echo "error BUILD_WORKING_DIRECTORY not set"
exit 1
fi

cmd="$( pwd )/${1}"
cd "${BUILD_WORKING_DIRECTORY}"
shift

exec "${cmd}" "$@"

0 comments on commit 99f02f1

Please sign in to comment.