-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[common-utils] - append shell history functionality - #1026 #1157
base: main
Are you sure you want to change the base?
[common-utils] - append shell history functionality - #1026 #1157
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions:
- Wouldn't adding more functionality to common-utils here go against this discussion? Consider splitting up the
common
feature #67 - Why not use lifecycle-scripts? See Use Lifecycle Scripts stuartleeks/dev-container-features#16
…_common-utils_integration
}, | ||
"mounts": [ | ||
{ | ||
"source": "${devcontainerId}-shellhistory", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will add a volume for each container which will make volumes harder to manage for the user. Maybe you could use a single volume devcontainers
at /devcontainers
and in that create a folder /devcontainers/shellHistory/${devcontainerId}
for each dev container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have added logic such that uuidgen utility is used for generating random devcontainer id for a container, intent is to embed it inside the folder structure like this :
/devcontainers/$(uuidgen)/shellHistory for a symlink to the ~/.bash_history being kept here. Logic is working for retention of shell history, keeping it as draft so you can check for bash shell
src/common-utils/main.sh
Outdated
if [[ -z "\$HISTFILE_OLD" ]]; then | ||
export HISTFILE_OLD=\$HISTFILE | ||
fi | ||
export HISTFILE=/dc/shellhistory/.bash_history |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be value in keeping the default path ~/.bash_history
and instead make that a symbolic link to the actual file in the volume? (I haven't tried using a symbolic link, best to check first if bash/zsh work correctly with that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done like this. thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add this functionality to common-utils instead of relying on another Feature?
Wouldn't common-utils be too heavy a dependency for users who only want to use history?
And I am also convinced that the lifecycle script approach is far superior when implementing such a functionality.
Please check stuartleeks/dev-container-features#16
src/common-utils/main.sh
Outdated
sudo apt-get install -y uuid-runtime | ||
fi | ||
# Create the shell history directory in the mounted volume | ||
DEVCONTAINER_ID=$(uuidgen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One downside of generating a UUID here is that it will change with each rebuild of the container image. The ${devcontainerId}
value could be passed into the container with "containerEnv"
(it could make sense for the CLI to do this automatically, but it currently doesn't) where this script could use it when run as part of the "postCreateCommand"
. 🤔 (It would also make sense for the CLI to pass DEVCONTAINER_ID
into the feature install scripts.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made changes as suggested.
src/common-utils/main.sh
Outdated
# Ensure the volume's history file exists and set permissions | ||
if [[ ! -f "${VOLUME_HISTORY_FILE}" ]]; then | ||
# Create an empty history file if it doesn’t already exist | ||
sudo touch "${VOLUME_HISTORY_FILE}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this won't work when the volume already exists because the volume is not mounted at this point and the image contents at /devcontainer
will be copied to the volume only once - when the volume is created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the check
src/common-utils/main.sh
Outdated
|
||
# Create or update the user’s .bash_history to append to the volume’s history | ||
if [[ ! -f "${USER_HISTORY_FILE}" ]]; then | ||
sudo touch "${USER_HISTORY_FILE}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be overwritten by the symbolic link below. I think this can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
I agree, I'm also not sure if adding a
This seems to require password-less |
Isn't that irrelevant whether or not lifecycle scripts are used? We don't know the permissions of a mounted volume until it is mounted, do we? |
Ref: #1026
Feature
Description
common-utils
feature as a configurable optionchangelog
devcontainer-feature.json
file, added boolean optionallowShellHistory
and mounts as a configurable optionmain.sh
incommon-utils
features srcscenarios
to test this new featureallow_shell_history.sh
fileChecklist