From f501f5d83b83e0d427e131da5ef14dc89de05461 Mon Sep 17 00:00:00 2001 From: Enguerrand de Ribaucourt Date: Wed, 28 Feb 2024 09:48:44 +0100 Subject: [PATCH 1/6] split user and global ssh config forwarding The user `~/.ssh` config forwarding is now controlled by the `CQFD_NO_USER_SSH_CONFIG` environment variable. This allows finer control over the ssh configuration forwarding. --- README.md | 11 +++++++---- cqfd | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 162875f..9e0b6ca 100644 --- a/README.md +++ b/README.md @@ -213,10 +213,13 @@ docker-build options to be append to the building image. Format is the same as (and passed to) docker-build’s options. See 'docker build --help'. -``CQFD_NO_SSH_CONFIG``: Set to ``true`` to disable forwarding -the user's ``~/.ssh`` and global ``/etc/ssh`` configurations to the -container. This may be required if the host's ``ssh`` configuration -is not compatible with the ``ssh`` version within the container. +``CQFD_NO_SSH_CONFIG``: Set to ``true`` to disable forwarding the global +``/etc/ssh`` configurations to the container. This may be required if +the host's ``ssh`` configuration is not compatible with the ``ssh`` +version within the container. + +``CQFD_NO_USER_SSH_CONFIG``: Set to ``true`` to disable forwarding +the user's ``~/.ssh`` configuration to the container. ### Appending to the build command ### diff --git a/cqfd b/cqfd index 501d5da..907b914 100755 --- a/cqfd +++ b/cqfd @@ -237,8 +237,11 @@ docker_run() { args+=(-e "$home_env_var") fi - if [ "$CQFD_NO_SSH_CONFIG" != true ]; then + if [ "$CQFD_NO_USER_SSH_CONFIG" != true ]; then args+=(-v "$cqfd_user_home/.ssh:$cqfd_user_home/.ssh") + fi + + if [ "$CQFD_NO_SSH_CONFIG" != true ]; then args+=(-v /etc/ssh:/etc/ssh) fi From 096ebdad732e68a86d4a09a79b24cd6da3c47903 Mon Sep 17 00:00:00 2001 From: Enguerrand de Ribaucourt Date: Thu, 5 Sep 2024 14:23:29 +0200 Subject: [PATCH 2/6] cqfd: Add option to forward the user's .gitconfig When running commands that use git, it is useful to have the user's .gitconfig available in the container. Mostly to have the user's name and email configured. For instance, when running Yocto's `devtool modify`, it will produce an error if the user's name and email are not configured. I chose to enable this new option by default, but it can be disabled with the `CQFD_NO_USER_GIT_CONFIG` environment variable. It is documented in the README. --- README.md | 3 +++ cqfd | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 9e0b6ca..595fbbc 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,9 @@ version within the container. ``CQFD_NO_USER_SSH_CONFIG``: Set to ``true`` to disable forwarding the user's ``~/.ssh`` configuration to the container. +``CQFD_NO_USER_GIT_CONFIG``: Set to ``true`` to disable forwarding +the user's ``~/.gitconfig`` configuration to the container. + ### Appending to the build command ### The `-c` option allows appending the command of a cqfd run for temporary developments: diff --git a/cqfd b/cqfd index 907b914..9578792 100755 --- a/cqfd +++ b/cqfd @@ -250,6 +250,10 @@ docker_run() { args+=(-e "SSH_AUTH_SOCK=$cqfd_user_home/.sockets/ssh") fi + if [ "$CQFD_NO_USER_GIT_CONFIG" != true ]; then + args+=(-v "$cqfd_user_home/.gitconfig:$cqfd_user_home/.gitconfig") + fi + args+=(-v "$cqfd_project_dir:$cqfd_project_dir") tmp_launcher=$(make_launcher) From cd6e730881f3682be78b9004a69fa0bb583ee7d1 Mon Sep 17 00:00:00 2001 From: Enguerrand de Ribaucourt Date: Thu, 5 Sep 2024 14:25:07 +0200 Subject: [PATCH 3/6] cqfd: use CQFD_SHELL also for the default login shell When running `cqfd run -c` commands, the default login shell could be used instead of the one defined for `cqfd shell`. This was confusing and not configurable. The same shell will be always used, defined by the `CQFD_SHELL` environment variable. This notably overcomes a regression when using scripts that require bashisms. In the previous release, the default shell was `/bin/bash`, and is now `/bin/sh`. Users relying on bashisms still need to set `CQFD_SHELL` to `/bin/bash` in their environment. See issue #310. --- README.md | 2 ++ cqfd | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 595fbbc..de16278 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,8 @@ the user's ``~/.ssh`` configuration to the container. ``CQFD_NO_USER_GIT_CONFIG``: Set to ``true`` to disable forwarding the user's ``~/.gitconfig`` configuration to the container. +``CQFD_SHELL``: The shell to be launched, by default ``/bin/sh``. + ### Appending to the build command ### The `-c` option allows appending the command of a cqfd run for temporary developments: diff --git a/cqfd b/cqfd index 9578792..3407541 100755 --- a/cqfd +++ b/cqfd @@ -376,7 +376,7 @@ test_su_session_command && has_su_session_command=1 # Add the host's user and group to the container, and adjust ownership. groupadd -og $GROUPS -f builders || die "groupadd command failed." -useradd -s /bin/sh -oN -u $UID -g $GROUPS -d "$cqfd_user_home" $cqfd_user \ +useradd -s ${CQFD_SHELL:-/bin/sh} -oN -u $UID -g $GROUPS -d "$cqfd_user_home" $cqfd_user \ || die "useradd command failed." mkdir -p "$cqfd_user_home" || die "mkdir command failed." chown $UID:$GROUPS "$cqfd_user_home" || die "chown command failed." From 8a4a793d477e9572b618278cc1704a767b1ec17a Mon Sep 17 00:00:00 2001 From: Enguerrand de Ribaucourt Date: Thu, 5 Sep 2024 14:34:33 +0200 Subject: [PATCH 4/6] cqfd: revert bash as default shell The default shell used to be /bin/bash. This was changed to /bin/sh arbitrarily in commit 0051142 which broke builds for users relying on bash-specific features. Notably running bitbake. See Issue #130 --- cqfd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cqfd b/cqfd index 3407541..2cd5d9f 100755 --- a/cqfd +++ b/cqfd @@ -26,6 +26,7 @@ cqfdrc=".cqfdrc" cqfd_user='builder' cqfd_user_home='/home/builder' cqfd_user_cwd="$cqfd_user_home/src" +cqfd_shell=${CQFD_SHELL:-/bin/bash} ## usage() - print usage on stdout usage() { @@ -376,7 +377,7 @@ test_su_session_command && has_su_session_command=1 # Add the host's user and group to the container, and adjust ownership. groupadd -og $GROUPS -f builders || die "groupadd command failed." -useradd -s ${CQFD_SHELL:-/bin/sh} -oN -u $UID -g $GROUPS -d "$cqfd_user_home" $cqfd_user \ +useradd -s $cqfd_shell -oN -u $UID -g $GROUPS -d "$cqfd_user_home" $cqfd_user \ || die "useradd command failed." mkdir -p "$cqfd_user_home" || die "mkdir command failed." chown $UID:$GROUPS "$cqfd_user_home" || die "chown command failed." @@ -576,7 +577,7 @@ while [ $# -gt 0 ]; do shell) shift config_load "$flavor" - command_string="${CQFD_SHELL:-/bin/sh}" + command_string="$cqfd_shell" if [ "$#" -gt 0 ]; then command_string+=" ${@@Q}" fi From 16922b19ac0db176d6a7f72e18c08e3538678436 Mon Sep 17 00:00:00 2001 From: Enguerrand de Ribaucourt Date: Thu, 5 Sep 2024 16:00:37 +0200 Subject: [PATCH 5/6] cqfd: add a verbose option It can be useful for users to get access to the docker commands in order to tweak them, or dissect the options passed. --- cqfd | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cqfd b/cqfd index 2cd5d9f..54488aa 100755 --- a/cqfd +++ b/cqfd @@ -40,6 +40,7 @@ Options: -b Target a specific build flavor. -q Turn on quiet mode. -v or --version Show version. + --verbose Increase the script's verbosity. -h or --help Show this help text. Commands: @@ -113,11 +114,18 @@ die() { exit 1 } +## debug() - print verbose messages +debug() { + test -n "$CQFD_DEBUG" && echo "cqfd: debug: $*" || true +} + # docker_build() - Initialize build container docker_build() { if [ -z "$project_build_context" ]; then + debug executing: docker build ${quiet:+-q} $CQFD_EXTRA_BUILD_ARGS -t "$docker_img_name" "$(dirname "$dockerfile")" docker build ${quiet:+-q} $CQFD_EXTRA_BUILD_ARGS -t "$docker_img_name" "$(dirname "$dockerfile")" else + debug executing: docker build ${quiet:+-q} $CQFD_EXTRA_BUILD_ARGS -t "$docker_img_name" "${project_build_context}" -f "$dockerfile" docker build ${quiet:+-q} $CQFD_EXTRA_BUILD_ARGS -t "$docker_img_name" "${project_build_context}" -f "$dockerfile" fi } @@ -264,6 +272,7 @@ docker_run() { args+=("$docker_img_name" cqfd_launch "$1") + debug executing: docker run "${args[@]}" docker run "${args[@]}" } @@ -520,6 +529,9 @@ while [ $# -gt 0 ]; do echo $VERSION exit 0 ;; + verbose|"--verbose") + export CQFD_DEBUG=true + ;; init) config_load $flavor docker_build From bc52558410ccdb7324213a115ab355a95dc74ac5 Mon Sep 17 00:00:00 2001 From: Enguerrand de Ribaucourt Date: Fri, 6 Sep 2024 13:44:14 +0200 Subject: [PATCH 6/6] bash-completion: improve compatibility with zsh When running bash-completion's completion functions in zsh, the `_init_completion` and `_get_first_arg` functions are not defined in `bashcompinit`. Defining dummy functions allow using auto-completion in zsh although its not as accurate. Without _get_first_arg, the completion doesn't detail the options specific to that command and lists all of them. --- bash-completion | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bash-completion b/bash-completion index 574fb45..6d64549 100644 --- a/bash-completion +++ b/bash-completion @@ -15,6 +15,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ -z "$BASH_VERSION" ]; then + _init_completion() { + } + _get_first_arg() { + } +fi + _cqfd() { local cur prev words cword _init_completion || return