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

[Suggestion] Pass variables created in the manifest files to be used in the container #1643

Closed
amonull opened this issue Dec 28, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@amonull
Copy link

amonull commented Dec 28, 2024

Is your feature request related to a problem? Please describe.
Cannot pass variables to use when declared in the manifest files, so if i have a hook which does pre_init_hook="export SOME_VAL=" the SOME_VAL will never be seen by the container as a variable but instead it will get processed by the host.

Another issue caused by letting host handle these vars is the usage of existing env vars like $HOME which redirect to host HOME but i assumed to point to the containers home.

Describe the solution you'd like
allow passing hooks to to distrobox-create as encoded strings which are later decoded to only use variables on the container and not on the host. Could have the flag --encoded-hooks which would indicate to create that it should decode them first before attempting to evaluate them.

Describe alternatives you've considered
A workaround i found was to wrap the distrobox assemble --file filename.ini to another sh script that sets the variables from there and then when they eventually get passed down those vars exist and are not unbound. This workaround is fine but can cause problems when i need to create a variable specific to the containers current state which my host machine will not have access to at that moment. To create and have access l vars during runtime of container files could be used to store values but this still lews desirable than having access to vars during container runtine.

Example

#!/bin/sh
export INTELLJ_TOOLBOX_VER="2.5.2.35332" # a var that exists and is called to by hooks in filename.ini

distrobox assemble create --file filename.ini

unset INTELLJ_TOOLBOX_VER

Additional context
incomplete manifest file i tried to use

[dev]
image=ubuntu:latest
pull=false
start_now=false
entry=true

home="/home/.containers/dev"

root=false
unshare_ipc=true
unsahare_devsys=true
unshare_process=true
unshare_netns=false
unshare_groups=false
nvidia=false
init=false

# Mount/link required folders and set env vars
# NOTE: some things here like version are hardcoded and need to be changed frequently (find way to avoid this i.e. have a look at https://phantomjs.org/)
pre_init_hooks="mkdir $HOME/Documents && ln -s /home/amon/Documents/Programming $HOME/Documents/"
pre_init_hooks="mkdir $HOME/Downloads/setup && export SETUP_LOC=$HOME/Downloads/setup"
pre_init_hooks='export INTELLJ_TOOLBOX_VERSION="2.5.2.35332"'

# Download required files
# TODO: just generate expect scripts and run those with the appropriate curl or wget command instead of downloading files first and processing later
pre_init_hooks="wget -q -O- 'https://download.jetbrains.com/toolbox/jetbrains-toolbox-${INTELLJ_TOOLBOX_VERSION}.tar.gz' | tar -xz -C $SETUP_LOC"
pre_init_hooks="curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org -o $SETUP_LOC/ghcup"
pre_init_hooks="curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o $SETUP_LOC/rustup"
pre_init_hooks="curl -L https://install.perlbrew.pl -o $SETUP_LOC/perlbrew"
pre_init_hooks="curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh -o $SETUP_LOC/nvm"
pre_init_hooks="curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer -o $SETUP_LOC/gvm"
pre_init_hooks="curl https://pyenv.run -o $SETUP_LOC/pyenv"
pre_init_hooks="curl -s 'https://get.sdkman.io' -o $SETUP_LOC/sdkman"
pre_init_hooks="curl -fsSL https://raw.githubusercontent.com/dhavalkapil/luaver/master/install.sh -o $SETUP_LOC/luaver"

# first line pkgs required for jetbrains toolbox appimage to work
# second line some shared libs to get common things to work
# expect required for script automation for ghcup and other related scripts
additional_packages="libfuse2 libxi6 libxrender1 libxtst6 mesa-utils libfontconfig libgtk-3-bin tar dbus-user-session"
additional_packages="libnss3 libasound2t64"
# NOTE: fish shell might not be required as it looks like distrobox auto picks it up
additional_packages="git"
additional_packages="clang gcc gdb nasm"
additonal_packages="expect"

init_hooks="$SETUP_LOC/jetbrains-toolbox-${INTELLJ_TOOLBOX_VERSION}/jetbrains-toolbox"
# TODO: automate with expect init_hooks="echo y | socat stdio exec:$SETUP_LOC/ghcup,pty,setsid,echo=0"

exported_bins="/usr/bin/git"
exported_apps="$HOME/.local/share/applications/jetbrains-toolbox.desktop"

# cleanup (remove script automation tool)
init_hooks="sudo apt -y purge expect"
init_hooks="rm -rf $SETUP_LOC && unset SETUP_LOC"
init_hooks="unset INTELLJ_TOOLBOX_VERSION"
@amonull amonull added the enhancement New feature or request label Dec 28, 2024
@amonull
Copy link
Author

amonull commented Jan 4, 2025

After trying init_hooks it seems to use the vars in the actual way that i assumed it did (for pre_init_hooks) and it now feels clear that pre_init is meant to be used before the container is even setup so my solutions and manifest file would not even work as intended.

Closing issue.

@amonull amonull closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant