Skip to content
Snippets Groups Projects
venv 2.15 KiB
# simplistic "venv" you can use with "source venv" (pwd = same directory is required)


function info() {
  t="$1"
  shift
  printf "[\033[32minfo\033[0m][venv] $t\n" "$@"
}

function warn() {
  t="$1"
  shift
  printf "[\033[33mwarning\033[0m][venv] $t\n" "$@"
}

function error() {
  t="$1"
  shift
  printf "[\033[31merror\033[0m][venv] $t\n" "$@"
}

project_dir="$(pwd)"
if [ ! -f "$project_dir/venv" ]; then
    error "please use for \"source venv\" the git root as working directory. I couldn't find \"$project_dir/venv\""
    exit 1
fi
PS1="(OpenCoDE) ${PS1:-}"

info "exporting $(grep -Ece '^[^#=][^#=]*' .env || echo 0) variables from .env"
set -a
source .env
cluster_config="$(realpath "$project_dir/../subcluster1.yaml")"
# set default cluster
if [ -f "$cluster_config" ]; then
    # shellcheck disable=SC2034 # false positive due to set -a
    KUBECONFIG="$cluster_config"
    info "set KUBECONFIG = $KUBECONFIG"
else
    warn "no cluster config found at $cluster_config. Only if you want to use kubectl you need one!"
fi
set +a

function set_alias() {
    #shellcheck disable=SC2139 # we want to set it during definition
    alias "${1:?}=${2:?}"
    info "$1\t\t${3:-${2}}"
}
set_alias gradlew "\"$project_dir/gradlew\" --project-dir \"$project_dir\"" "execute gradlew from anywhere"
set_alias compose "docker compose"
set_alias dev "kubectl --namespace=fraunhofer"
set_alias prod "kubectl --namespace=fraunhoferprod"

info "dev-overview\tshow dev pods / containers / state"
function dev-overview() {
    echo -e "Namespace:\tPod:\t\t\t\tContainer:\tready:"
    dev get pods -o jsonpath='{range .items[*]}{.metadata.namespace}{"\t"}{.metadata.name}{"\t"}{range .status.containerStatuses[*]}{.name}{"\t"}{.ready}{"\n"}{end}{end}'
}

info "prod-overview\tshow prod pods / containers / state"
function prod-overview() {
    echo -e "Namespace:\tPod:\t\t\t\tContainer:\tready:"
    prod get pods -o jsonpath='{range .items[*]}{.metadata.namespace}{"\t"}{.metadata.name}{"\t"}{range .status.containerStatuses[*]}{.name}{"\t"}{.ready}{"\n"}{end}{end}'
}

info "reload-venv\treload venv file"
function reload-venv() {
    PS1="${PS1:23}" # remove "(OpenCoDE) "
    source "${project_dir:?}/venv"
}

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.