Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/ent
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ RUN() {
handle_status_config ENTANDO_APPVER "$@"
;;
"appname") #H: sets the default application names
handle_status_config ENTANDO_APPNAME "$@"
handle_appname "$@"
;;
"profile"|"P"|"pro") #H: helps creating and managing profiles
# shellcheck disable=SC1090
Expand Down
10 changes: 9 additions & 1 deletion bin/mod/ent-app
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ RUN() {
"status") #H: prints status information about the current EntandoApp
local WATCH
determine_namespace ENTANDO_NAMESPACE "$@"
args_or_ask -h "$HH" -n -p ENTANDO_APPNAME "--appname/ext_ic_id//%sp the application name" "$@"
args_or_ask -h "$HH" -n -p ENTANDO_APPNAME "--appname/appname_param//%sp the application name" "$@"
args_or_ask -h "$HH" -n -F WATCH "--watch///" "$@"

[ -n "$HH" ] && exit 0

kube.discover-and-set-app-name-if-needed

if [[ "$ENTANDO_APPNAME" == ":auto" && "${ENTANDO_DISABLE_APPNAME_DISCOVERY}" == "true" ]]; then
_log_e "Auto-discovery is disabled (ENTANDO_DISABLE_APPNAME_DISCOVERY=true)"
_log_e "Cannot use ':auto' - please provide an explicit app name"
exit 1
fi

if $WATCH; then
ent app-info watch "$ENTANDO_APPNAME" "$ENTANDO_NAMESPACE"
else
Expand Down
9 changes: 9 additions & 0 deletions bin/mod/ent-app-info
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ WATCH=false; [ "$1" = "watch" ] && { WATCH=true; shift; }
reload_cfg

[ -n "$1" ] && ENTANDO_APPNAME="$1" && shift

kube.discover-and-set-app-name-if-needed

if [[ "$ENTANDO_APPNAME" == ":auto" && "${ENTANDO_DISABLE_APPNAME_DISCOVERY}" == "true" ]]; then
_log_e "Auto-discovery is disabled (ENTANDO_DISABLE_APPNAME_DISCOVERY=true)"
_log_e "Cannot use ':auto' - please provide an explicit app name"
exit 1
fi

[ "$ENTANDO_APPNAME" = "" ] && echo "please provide the app name" 1>&2 && exit 1
[ -n "$1" ] && ENTANDO_NAMESPACE="$1" && shift
[ "$ENTANDO_NAMESPACE" = "" ] && echo "please provide the namespace name" 1>&2 && exit 1
Expand Down
163 changes: 143 additions & 20 deletions bin/mod/ent-check-env
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN() {


# DEVELOP TOOLS
$M_DEVL && check-env.develop.minimal-tools-requirements
$M_DEVL_BASE && check-env.develop.minimal-tools-requirements

# ENT-LOCAL NODE
$M_DEVL_BASE && check-env.check-node
Expand Down Expand Up @@ -208,11 +208,17 @@ check-env.check-jhipster() {
parse-version-flags FLAGS VER_JHIPSTER_DEF VER_JHIPSTER_REQ ENTANDO_JHIPSTER_VERSION_OVERRIDE
_str_contains "$FLAGS" ",f," && FORCE=true

check-env.npm-registry-package central-registry "jhipster" "generator-jhipster" \
"$VER_JHIPSTER_REQ" \
"$VER_JHIPSTER_DEF" \
"$ENTANDO_JHIPSTER_VERSION_OVERRIDE" \
"$FORCE"
if [ "${ENTANDO_CLI_HIDE_PRIVATE_NODEJS}" == "true" ]; then
# Use user's node - only check user's installation
check-env.check-jhipster-in-user-node "$VER_JHIPSTER_DEF" "$FORCE"
else
# Use ent's private node - only check ent's installation
check-env.npm-registry-package central-registry "jhipster" "generator-jhipster" \
"$VER_JHIPSTER_REQ" \
"$VER_JHIPSTER_DEF" \
"$ENTANDO_JHIPSTER_VERSION_OVERRIDE" \
"$FORCE"
fi
}


Expand All @@ -224,22 +230,24 @@ check-env.check-bundle-cli() {
parse-version-flags FLAGS VER_ENTANDO_BUNDLE_CLI_DEF VER_ENTANDO_BUNDLE_CLI_REQ ENTANDO_BUNDLE_CLI_VERSION_OVERRIDE
_str_contains "$FLAGS" ",f," && FORCE=true

if [[ "$VER_ENTANDO_BUNDLE_CLI_REQ" == "v1.2.0" || "$VER_ENTANDO_BUNDLE_CLI_REQ" == *"v1.0"* ]]; then
local SOURCE_BASED=true
_str_contains "$FLAGS" ",r," && SOURCE_BASED=false
else
if [[ "$VER_ENTANDO_BUNDLE_CLI_REQ" == *"v1.2.0"* || "$VER_ENTANDO_BUNDLE_CLI_REQ" == *"v1.0"* ]]; then
# OLD VERSIONS
local SOURCE_BASED=false
_str_contains "$FLAGS" ",g," && SOURCE_BASED=true
else
# NEW VERSIONS
local SOURCE_BASED=true
_str_contains "$FLAGS" ",r," && SOURCE_BASED=false
fi

if $SOURCE_BASED; then
check-env.npm-registry-package entando-registry "entando-bundle-cli" "@entando/entando-bundle-cli" \
check_npm_git_package --full "$REPO_ENTANDO_BUNDLE_CLI_ADDR" \
"$VER_ENTANDO_BUNDLE_CLI_REQ" "$VER_ENTANDO_BUNDLE_CLI_DEF" \
"$C_ENTANDO_BUNDLE_CLI_DIR" "$C_ENTANDO_BUNDLE_CLI_DIR" \
"$FORCE"
else
check_npm_git_package --full "$REPO_ENTANDO_BUNDLE_CLI_ADDR" \
check-env.npm-registry-package entando-registry "entando-bundle-cli" "@entando/entando-bundle-cli" \
"$VER_ENTANDO_BUNDLE_CLI_REQ" "$VER_ENTANDO_BUNDLE_CLI_DEF" \
"$C_ENTANDO_BUNDLE_CLI_DIR" "$C_ENTANDO_BUNDLE_CLI_DIR" \
"$FORCE"
fi
}
Expand All @@ -249,10 +257,126 @@ check-env.check-generator-jhipster-entando() {
parse-version-flags FLAGS VER_GENERATOR_JHIPSTER_ENTANDO_DEF VER_GENERATOR_JHIPSTER_ENTANDO_REQ ENTANDO_GENERATOR_JHIPSTER_VERSION_OVERRIDE
_str_contains "$FLAGS" ",f," && FORCE=true

check_npm_git_package "$REPO_GENERATOR_JHIPSTER_ENTANDO_ADDR" \
"$VER_GENERATOR_JHIPSTER_ENTANDO_REQ" "$VER_GENERATOR_JHIPSTER_ENTANDO_DEF" \
"$C_GENERATOR_JHIPSTER_ENTANDO_NAME" "$C_GENERATOR_JHIPSTER_ENTANDO_NAME" \
"$FORCE"
if [ "${ENTANDO_CLI_HIDE_PRIVATE_NODEJS}" == "true" ]; then
# Use user's node - first ensure the package is cloned/built, then install to user's node
check_npm_git_package --no-local-install "$REPO_GENERATOR_JHIPSTER_ENTANDO_ADDR" \
"$VER_GENERATOR_JHIPSTER_ENTANDO_REQ" "$VER_GENERATOR_JHIPSTER_ENTANDO_DEF" \
"$C_GENERATOR_JHIPSTER_ENTANDO_NAME" "$C_GENERATOR_JHIPSTER_ENTANDO_NAME" \
"$FORCE"
check-env.check-generator-jhipster-entando-in-user-node "$VER_GENERATOR_JHIPSTER_ENTANDO_DEF" "$FORCE"
else
# Use ent's private node - only check ent's installation
check_npm_git_package "$REPO_GENERATOR_JHIPSTER_ENTANDO_ADDR" \
"$VER_GENERATOR_JHIPSTER_ENTANDO_REQ" "$VER_GENERATOR_JHIPSTER_ENTANDO_DEF" \
"$C_GENERATOR_JHIPSTER_ENTANDO_NAME" "$C_GENERATOR_JHIPSTER_ENTANDO_NAME" \
"$FORCE"
fi
}

check-env.check-jhipster-in-user-node() {
local VER_DEF="$1"
local FORCE="$2"

_log_i "Checking user's node installation of jhipster.."

# Filter out ent's private node from PATH to use only user's node
local ENT_NODE_PREFIX="$ENT_OPTS/node-"
local FILTERED_PATH=$(echo "$PATH" | tr ':' '\n' | grep -v "^${ENT_NODE_PREFIX}" | tr '\n' ':' | sed 's/:$//')

# Run npm commands with user's node only
(
export PATH="$FILTERED_PATH"

# Check if user has node installed
if ! command -v node &> /dev/null; then
_log_w "User's node.js is not found in PATH"
_log_w "Please install Node.js v16 or later (recommended: Node v16.20.2)"
_log_w "Visit https://nodejs.org/ or use nvm: https://github.com/nvm-sh/nvm"
return 1
fi

local USER_NODE_VERSION=$(node --version 2>/dev/null)
_log_i "\tUser's node version: $USER_NODE_VERSION"

# Check if version is compatible (v16.x recommended)
local NODE_MAJOR_VERSION=$(echo "$USER_NODE_VERSION" | sed 's/v\([0-9]*\).*/\1/')
if [[ "$NODE_MAJOR_VERSION" -lt 16 ]]; then
_log_w "\tWARNING: Node.js $USER_NODE_VERSION may not be compatible with JHipster 7.9.3"
_log_w "\tRecommended: Node v16.20.2 (tested and verified to work)"
_log_w "\tTo switch: nvm install v16.20.2 && nvm use v16.20.2"
elif [[ "$NODE_MAJOR_VERSION" -gt 20 ]]; then
_log_w "\tWARNING: Node.js $USER_NODE_VERSION has not been tested with JHipster 7.9.3"
_log_w "\tRecommended: Node v16.20.2 (tested and verified to work)"
_log_w "\tTo switch: nvm install v16.20.2 && nvm use v16.20.2"
elif [[ "$NODE_MAJOR_VERSION" -ne 16 ]]; then
_log_i "\tNote: You're using Node.js $USER_NODE_VERSION. If you encounter issues, try Node v16.20.2"
fi

if npm list -g generator-jhipster 2>/dev/null | grep -q "generator-jhipster@"; then
_log_i "\tgenerator-jhipster is already installed in user's node => OK"
else
_log_i "\tgenerator-jhipster not found in user's node"
if ask "Should I install generator-jhipster@$VER_DEF in your node?" "y"; then
_log_i "\tInstalling generator-jhipster@$VER_DEF globally in user's node.."
npm install -g "generator-jhipster@$VER_DEF" || {
_log_w "Failed to install in user's node. You may need to install it manually with:"
_log_w " npm install -g generator-jhipster@$VER_DEF"
}
else
_log_w "Skipping installation in user's node. JHipster commands may not work with user's node."
fi
fi
)
}

check-env.check-generator-jhipster-entando-in-user-node() {
local VER_DEF="$1"
local FORCE="$2"

_log_i "Checking user's node installation of generator-jhipster-entando.."

# Filter out ent's private node from PATH to use only user's node
local ENT_NODE_PREFIX="$ENT_OPTS/node-"
local FILTERED_PATH=$(echo "$PATH" | tr ':' '\n' | grep -v "^${ENT_NODE_PREFIX}" | tr '\n' ':' | sed 's/:$//')

# Run npm commands with user's node only
(
export PATH="$FILTERED_PATH"

# Check if user has node installed
if ! command -v node &> /dev/null; then
_log_w "User's node.js is not found in PATH"
_log_w "Please install Node.js v16 or later (recommended: Node v16.20.2)"
return 1
fi

# Check if version is compatible (v16.x recommended)
local USER_NODE_VERSION=$(node --version 2>/dev/null)
local NODE_MAJOR_VERSION=$(echo "$USER_NODE_VERSION" | sed 's/v\([0-9]*\).*/\1/')
if [[ "$NODE_MAJOR_VERSION" -lt 16 ]]; then
_log_w "\tWARNING: Node.js $USER_NODE_VERSION may not be compatible with JHipster 7.9.3"
_log_w "\tRecommended: Node v16.20.2 (tested and verified to work)"
elif [[ "$NODE_MAJOR_VERSION" -gt 20 ]]; then
_log_w "\tWARNING: Node.js $USER_NODE_VERSION has not been tested with JHipster 7.9.3"
_log_w "\tRecommended: Node v16.20.2 (tested and verified to work)"
fi

if npm list -g generator-jhipster-entando 2>/dev/null | grep -q "generator-jhipster-entando@"; then
_log_i "\tgenerator-jhipster-entando is already installed in user's node => OK"
else
_log_i "\tgenerator-jhipster-entando not found in user's node"
if ask "Should I install generator-jhipster-entando@$VER_DEF from ent's installation in your node?" "y"; then
_log_i "\tInstalling generator-jhipster-entando from $ENT_OPTS_ENTANDO/generator-jhipster-entando/$VER_DEF"
# Install from the already-built git source in ent's private directory
npm install -g "$ENT_OPTS_ENTANDO/generator-jhipster-entando/$VER_DEF" || {
_log_w "Failed to install in user's node. You may need to install it manually with:"
_log_w " npm install -g $ENT_OPTS_ENTANDO/generator-jhipster-entando/$VER_DEF"
}
else
_log_w "Skipping installation in user's node. JHipster commands may not work with user's node."
fi
fi
)
}

check-env.check-bundler() {
Expand Down Expand Up @@ -403,8 +527,7 @@ check_npm_git_package() {
) || _SOE

# ACTUAL INSTALLATION

___npm "PHASE 2" install --global
___npm "PHASE 2" install --ignore-scripts --global

date > .entando-finalized
echo '~~~'$'\n'
Expand Down
8 changes: 8 additions & 0 deletions bin/mod/ent-host
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ RUN() {
set_nn_dn "ENTANDO_APPNAME" "${CFG_ARR[1]}"
set_nn_fdn "ENTANDO_SUFFIX" "${CFG_ARR[2]}"

kube.discover-and-set-app-name-if-needed

if [[ "$ENTANDO_APPNAME" == ":auto" && "${ENTANDO_DISABLE_APPNAME_DISCOVERY}" == "true" ]]; then
_log_e "Auto-discovery is disabled (ENTANDO_DISABLE_APPNAME_DISCOVERY=true)"
_log_e "Cannot use ':auto' - please provide an explicit app name"
exit 1
fi

_log_i "In VM: $VM_NAME"
_log_i "Found NAMESPACE: $ENTANDO_NAMESPACE"
_log_i "Found APPNAME: $ENTANDO_APPNAME"
Expand Down
22 changes: 18 additions & 4 deletions bin/mod/ent-profile
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ _use_or_list_profile() {

setup_curr_profile() {
HH="$(parse_help_option "$@")"
args_or_ask -h "$HH" ENTANDO_APPNAME "--appname/ext_ic_id/$PROFILE/%sp EntandoApp name" "$@" && {
args_or_ask -h "$HH" ENTANDO_APPNAME "--appname/appname_param/:auto/%sp EntandoApp name" "$@" && {
save_cfg_value ENTANDO_APPNAME "$ENTANDO_APPNAME"
}
args_or_ask -h "$HH" ENTANDO_NAMESPACE "--namespace/ext_ic_id/$PROFILE/%sp default namespace" "$@" && {
Expand Down Expand Up @@ -233,7 +233,7 @@ use_profile() {
. "$COMMAND_FILE" --full
activate_designated_workdir --temporary
else
set_curr_profile "$DESIGNATED_PROFILE" "$DESIGNATED_PROFILE_HOME" "$DESIGNATED_PROFILE_SUB"
set_curr_profile "$DESIGNATED_PROFILE" "" "$DESIGNATED_PROFILE_SUB"
activate_designated_workdir
fi
}
Expand Down Expand Up @@ -414,11 +414,24 @@ select_profile_item() {
_set_var "$res_var" "$_tmp_result"
}

assert_appname_param() {
if [[ "$2" == "<auto-discovered>" || "$2" == ":auto" ]]; then
if [ "${ENTANDO_DISABLE_APPNAME_DISCOVERY}" == "true" ]; then
_log_e "Auto-discovery is disabled (ENTANDO_DISABLE_APPNAME_DISCOVERY=true)"
_log_e "Please provide an explicit app name instead of ':auto'"
return 1
fi
return 0
fi
assert_ext_ic_id "$@"
}


parse_basic_profile_args() {
local from="$1"
shift
args_or_ask -h "$HH" -a ENTANDO_APPNAME "$((from + 0))/ext_ic_id/$PROFILE/%sp EntandoApp name" "$@"
args_or_ask -h "$HH" -a ENTANDO_NAMESPACE "$((from + 1))/ext_ic_id/$PROFILE/%sp default namespace" "$@"
args_or_ask ${HH:+"$HH"} -a ENTANDO_NAMESPACE "$((from + 0))/ext_ic_id/$PROFILE/%sp default namespace" "$@"
args_or_ask ${HH:+"$HH"} -a ENTANDO_APPNAME "$((from + 1))/appname_param/:auto/%sp EntandoApp name" "$@"
}

_determine_profile_dir() {
Expand Down Expand Up @@ -545,6 +558,7 @@ delete_profile() {
true
) && {
DESIGNATED_PROFILE="" DESIGNATED_PROFILE_SUB="" DESIGNATED_PROFILE_HOME=""
THIS_PROFILE=""
reload_cfg "$ENTANDO_GLOBAL_CFG"

if [ "$PROFILE" = "$THIS_APP_PROFILE" ]; then
Expand Down
4 changes: 4 additions & 0 deletions s/_conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ ENTANDO_CLI_HIDE_PRIVATE_NODEJS="true"
ENTANDO_NPM_REGISTRY_NO_SCHEMA="npm.pkg.github.com"
ENTANDO_NPM_REGISTRY="https://$ENTANDO_NPM_REGISTRY_NO_SCHEMA"

# KUBERNETES RELATED VALUES
ENTANDO_APPNAME=":auto"
ENTANDO_DISABLE_APPNAME_DISCOVERY=false

# UNPRIVILEDGED TOKEN USED FOR ANONYMOUS ACCESS TO GITHUB PACKAGES
# THE TOKEN HAS IN FACT NO PERMISSION BUT repository:read
# it's obfuscated just to avoid false positives from security scanners
Expand Down
16 changes: 16 additions & 0 deletions s/_root-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ print_config_file() {
print-secrets-leak-warning
}

handle_appname() {
bgn_help_parsing "${BASH_SOURCE[0]}" "$@"
args_or_ask -h "$HH" -a -n -- APPNAME '1///%sp the EntandoApp name' "$@"
if [ -z "$APPNAME" ]; then
args_or_ask -h "$HH" -n -f -- '--auto///%sp tries to auto-discover the EntandoApp name by checking the namespace' "$@" && {
# shellcheck disable=SC2034
ENTANDO_APPNAME=":auto"
kube.discover-and-set-app-name-if-needed
exit 0
}
fi
end_help_parsing

handle_status_config ENTANDO_APPNAME "$APPNAME"
}

handle_status_config() {
if [ "$V" = "--del" ]; then
ent config --set ""
Expand Down
1 change: 1 addition & 0 deletions s/check-app-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cd "$DIR/.." || {
# PARAMS

[ -n "$1" ] && ENTANDO_APPNAME="$1" && shift
kube.discover-and-set-app-name-if-needed
[ "$ENTANDO_APPNAME" = "" ] && echo "please provide the app name" 1>&2 && exit 1

[ -n "$1" ] && ENTANDO_NAMESPACE="$1" && shift
Expand Down
Loading