From e900e578a80d0161f6f9892e4fe0a0b09b586b7d Mon Sep 17 00:00:00 2001 From: Olivier Grand Date: Wed, 4 May 2022 12:03:55 +0200 Subject: [PATCH] install gcloud with ubuntu packages --- Dockerfile | 9 +++-- bosh-cli/profile | 85 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4462e63..78e7744 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,15 +48,13 @@ ENV INIT_PACKAGES="apt-transport-https ca-certificates curl openssh-server opens GEM_HOME="/usr/local/rvm/gems/ruby-${RUBY_VERSION}" \ GEM_PATH="/usr/local/rvm/gems/ruby-${RUBY_VERSION}:/usr/local/rvm/gems/ruby-${RUBY_VERSION}@global" \ CF_PLUGINS="CLI-Recorder,doctor,manifest-generator,Statistics,Targets,Usage Report" \ - KUBECTL_PLUGINS="get-all,ctx,ns" \ - GCP_CLI_COMPONENTS="alpha beta" + KUBECTL_PLUGINS="get-all,ctx,ns" ADD bosh-cli/* /tmp/bosh-cli/ RUN printf '\n=====================================================\n Install system packages\n=====================================================\n' && \ - apt-get update && apt-get install -y --no-install-recommends apt-utils && \ + apt-get update && apt-get install -y --no-install-recommends apt-utils dialog && \ apt-get install -y --no-install-recommends ${INIT_PACKAGES} ${TOOLS_PACKAGES} ${NET_PACKAGES} ${DEV_PACKAGES} ${RUBY_PACKAGES} && \ - apt-get upgrade -y && apt-get autoremove -y && apt-get clean && apt-get purge && \ cp /usr/bin/chardetect3 /usr/local/bin/chardetect && \ printf '\n=====================================================\n Install ruby tools\n=====================================================\n' && \ curl -sSL https://rvm.io/mpapis.asc | gpg --import - && curl -sSL https://rvm.io/pkuczynski.asc | gpg --import - && curl -sSL https://get.rvm.io | bash -s stable && \ @@ -88,7 +86,7 @@ RUN printf '\n=====================================================\n Install sy printf '\n=> Add CREDHUB-CLI\n' && curl -sSL "https://github.com/cloudfoundry-incubator/credhub-cli/releases/download/${CREDHUB_VERSION}/credhub-linux-${CREDHUB_VERSION}.tgz" | tar -xz -C /usr/local/bin && \ printf '\n=> Add FLY-CLI\n' && curl -sSL "https://github.com/concourse/concourse/releases/download/v${FLY_VERSION}/fly-${FLY_VERSION}-linux-amd64.tgz" | tar -xz -C /usr/local/bin && \ printf '\n=> Add FLUX-CLI\n' && curl -sSL "https://github.com/fluxcd/flux2/releases/download/v${FLUX_VERSION}/flux_${FLUX_VERSION}_linux_amd64.tar.gz" | tar -xz -C /usr/local/bin && \ - printf '\n=> Add GCP-CLI\n' && su -l bosh -s /bin/bash -c "curl -sSL "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-${GCP_CLI_VERSION}-linux-x86_64.tar.gz" | tar -xz -C /home/bosh ; /home/bosh/google-cloud-sdk/install.sh -q --usage-reporting false --additional-components ${GCP_CLI_COMPONENTS}" && \ + printf '\n=> Add GCP-CLI\n' && echo "deb https://packages.cloud.google.com/apt cloud-sdk main" > /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && apt-get update && apt-get install -y --no-install-recommends google-cloud-cli && \ printf '\n=> Add GOVC-CLI\n' && curl -sSL "https://github.com/vmware/govmomi/releases/download/v${GOVC_VERSION}/govc_Linux_x86_64.tar.gz" | tar -xz -C /tmp && mv /tmp/govc /usr/local/bin/govc && \ printf '\n=> Add GO3FR-CLI\n' && curl -sSL "https://github.com/rlmcpherson/s3gof3r/releases/download/v${GO3FR_VERSION}/gof3r_${GO3FR_VERSION}_linux_amd64.tar.gz" | tar -xz -C /tmp && mv /tmp/gof3r_${GO3FR_VERSION}_linux_amd64/gof3r /usr/local/bin/go3fr && \ printf '\n=> Add HELM-CLI\n' && curl -sSL "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar -xz -C /tmp && mv /tmp/linux-amd64/helm /usr/local/bin/helm && chmod 755 /usr/local/bin/helm && \ @@ -151,6 +149,7 @@ RUN printf '\n=====================================================\n Install sy printf ' "tools" command gives available tools.\n' >> /etc/motd && \ printf ' All path except "/data/shared" are not persistant (do not save data on it).\n\n' >> /etc/motd && \ printf '\n=====================================================\n Configure system and cleanup docker image\n=====================================================\n' && \ + apt-get upgrade -y && apt-get autoremove -y && apt-get clean && apt-get purge && \ locale-gen en_US.UTF-8 && \ mv /tmp/bosh-cli/*.sh /usr/local/bin/ && mv /tmp/bosh-cli/sshd.conf /etc/supervisor/conf.d/ && mv /tmp/bosh-cli/profile /home/bosh/.profile && chmod 664 /home/bosh/.profile && \ chmod 644 /etc/motd && mkdir -p /home/bosh/.ssh && chmod 700 /home/bosh /home/bosh/.ssh && \ diff --git a/bosh-cli/profile b/bosh-cli/profile index a32129e..d075e31 100644 --- a/bosh-cli/profile +++ b/bosh-cli/profile @@ -146,7 +146,7 @@ if [ ! -L ${HOME}/.cf/plugins ] ; then fi #--- Redefine Path to binary -export PATH=.:/data/shared/${MY_BOSH_USER}/bin:/home/bosh/google-cloud-sdk/bin:${HOME}/bosh/template/admin:${HOME}/.krew/bin:${PATH} +export PATH=.:/data/shared/${MY_BOSH_USER}/bin:${HOME}/bosh/template/admin:${HOME}/.krew/bin:${PATH} #--- Init user aliases cat > ${HOME}/.bash_aliases <<'EOF' @@ -356,8 +356,85 @@ source <(flux completion bash) #--- argo cli completion source <(argo completion bash) -#--- gcloud completion -source /home/bosh/google-cloud-sdk/completion.bash.inc +#--- gcloud cli completion +_python_argcomplete() { + local IFS=' ' + local prefix= + typeset -i n + (( lastw=${#COMP_WORDS[@]} -1)) + if [[ ${COMP_WORDS[lastw]} == --*=* ]]; then + # for bash version 3.2 + flag=${COMP_WORDS[lastw]%%=*} + set -- "$1" "$2" '=' + elif [[ $3 == '=' ]]; then + flag=${COMP_WORDS[-3]} + fi + if [[ $3 == ssh && $2 == *@* ]] ;then + # handle ssh user@instance specially + prefix=${2%@*}@ + COMP_LINE=${COMP_LINE%$2}"${2#*@}" + elif [[ $3 == '=' ]] ; then + # handle --flag=value + prefix=$flag=$2 + line=${COMP_LINE%$prefix}; + COMP_LINE=$line${prefix/=/ }; + prefix= + fi + if [[ $2 == *,* ]]; then + # handle , separated list + prefix=${2%,*}, + set -- "$1" "${2#$prefix}" "$3" + COMP_LINE==${COMP_LINE%$prefix*}$2 + fi + # Treat --flag= as --flag to work around bash 4.x bug + if [[ ${COMP_LINE} == *= && ${COMP_WORDS[-2]} == --* ]]; then + COMP_LINE=${COMP_LINE%=}' ' + fi + COMPREPLY=( $(IFS="$IFS" COMP_LINE="$COMP_LINE" COMP_POINT="$COMP_POINT" _ARGCOMPLETE_COMP_WORDBREAKS="$COMP_WORDBREAKS" _ARGCOMPLETE=1 "$1" 8>&1 9>&2 1>/dev/null 2>/dev/null) ) + if [[ $? != 0 ]]; then + unset COMPREPLY + return + fi + if [[ $prefix != '' ]]; then + for ((n=0; n < ${#COMPREPLY[@]}; n++)); do + COMPREPLY[$n]=$prefix${COMPREPLY[$n]} + done + fi + for ((n=0; n < ${#COMPREPLY[@]}; n++)); do + match=${COMPREPLY[$n]%' '} + if [[ $match != '' ]]; then + COMPREPLY[$n]=${match//? /' '}' ' + fi + done + # if flags argument has a single completion and ends in '= ', delete ' ' + if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} == -* && ${COMPREPLY[0]} == *'= ' ]]; then + COMPREPLY[0]=${COMPREPLY[0]%' '} + fi +} +complete -o nospace -F _python_argcomplete "gcloud" +complete -o nospace -F _python_argcomplete gsutil + +#--- bq cli completion +_completer() { + command=$1 + name=$2 + eval '[[ "$'"${name}"'_COMMANDS" ]] || '"${name}"'_COMMANDS="$('"${command}"')"' + set -- $COMP_LINE + shift + while [[ $1 == -* ]]; do + shift + done + [[ $2 ]] && return + grep -q "${name}\s*$" <<< $COMP_LINE && eval 'COMPREPLY=($'"${name}"'_COMMANDS)' && return + [[ "$COMP_LINE" == *" " ]] && return + [[ $1 ]] && eval 'COMPREPLY=($(echo "$'"${name}"'_COMMANDS" | grep ^'"$1"'))' +} + +unset bq_COMMANDS +_bq_completer() { + _completer "CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK=1 bq help | grep '^[^ ][^ ]* ' | sed 's/ .*//'" bq +} +complete -F _bq_completer bq #--- Load OSB-CMDB bash functions if [ -f /usr/local/bin/cf-cli-cmdb-functions.bash ] ; then @@ -369,4 +446,4 @@ EOF #--- Load user bash profile . ${HOME}/.bash_profile -cd ${HOME} +cd ${HOME} \ No newline at end of file