forked from freeleaps/freeleaps-pub
Update for support ./devbox freeleaps and ./devbox <product_id>
This commit is contained in:
parent
48ecc5c142
commit
12503a2924
@ -49,6 +49,79 @@ get_arg() {
|
||||
}
|
||||
|
||||
|
||||
devbox_init_guidance() {
|
||||
printf "Welcome to DevBox CLI!\n\n"
|
||||
# if $1 is empty, then ask user select a choice or match user input $1 action to be product_id
|
||||
if [[ -z $1 ]]; then
|
||||
# Guide user to select use freeleaps env or custom repository for source code
|
||||
printf "Please choose an option:\n"
|
||||
printf " 1. Use Freeleaps.com repository\n"
|
||||
printf " 2. Use custom repository\n"
|
||||
read -p "Enter your choice (1 or 2): " choice
|
||||
else
|
||||
echo "Your will start with init product $1 develop environment"
|
||||
product_id=$1
|
||||
case "$product_id" in
|
||||
freeleaps)
|
||||
choice=1
|
||||
;;
|
||||
*)
|
||||
choice=2
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
case "$choice" in
|
||||
1)
|
||||
freeleaps_username=""
|
||||
freeleaps_password=""
|
||||
use_local_component=false
|
||||
use_custom_repository=""
|
||||
freeleaps_components=""
|
||||
|
||||
# Ask user for Freeleaps.com username and password
|
||||
read -p "Enter your Freeleaps.com username: " freeleaps_username
|
||||
read -s -p "Enter your Freeleaps.com password: " freeleaps_password
|
||||
echo
|
||||
read -p "Use local component dev environment? (y/n): " choose_local_component
|
||||
if [[ $choose_local_component == "y" ]]; then
|
||||
use_local_component=true
|
||||
fi
|
||||
|
||||
add_arg "--freeleaps-username" "$freeleaps_username"
|
||||
add_arg "--freeleaps-password" "$freeleaps_password"
|
||||
add_arg "--use-local-component" "$use_local_component"
|
||||
add_arg "--use-custom-repository" "$use_custom_repository"
|
||||
;;
|
||||
2)
|
||||
# Ask user for Freeleaps.com username and password
|
||||
read -p "Enter your Freeleaps.com username: " freeleaps_username
|
||||
read -s -p "Enter your Freeleaps.com password: " freeleaps_password
|
||||
echo
|
||||
|
||||
add_arg "--freeleaps-username" "$freeleaps_username"
|
||||
add_arg "--freeleaps-password" "$freeleaps_password"
|
||||
|
||||
ENCODING_FREELEAPS_USERNAME=$(url_encode "$freeleaps_username")
|
||||
ENCODEING_FREELEAPS_PASSWORD=$(url_encode "$freeleaps_password")
|
||||
use_custom_repository="https://$ENCODING_FREELEAPS_USERNAME:$ENCODEING_FREELEAPS_PASSWORD@freeleaps.com:3443/products/$product_id.git"
|
||||
|
||||
# Test the repository connection
|
||||
if ! git ls-remote "$use_custom_repository"; then
|
||||
printf "Failed to connect to the repository. Please check your username and password.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "Repository connection successful.\n"
|
||||
|
||||
add_arg "--use-custom-repository" "$use_custom_repository"
|
||||
;;
|
||||
*)
|
||||
printf "Invalid choice. Exiting.\n"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# :command.usage
|
||||
devbox_usage() {
|
||||
@ -504,8 +577,6 @@ build_local_image() {
|
||||
# :command.command_functions
|
||||
# :command.function
|
||||
devbox_init_command() {
|
||||
|
||||
#!/usr/bin/env bash
|
||||
echo "==> [INIT] Starting DevBox environment initialization..."
|
||||
echo
|
||||
|
||||
@ -596,11 +667,8 @@ devbox_init_command() {
|
||||
start_components=("${components[@]}")
|
||||
fi
|
||||
|
||||
component_tag="latest-linux-arm64"
|
||||
if [[ "$ARCH" == "amd64" ]]; then
|
||||
component_tag="latest-linux-amd64"
|
||||
fi
|
||||
|
||||
echo "init arch value is : $ARCH "
|
||||
|
||||
# If is_pull_all_components is true, then pull all components
|
||||
if [[ "$is_pull_all_components" == true ]]; then
|
||||
start_components=("${components[@]}")
|
||||
@ -662,6 +730,10 @@ devbox_init_command() {
|
||||
fi
|
||||
fi
|
||||
|
||||
component_tag="latest-linux-arm64"
|
||||
if [[ "$ARCH" == "amd64" ]]; then
|
||||
component_tag="latest-linux-amd64"
|
||||
fi
|
||||
|
||||
# Default arch tag value if Arch is amd64 then latest-linux-amd64 else latest-linux-arm64
|
||||
local arch_tag="latest-linux-${ARCH}"
|
||||
@ -772,7 +844,6 @@ devbox_init_command() {
|
||||
if ! docker network ls | grep -q "$DEVBOX_FREELEAPS2_NETWORK"; then
|
||||
echo "==> Creating Docker network: $DEVBOX_FREELEAPS2_NETWORK"
|
||||
docker network create "$DEVBOX_FREELEAPS2_NETWORK"
|
||||
|
||||
else
|
||||
echo "==> Docker network devbox_freeleaps2-network already exists."
|
||||
fi
|
||||
@ -803,15 +874,19 @@ devbox_init_command() {
|
||||
echo "$DEVBOX_FRONTEND_PORT" > "$WORKING_HOME/.devbox-frontend-port"
|
||||
echo "$DEVBOX_BACKEND_PORT" > "$WORKING_HOME/.devbox-backend-port"
|
||||
|
||||
# Check if username and password are set
|
||||
if [[ -z "$FREELEAPS_USERNAME" || -z "$FREELEAPS_PASSWORD" ]]; then
|
||||
|
||||
# Check if use custom repository
|
||||
if [[ -n "$USE_CUSTOM_REPOSITORY" ]]; then
|
||||
echo "==> [INIT] Using custom repository."
|
||||
elif [[ -z "$FREELEAPS_USERNAME" || -z "$FREELEAPS_PASSWORD" ]]; then
|
||||
echo "Warining: Username and password are required to pull freeleaps.com code."
|
||||
echo "==> [INIT] DevBox environment initialization completed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
DOVBOX_CLI_DIR=$(pwd)
|
||||
|
||||
ECHO_USE_CUSTOM_REPOSITORY=""
|
||||
|
||||
# Check if USE_CUSTOM_REPOSITORY is empty
|
||||
if [[ -z "$USE_CUSTOM_REPOSITORY" ]]; then
|
||||
@ -854,6 +929,7 @@ devbox_init_command() {
|
||||
popd > /dev/null
|
||||
fi
|
||||
else
|
||||
|
||||
if ! echo "$USE_CUSTOM_REPOSITORY" | grep -Eq '^(https:\/\/|git@|git:\/\/|file:\/\/\/)[^ ]+\.git$'; then
|
||||
echo "ERROR: Invalid custom repository URL. Please provide a valid URL."
|
||||
exit 1
|
||||
@ -868,11 +944,13 @@ devbox_init_command() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ECHO_USE_CUSTOM_REPOSITORY=$(echo "$USE_CUSTOM_REPOSITORY" | sed 's/\(https:\/\/[^:]*\):[^@]*@/\1:****@/')
|
||||
|
||||
CUSTOM_FOLDER_NAME=$(basename "$USE_CUSTOM_REPOSITORY" .git)
|
||||
CUSTOM_DIR="$WORKING_HOME/$CUSTOM_FOLDER_NAME"
|
||||
if [ ! -d "$CUSTOM_DIR" ]; then
|
||||
pushd "$WORKING_HOME" > /dev/null
|
||||
echo "Git cloning custom repository: $USE_CUSTOM_REPOSITORY"
|
||||
echo "Git cloning custom repository: $ECHO_USE_CUSTOM_REPOSITORY"
|
||||
git clone --depth 5 "$USE_CUSTOM_REPOSITORY"
|
||||
else
|
||||
pushd "$CUSTOM_DIR" > /dev/null
|
||||
@ -883,7 +961,7 @@ devbox_init_command() {
|
||||
rmdir "$CUSTOM_DIR" # Remove $CUSTOM_DIR
|
||||
|
||||
# Git clone custom repository
|
||||
echo "Cloning repository again: $USE_CUSTOM_REPOSITORY"
|
||||
echo "Cloning repository again: $ECHO_USE_CUSTOM_REPOSITORY"
|
||||
sudo chown -R "$OWNER_GROUP" "$WORKING_HOME"
|
||||
git clone --depth 5 "$USE_CUSTOM_REPOSITORY"
|
||||
else
|
||||
@ -912,11 +990,14 @@ echo "$USE_CUSTOM_REPOSITORY" > "$WORKING_HOME/.custom-repository"
|
||||
|
||||
# If USE_CUSTOM_REPOSITORY is not empty, initialize the custom repository completed
|
||||
if [[ -n "$USE_CUSTOM_REPOSITORY" ]]; then
|
||||
# Remove the ':' and password from USE_CUSTOM_REPOSITORY
|
||||
|
||||
|
||||
echo
|
||||
echo "==========================================================="
|
||||
echo "==> [INIT] Custom repository initialization completed."
|
||||
echo "==> Custom repository is located at: ${WORKING_HOME}/${CUSTOM_FOLDER_NAME}"
|
||||
echo "==> Custom repository URL: $USE_CUSTOM_REPOSITORY"
|
||||
echo "==> Custom repository URL: $ECHO_USE_CUSTOM_REPOSITORY"
|
||||
echo "==> Custom repository is ready for use."
|
||||
echo "==========================================================="
|
||||
echo
|
||||
@ -924,7 +1005,7 @@ if [[ -n "$USE_CUSTOM_REPOSITORY" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check
|
||||
# If USE_LOCAL_COMPONENT is true, then use local components
|
||||
if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
|
||||
|
||||
echo ' ===> Using local components for Freeleaps services.'
|
||||
@ -951,7 +1032,7 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Echo OWNER_GROUP
|
||||
# Echo OWNER_GROUP
|
||||
echo "OWNER_GROUP: $OWNER_GROUP"
|
||||
|
||||
# Copy gitea data to the gitea container
|
||||
@ -991,9 +1072,6 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
|
||||
echo "===> start Gitea, MongoDB, RabbitMQ and other components containers"
|
||||
docker-compose -f docker-compose.dev.arm64.new.yaml up -d mongodb rabbitmq gitea redis "${start_components[@]}"
|
||||
|
||||
echo "===> start components is $start_components"
|
||||
|
||||
|
||||
gitea_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-gitea$" --format "{{.ID}}")
|
||||
echo "$gitea_container_id" > "$WORKING_HOME/.gitea-instance"
|
||||
|
||||
@ -1047,8 +1125,6 @@ else
|
||||
echo "$redis_container_id" > "$WORKING_HOME/.redis-instance"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# Save $USE_LOCAL_COMPONENT false/true to $WORKING_HOME/.use-local-component
|
||||
echo "$USE_LOCAL_COMPONENT" > "$WORKING_HOME/.use-local-component"
|
||||
|
||||
@ -2262,7 +2338,7 @@ parse_requirements() {
|
||||
# :command.command_filter
|
||||
action=${1:-}
|
||||
|
||||
case $action in
|
||||
case "$action" in
|
||||
-*) ;;
|
||||
|
||||
init | i)
|
||||
@ -2307,15 +2383,21 @@ parse_requirements() {
|
||||
shift $#
|
||||
;;
|
||||
|
||||
# :command.command_fallback
|
||||
"")
|
||||
devbox_usage >&2
|
||||
exit 1
|
||||
devbox_init_guidance >&2
|
||||
action="init"
|
||||
shift
|
||||
devbox_init_parse_requirements "$@"
|
||||
shift $#
|
||||
;;
|
||||
|
||||
*)
|
||||
printf "invalid command: %s\n" "$action" >&2
|
||||
exit 1
|
||||
# pass * parameter to devbox_init_guidance
|
||||
devbox_init_guidance $action >&2
|
||||
|
||||
action="init"
|
||||
shift
|
||||
devbox_init_parse_requirements "$@"
|
||||
shift $#
|
||||
;;
|
||||
|
||||
esac
|
||||
@ -2335,7 +2417,6 @@ parse_requirements() {
|
||||
# :command.parse_requirements_case_simple
|
||||
printf "invalid argument: %s\n" "$key" >&2
|
||||
exit 1
|
||||
|
||||
;;
|
||||
|
||||
esac
|
||||
@ -3041,8 +3122,6 @@ devbox_restart_parse_requirements() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
initialize() {
|
||||
version="1.0.0"
|
||||
long_usage=""
|
||||
@ -3073,6 +3152,7 @@ run() {
|
||||
"status") devbox_status_command ;;
|
||||
"restart") devbox_restart_command ;;
|
||||
esac
|
||||
|
||||
}
|
||||
initialize
|
||||
run "$@"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user