Build docker container with ready to use user env
Prepare user environment at build time and update user and group id at runtime if necessary. Update submodule sync step to avoid a dependency on cargo Run `make update all` instead of just `make all`. The target `update` didn't update the container environment since it was executed on the host.
This commit is contained in:
parent
72674a6e6a
commit
95915513ee
3 changed files with 50 additions and 38 deletions
|
@ -1,17 +1,18 @@
|
|||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Add local user
|
||||
# Either use the LOCAL_USER_ID if passed in at runtime or
|
||||
# fallback
|
||||
# Use -e LOCAL_UID="$(id -u)" -e LOCAL_GID="$(id -g)"
|
||||
# on the docker run command line if the container build user is different
|
||||
# from the run user
|
||||
|
||||
USER_ID=${LOCAL_USER_ID:-9001}
|
||||
CONT_UID=`id -u user`
|
||||
CONT_GID=`id -g user`
|
||||
RUN_UID=${LOCAL_UID:-$CONT_UID}
|
||||
RUN_GID=${LOCAL_GID:-$CONT_GID}
|
||||
|
||||
echo "Starting with UID : $USER_ID "
|
||||
echo "CARGO_HOME is $CARGO_HOME"
|
||||
echo "RUSTUP_HOME is $RUSTUP_HOME"
|
||||
useradd --shell /bin/bash -u $USER_ID -o -c "" -m user
|
||||
export HOME=/home/user
|
||||
chown user:user -R $CARGO_HOME
|
||||
chown user:user -R $RUSTUP_HOME
|
||||
if [ $RUN_UID != $CONT_UID ] || [ $RUN_GID != $CONT_GID ]; then
|
||||
echo -e "\033[01;38;5;155mChanging user id:group to ${RUN_UID}:${RUN_GID}. Please wait...\033[0m"
|
||||
groupmod -g $RUN_GID user
|
||||
usermod -u $RUN_UID -g $RUN_GID user
|
||||
fi
|
||||
|
||||
exec gosu user:user "$@"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue