mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-01 18:30:15 +00:00
Merge pull request #1920 from bzub/1919-build_go_plugins_script
Add script to detect/build Go plugins.
This commit is contained in:
14
Makefile
14
Makefile
@@ -229,6 +229,20 @@ $(MYGOBIN)/helm:
|
|||||||
rm -rf $$d \
|
rm -rf $$d \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
.PHONY: build-external-go-plugins
|
||||||
|
build-external-go-plugins:
|
||||||
|
( \
|
||||||
|
cd plugin; \
|
||||||
|
../hack/buildExternalGoPlugins.sh; \
|
||||||
|
)
|
||||||
|
|
||||||
|
.PHONY: clean-external-go-plugins
|
||||||
|
clean-external-go-plugins:
|
||||||
|
( \
|
||||||
|
cd plugin; \
|
||||||
|
../hack/buildExternalGoPlugins.sh clean; \
|
||||||
|
)
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
go clean --cache
|
go clean --cache
|
||||||
|
|||||||
40
hack/buildExternalGoPlugins.sh
Executable file
40
hack/buildExternalGoPlugins.sh
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# We assume one go file per plugin, and the desired name of the plugin .so
|
||||||
|
# matches the basename of said go file.
|
||||||
|
# Example: ReplacementTransformer.go -> ReplacementTransformer.so
|
||||||
|
#
|
||||||
|
# We also assume the script is run from a kustomize plugin directory.
|
||||||
|
# Usually one of:
|
||||||
|
# - ${HOME}/.config/kustomize/plugin
|
||||||
|
# - ${kustomize_git_repo}/plugin
|
||||||
|
plugins_dir="${PWD}"
|
||||||
|
command="${1}"
|
||||||
|
|
||||||
|
function buildPlugin {
|
||||||
|
pushd "${1}" >& /dev/null
|
||||||
|
plugin_src="$(find "${1}" -name '*.go'|grep -Ev '.*_test.go'|head -n1)"
|
||||||
|
plugin_bin="$(echo "${plugin_src}"|sed 's/\(.*\).go/\1.so/')"
|
||||||
|
if [ "${command}" = "clean" ]; then
|
||||||
|
echo "Deleting ${plugin_bin}"
|
||||||
|
rm -f "${plugin_bin}"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
echo "Building ${plugin_bin}"
|
||||||
|
go build -buildmode plugin -o "${plugin_bin}" "${plugin_src}"
|
||||||
|
popd >& /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
for goMod in $(find "${plugins_dir}" -name 'go.mod'); do
|
||||||
|
d=$(dirname "${goMod}")
|
||||||
|
# Skip "builtin" plugins in kustomize repo.
|
||||||
|
if [ ! -z "$(echo "${goMod}" | grep -F "/plugin/builtin/")" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
# Skip plugins with only test Go files.
|
||||||
|
if [ -z "$(find "${d}" -maxdepth 1 -name '*.go' | grep -Ev ".*_test.go")" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
buildPlugin "${d}"
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user