Skip to content

Commit f0e9c78

Browse files
committed
Enhance user context handling in Spin script
- Introduced SPIN_RUN_AS_USER environment variable to specify the user running the Spin commands, improving flexibility and clarity. - Updated multiple Docker run commands in functions.sh to utilize SPIN_RUN_AS_USER instead of directly calling `whoami`, ensuring consistent user context across operations.
1 parent 0e93dd4 commit f0e9c78

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

bin/spin

+2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ export COMPOSE_CMD=${COMPOSE_CMD:-"docker compose"}
1515
# Export the current user and group ID
1616
SPIN_USER_ID=${SPIN_USER_ID:-$(id -u)}
1717
SPIN_GROUP_ID=${SPIN_GROUP_ID:-$(id -g)}
18+
SPIN_RUN_AS_USER=${SPIN_RUN_AS_USER:-$(whoami)}
1819
export SPIN_USER_ID
1920
export SPIN_GROUP_ID
21+
export SPIN_RUN_AS_USER
2022

2123
# Default Images
2224
SPIN_PHP_IMAGE=${SPIN_PHP_IMAGE:-"serversideup/php:cli"}

lib/functions.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ get_ansible_variable(){
480480
raw_output=$(docker run --rm -i \
481481
-e "PUID=${SPIN_USER_ID}" \
482482
-e "PGID=${SPIN_GROUP_ID}" \
483-
-e "RUN_AS_USER=$(whoami)" \
483+
-e "RUN_AS_USER=${SPIN_RUN_AS_USER}" \
484484
-e "ANSIBLE_STDOUT_CALLBACK=minimal" \
485485
-e "ANSIBLE_DISPLAY_SKIPPED_HOSTS=false" \
486486
-e "ANSIBLE_DISPLAY_OK_HOSTS=false" \
@@ -883,7 +883,7 @@ prepare_ansible_run() {
883883
docker run --rm -it \
884884
-e "PUID=${SPIN_USER_ID}" \
885885
-e "PGID=${SPIN_GROUP_ID}" \
886-
-e "RUN_AS_USER=$(whoami)" \
886+
-e "RUN_AS_USER=${SPIN_RUN_AS_USER}" \
887887
-v "$SPIN_ANSIBLE_COLLECTIONS_PATH:/etc/ansible/collections" \
888888
"$SPIN_ANSIBLE_IMAGE" \
889889
ansible-galaxy collection install "${SPIN_ANSIBLE_COLLECTION_NAME}" --force
@@ -1222,7 +1222,7 @@ run_ansible() {
12221222
docker run --rm -it \
12231223
-e "PUID=${SPIN_USER_ID}" \
12241224
-e "PGID=${SPIN_GROUP_ID}" \
1225-
-e "RUN_AS_USER=$(whoami)" \
1225+
-e "RUN_AS_USER=${SPIN_RUN_AS_USER}" \
12261226
"${additional_docker_args[@]}" \
12271227
"$SPIN_ANSIBLE_IMAGE" \
12281228
"${ansible_args[@]}"
@@ -1301,7 +1301,7 @@ run_gh() {
13011301
docker run --rm $interactive_flag \
13021302
-e "PUID=${SPIN_USER_ID}" \
13031303
-e "PGID=${SPIN_GROUP_ID}" \
1304-
-e "RUN_AS_USER=$(whoami)" \
1304+
-e "RUN_AS_USER=${SPIN_RUN_AS_USER}" \
13051305
-v "$(pwd):/app" \
13061306
-v "$HOME/.config/gh:/config/gh:rw" \
13071307
"${additional_docker_args[@]}" \
@@ -1339,7 +1339,7 @@ set_ansible_vault_args() {
13391339
docker run --rm -i \
13401340
-e "PUID=${SPIN_USER_ID}" \
13411341
-e "PGID=${SPIN_GROUP_ID}" \
1342-
-e "RUN_AS_USER=$(whoami)" \
1342+
-e "RUN_AS_USER=${SPIN_RUN_AS_USER}" \
13431343
-v "$(pwd):/ansible" \
13441344
"$SPIN_ANSIBLE_IMAGE" \
13451345
ansible-vault view --vault-password-file="/ansible/.vault-password" "$variable_file" > /dev/null 2>&1

0 commit comments

Comments
 (0)