Skip to content
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

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

gauravsaini04
Copy link
Contributor

Ref: #1026

Feature

  • Common-Utils

Description

changelog

  • Have added changes to devcontainer-feature.json file, added boolean option allowShellHistory and mounts as a configurable option
  • Have added changes to main.sh in common-utils features src
  • Have added to scenarios to test this new feature
  • Have added test cases in allow_shell_history.sh file

Checklist

  • checked that applied changes work as expected

Copy link
Contributor

@eitsupi eitsupi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions:

@gauravsaini04 gauravsaini04 marked this pull request as ready for review October 28, 2024 22:26
@gauravsaini04 gauravsaini04 requested a review from a team as a code owner October 28, 2024 22:26
},
"mounts": [
{
"source": "${devcontainerId}-shellhistory",

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.

Copy link
Contributor Author

@gauravsaini04 gauravsaini04 Nov 3, 2024

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

if [[ -z "\$HISTFILE_OLD" ]]; then
export HISTFILE_OLD=\$HISTFILE
fi
export HISTFILE=/dc/shellhistory/.bash_history

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.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done like this. thanks.

Copy link
Contributor

@eitsupi eitsupi left a 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

@gauravsaini04 gauravsaini04 marked this pull request as draft November 3, 2024 00:31
@gauravsaini04
Copy link
Contributor Author

And I am also convinced that the lifecycle script approach is far superior when implementing such a functionality.

Thanks for valuable inputs @eitsupi, waiting for the logic to be approved by @chrmarti, will be converting to a lifecycle script after this

sudo apt-get install -y uuid-runtime
fi
# Create the shell history directory in the mounted volume
DEVCONTAINER_ID=$(uuidgen)
Copy link

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.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made changes as suggested.

# 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}"
Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the check


# 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}"
Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@chrmarti
Copy link

chrmarti commented Nov 4, 2024

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?

I agree, I'm also not sure if adding a devcontainers volume for all users of our base images will be ideal. Though having persistence for shell history built-in would be a great feature.

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

This seems to require password-less sudo access. The feature would not work without that.

@eitsupi
Copy link
Contributor

eitsupi commented Nov 6, 2024

This seems to require password-less sudo access. The feature would not work without that.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants