Fix minio-client creating config directory in user's home

This commit is contained in:
Brian Picciano 2023-09-04 21:38:28 +02:00
parent 98e5f4c98c
commit 3c3bd8649a
5 changed files with 60 additions and 3 deletions

View File

@ -169,6 +169,7 @@ in rec {
appImage appImage
pkgs.busybox pkgs.busybox
pkgs.yq-go pkgs.yq-go
pkgs.jq
]} ]}
export SHELL=${pkgs.bash}/bin/bash export SHELL=${pkgs.bash}/bin/bash
exec ${pkgs.bash}/bin/bash ${./tests}/entrypoint.sh "$@" exec ${pkgs.bash}/bin/bash ${./tests}/entrypoint.sh "$@"

View File

@ -7,6 +7,28 @@ import (
"syscall" "syscall"
) )
// minio-client keeps a configuration directory which contains various pieces of
// information which may or may not be useful. Unfortunately when it initializes
// this directory it likes to print some annoying logs, so we pre-initialize in
// order to prevent it from doing so.
func initMCConfigDir() (string, error) {
var (
path = filepath.Join(envDataDirPath, "mc")
sharePath = filepath.Join(path, "share")
configJSONPath = filepath.Join(path, "config.json")
)
if err := os.MkdirAll(sharePath, 0700); err != nil {
return "", fmt.Errorf("creating %q: %w", sharePath, err)
}
if err := os.WriteFile(configJSONPath, []byte(`{}`), 0600); err != nil {
return "", fmt.Errorf("writing %q: %w", configJSONPath, err)
}
return path, nil
}
var subCmdGarageMC = subCmd{ var subCmdGarageMC = subCmd{
name: "mc", name: "mc",
descr: "Runs the mc (minio-client) binary. The isle garage can be accessed under the `garage` alias", descr: "Runs the mc (minio-client) binary. The isle garage can be accessed under the `garage` alias",
@ -50,7 +72,15 @@ var subCmdGarageMC = subCmd{
args = args[i:] args = args[i:]
} }
args = append([]string{binPath("mc")}, args...) configDir, err := initMCConfigDir()
if err != nil {
return fmt.Errorf("initializing minio-client config directory: %w", err)
}
args = append([]string{
binPath("mc"),
"--config-dir", configDir,
}, args...)
var ( var (
mcHostVar = fmt.Sprintf( mcHostVar = fmt.Sprintf(

View File

@ -0,0 +1,13 @@
# shellcheck source=../../utils/with-single-node-cluster.sh
source "$UTILS"/with-single-node-cluster.sh
status="$(isle garage cli status | tail -n+3)"
[ "$(echo "$status" | wc -l)" = "3" ]
echo "$status" | grep -q '10.6.9.1:3900'
echo "$status" | grep -q '10.6.9.1:3910'
echo "$status" | grep -q '10.6.9.1:3920'
buckets="$(isle garage cli bucket list | tail -n+2)"
[ "$(echo "$buckets" | wc -l)" = 1 ]
echo "$buckets" | grep -q 'global-shared'

View File

@ -0,0 +1,8 @@
# shellcheck source=../../utils/with-single-node-cluster.sh
source "$UTILS"/with-single-node-cluster.sh
files="$(isle garage mc -- tree --json garage)"
[ "$(echo "$files" | jq -s '.|length')" -ge "1" ]
file="$(echo "$files" | jq -sr '.[0].key')"
[ "$(isle garage mc -- cat "garage/$file" | wc -c)" -gt "0" ]

View File

@ -50,7 +50,7 @@ test_files=$(
find ./cases -type f -name '*.sh' \ find ./cases -type f -name '*.sh' \
| sed "s|^\./cases/||" \ | sed "s|^\./cases/||" \
| grep -v entrypoint.sh \ | grep -v entrypoint.sh \
| sort -n | sort
) )
for r in "${REGEXS[@]}"; do for r in "${REGEXS[@]}"; do
@ -61,7 +61,12 @@ echo -e "number of tests: $(echo "$test_files" | wc -l)\n"
for file in $test_files; do for file in $test_files; do
echo "Running test case: $file" echo "Running test case: $file"
[ -z "$VERBOSE" ] && output="$TMPDIR/$file.log" || output=/dev/stdout if [ -z "$VERBOSE" ]; then
output="$TMPDIR/$file.log"
mkdir -p "$(dirname "$output")"
else
output=/dev/stdout
fi
( (
export TEST_CASE_FILE="$file" export TEST_CASE_FILE="$file"