Skip to content

Commit

Permalink
ci: This is the last one :rofl
Browse files Browse the repository at this point in the history
  • Loading branch information
MAHDTech committed Jul 22, 2023
1 parent 640e282 commit 9681595
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 98 deletions.
2 changes: 2 additions & 0 deletions nix/oci/tanzu/root/etc/profile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

Expand Down
2 changes: 2 additions & 0 deletions nix/oci/tanzu/root/etc/profile.d/shopt.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

##################################################
# Name: shopt
# Description: Contains the bash shell options configurations
Expand Down
120 changes: 60 additions & 60 deletions nix/oci/tanzu/root/etc/profile.d/tanzu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ if [[ -f "${HOME}/.config/tanzu/config.yaml" ]]; then
fi

# Make sure that the interactive parts are not run in a a VSCode remote env.
if [[ "${ENVIRONMENT_VSCODE^^}" == "CONTAINER" ]]; then
if [[ ${ENVIRONMENT_VSCODE^^} == "CONTAINER" ]]; then

echo "$(date '+%Y/%m/%d %T'): INFO: VSCode container environment detected, skipping interactive parts." | tee -a "/tmp/environment.log"
echo "$(date '+%Y/%m/%d %T'): INFO: Devcontainer is running, skipping Tanzu init." | tee -a "/tmp/environment.log"

else

Expand All @@ -69,92 +69,92 @@ else

case "$CHOICE" in

[Yy]*)
[Yy]*)

echo "INFO: Initialising Tanzu CLI..."
echo "INFO: Initialising Tanzu CLI..."

tanzu plugin clean || {
echo "ERROR: Failed to clean the Tanzu CLI plugins"
}
tanzu plugin clean || {
echo "ERROR: Failed to clean the Tanzu CLI plugins"
}

tanzu init || {
echo "ERROR: Failed to initialise the Tanzu CLI configuration"
}
tanzu init || {
echo "ERROR: Failed to initialise the Tanzu CLI configuration"
}

# There are 3 options for the Tanzu CLI OCI registry in preference order:
# 1. A custom registry is provided, use it.
# 2. A pull-through cache is provided, use it.
# 3. No pull-through or custom registry is provided, pull direct from internet.
# There are 3 options for the Tanzu CLI OCI registry in preference order:
# 1. A custom registry is provided, use it.
# 2. A pull-through cache is provided, use it.
# 3. No pull-through or custom registry is provided, pull direct from internet.

# If there is a custom registry, use it as priority.
if [[ ${TANZU_CUSTOM_REGISTRY:-EMPTY} != "EMPTY" ]]; then
# If there is a custom registry, use it as priority.
if [[ ${TANZU_CUSTOM_REGISTRY:-EMPTY} != "EMPTY" ]]; then

echo "INFO: Custom registry provided, using ${TANZU_CUSTOM_REGISTRY}"
echo "INFO: Custom registry provided, using ${TANZU_CUSTOM_REGISTRY}"

# Capture existing OCI URL
TANZU_CLI_OCI_URL="$(tanzu plugin source list --output yaml | yq .[].image)"
# Capture existing OCI URL
TANZU_CLI_OCI_URL="$(tanzu plugin source list --output yaml | yq .[].image)"

# Strip the VMware registry prefix.
TANZU_CLI_OCI_URL="${TANZU_CLI_OCI_URL#*projects.registry.vmware.com}"
# Strip the VMware registry prefix.
TANZU_CLI_OCI_URL="${TANZU_CLI_OCI_URL#*projects.registry.vmware.com}"

# Add the custom registry OCI URL and update the plugin cache.
TANZU_CLI_OCI_URL="${TANZU_CUSTOM_REGISTRY}${TANZU_CLI_OCI_URL}"
# Add the custom registry OCI URL and update the plugin cache.
TANZU_CLI_OCI_URL="${TANZU_CUSTOM_REGISTRY}${TANZU_CLI_OCI_URL}"

# Update the plugin source and test pulling the image.
tanzu plugin source update \
default \
--uri "${TANZU_CLI_OCI_URL}" || {
echo "ERROR: Failed to update plugin configuration to use the provided custom registry."
}
# Update the plugin source and test pulling the image.
tanzu plugin source update \
default \
--uri "${TANZU_CLI_OCI_URL}" || {
echo "ERROR: Failed to update plugin configuration to use the provided custom registry."
}

elif [[ ${TANZU_PULL_THROUGH_CACHE:-EMPTY} != "EMPTY" ]]; then
elif [[ ${TANZU_PULL_THROUGH_CACHE:-EMPTY} != "EMPTY" ]]; then

echo "INFO: Pull-through prefix provided, prefixing ${TANZU_PULL_THROUGH_CACHE}"
echo "INFO: Pull-through prefix provided, prefixing ${TANZU_PULL_THROUGH_CACHE}"

# Capture existing OCI URL
TANZU_CLI_OCI_URL="$(tanzu plugin source list --output yaml | yq .[].image)"
# Capture existing OCI URL
TANZU_CLI_OCI_URL="$(tanzu plugin source list --output yaml | yq .[].image)"

# Add the pull-through prefix
TANZU_CLI_OCI_URL="${TANZU_PULL_THROUGH_CACHE}/${TANZU_CLI_OCI_URL}"
# Add the pull-through prefix
TANZU_CLI_OCI_URL="${TANZU_PULL_THROUGH_CACHE}/${TANZU_CLI_OCI_URL}"

# Add the pull-through cache OCI URL and update the plugin cache.
tanzu plugin source update \
default \
--uri "${TANZU_CLI_OCI_URL}" || {
echo "ERROR: Failed to update plugin configuration to use the provided pull-through cache."
}
# Add the pull-through cache OCI URL and update the plugin cache.
tanzu plugin source update \
default \
--uri "${TANZU_CLI_OCI_URL}" || {
echo "ERROR: Failed to update plugin configuration to use the provided pull-through cache."
}

else
else

echo "INFO: No custom registry or pull-through cache provided, pulling direct from internet."
echo "INFO: No custom registry or pull-through cache provided, pulling direct from internet."

fi
fi

# Add the VMWare TKG group of plugins at the configured version to match the CLI.
tanzu plugin install \
--group "vmware-tkg/default:${TANZU_CLI_PLUGIN_GROUP_TKG_VERSION}" || {
echo "ERROR: Failed to install the Tanzu plugin group vmware-tkg/default:${TANZU_CLI_PLUGIN_GROUP_TKG_VERSION}"
}
# Add the VMWare TKG group of plugins at the configured version to match the CLI.
tanzu plugin install \
--group "vmware-tkg/default:${TANZU_CLI_PLUGIN_GROUP_TKG_VERSION}" || {
echo "ERROR: Failed to install the Tanzu plugin group vmware-tkg/default:${TANZU_CLI_PLUGIN_GROUP_TKG_VERSION}"
}

tanzu plugin sync || {
echo "ERROR: Failed to synchronise Tanzu CLI plugins"
}
tanzu plugin sync || {
echo "ERROR: Failed to synchronise Tanzu CLI plugins"
}

break
break

;;
;;

[Nn]*)
[Nn]*)

break
break

;;
;;

*)
*)

echo "Please answer yes or no."
echo "Please answer yes or no."

;;
;;

esac

Expand Down
2 changes: 2 additions & 0 deletions nix/oci/tanzu/root/etc/skel/.bash_logout
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
if [ "$SHLVL" = 1 ]; then
[ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi

echo "$(date '+%Y/%m/%d %T'): INFO: Logout of Devcontainer Environment: ${ENVIRONMENT_VSCODE}" >> "/tmp/environment.log"
55 changes: 34 additions & 21 deletions nix/oci/tanzu/root/etc/skel/.bashrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/usr/bin/env bash

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return ;;

*i*) ;;

*) return ;;

esac

# don't put duplicate lines or lines starting with space in the history.
Expand Down Expand Up @@ -40,7 +45,7 @@ fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color | *-256color) color_prompt=yes ;;
xterm-color | *-256color) color_prompt=yes ;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
Expand Down Expand Up @@ -68,38 +73,43 @@ unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm* | rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*) ;;
xterm* | rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*) ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"

if [[ -r ~/.dircolors ]]; then
eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
fi

alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

#alias grep='grep --color=auto'
#alias fgrep='fgrep --color=auto'
#alias egrep='egrep --color=auto'
fi
#colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
fi

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
# shellcheck disable=SC1090
. ~/.bash_aliases
fi

Expand All @@ -108,14 +118,16 @@ fi
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
# shellcheck disable=SC1091
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
# shellcheck disable=SC1091
. /etc/bash_completion
fi
fi

# Make sure that the interactive parts are not run in a a VSCode remote env.
if [[ "${ENVIRONMENT_VSCODE^^}" == "CONTAINER" ]]; then
if [[ ${ENVIRONMENT_VSCODE^^} == "CONTAINER" ]]; then

echo "$(date '+%Y/%m/%d %T'): INFO: VSCode container environment detected, skipping interactive parts." | tee -a "/tmp/environment.log"

Expand All @@ -124,6 +136,7 @@ else
# Starship
if [[ ${ENABLE_STARSHIP:-FALSE} == "TRUE" ]]; then
echo "INFO: Launching Starship prompt..."
# shellcheck disable=SC1090
source <(/bin/starship init bash)
else
echo "INFO: Starship prompt is disabled."
Expand All @@ -134,4 +147,4 @@ fi
echo "INFO: Finished loading .bashrc"

# When running in a VSCode environment, drop a log file for tracking
echo "$(date '+%Y/%m/%d %T'): INFO: VSCode Environment: ${ENVIRONMENT_VSCODE}" >> "/tmp/environment.log"
echo "$(date '+%Y/%m/%d %T'): INFO: Login to Devcontainer Environment: ${ENVIRONMENT_VSCODE}" >>"/tmp/environment.log"
2 changes: 2 additions & 0 deletions nix/oci/tanzu/root/etc/skel/.profile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#/usr/bin/env bash

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
Expand Down
37 changes: 20 additions & 17 deletions nix/oci/tanzu/root/usr/local/bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ if [[ ${ENABLE_DEBUG:-FALSE} == "TRUE" ]]; then
set -x
fi

# Start a fresh shell session.
/usr/bin/env bash --login -i || true

# Make sure that the interactive parts are not run in a a VSCode remote env.
if [[ "${ENVIRONMENT_VSCODE^^}" == "CONTAINER" ]]; then
if [[ ${ENVIRONMENT_VSCODE^^} == "CONTAINER" ]]; then

echo "$(date '+%Y/%m/%d %T'): INFO: VSCode container environment detected, skipping interactive parts." | tee -a "/tmp/environment.log"
while true; do
echo "$(date '+%Y/%m/%d %T'): INFO: Devcontainer environment is running..." | tee -a "/tmp/environment.log"
sleep 300
done

else

# Start a fresh shell session.
/usr/bin/env bash --login -i || true

while true; do

clear
Expand All @@ -25,26 +28,26 @@ else

case $CHOICE in

[Yy]*)
[Yy]*)

echo "Restarting shell..."
/usr/bin/env bash --login -i || true
echo "Restarting shell..."
/usr/bin/env bash --login -i || true

;;
;;

[Nn]*)
[Nn]*)

echo "Exiting..."
break
echo "Exiting..."
break

;;
;;

*)
*)

echo "Please answer yes or no."
sleep 1
echo "Please answer yes or no."
sleep 1

;;
;;

esac

Expand Down

0 comments on commit 9681595

Please sign in to comment.