forked from freeleaps/freeleaps-pub
Update for all checkout file reset when init. stop/start, restart
This commit is contained in:
parent
37d4997bfb
commit
3d483a3b99
@ -49,6 +49,7 @@ get_arg() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
# :command.usage
|
||||
devbox_usage() {
|
||||
printf "Command\n"
|
||||
@ -82,34 +83,16 @@ devbox_init_usage() {
|
||||
printf " --working-home -w [Optional] : Specifies the working home of DevBox CLI. Default: %s/devbox\n" "$HOME"
|
||||
printf " --devbox-container-name -n [Optional] : Specifies the DevBox container name. Default: devbox.\n"
|
||||
printf " --devbox-container-port -p [Optional] : Specifies the container port for DevBox SSH access. Default: 22222.\n"
|
||||
printf " --devbox-image-repo -R [Optional] : Specifies the DevBox container image repository. Default: docker.io/freeleaps.\n"
|
||||
printf " --devbox-image-name -I [Optional] : Specifies the DevBox container image name. Default: devbox.\n"
|
||||
printf " --devbox-image-tag -T [Optional] : Specifies the DevBox container image tag. Default: latest.\n"
|
||||
printf " --devbox-image-repo -r [Optional] : Specifies the DevBox container image repository. Default: docker.io/freeleaps.\n"
|
||||
printf " --devbox-image-name -i [Optional] : Specifies the DevBox container image name. Default: devbox.\n"
|
||||
printf " --devbox-image-tag -t [Optional] : Specifies the DevBox container image tag. Default: latest.\n"
|
||||
printf " --devbox-frontend-port -F [Optional] : Specifies the container port for DevBox frontend access. Default: 5173.\n"
|
||||
printf " --devbox-backend-port -B [Optional] : Specifies the container port for DevBox backend access. Default: 8002.\n"
|
||||
printf " --freeleaps-username -U [Optional] : Specifies the Freeleaps.com repository username.\n"
|
||||
printf " --freeleaps-password -X [Optional] : Specifies the Freeleaps.com repository password.\n"
|
||||
printf " --use-local-component -u [Optional] : Check if using local component or online dev environment. Default: false.\n"
|
||||
printf " --devsvc-image-repo -D [Optional] : Specifies the repository for devsvc component.\n"
|
||||
printf " --devsvc-image-name -M [Optional] : Specifies the image name for devsvc component.\n"
|
||||
printf " --devsvc-image-tag -G [Optional] : Specifies the image tag for devsvc component. Default: latest.\n"
|
||||
printf " --notification-image-repo -Y [Optional] : Specifies the repository for notification component.\n"
|
||||
printf " --notification-image-name -K [Optional] : Specifies the image name for notification component.\n"
|
||||
printf " --notification-image-tag -Z [Optional] : Specifies the image tag for notification component. Default: latest.\n"
|
||||
printf " --content-image-repo -C [Optional] : Specifies the repository for content component.\n"
|
||||
printf " --content-image-name -E [Optional] : Specifies the image name for content component.\n"
|
||||
printf " --content-image-tag -H [Optional] : Specifies the image tag for content component. Default: latest.\n"
|
||||
printf " --central_storage-image-repo -S [Optional] : Specifies the repository for central_storage component.\n"
|
||||
printf " --central_storage-image-name -J [Optional] : Specifies the image name for central_storage component.\n"
|
||||
printf " --central_storage-image-tag -Q [Optional] : Specifies the image tag for central_storage component. Default: latest.\n"
|
||||
printf " --authentication-image-repo -V [Optional] : Specifies the repository for authentication component.\n"
|
||||
printf " --authentication-image-name -L [Optional] : Specifies the image name for authentication component.\n"
|
||||
printf " --authentication-image-tag -W [Optional] : Specifies the image tag for authentication component. Default: latest.\n"
|
||||
printf " --use-custom-repository -C [Optional] : Specifies the custom git repository for source code.\n"
|
||||
printf " --chat-image-repo -M [Optional] : Specifies the repository for chat component.\n"
|
||||
printf " --chat-image-name -N [Optional] : Specifies the image name for chat component.\n"
|
||||
printf " --chat-image-tag -O [Optional] : Specifies the image tag for chat component. Default: latest.\n"
|
||||
|
||||
printf " --devbox-backend-port -b [Optional] : Specifies the container port for DevBox backend access. Default: 8002.\n"
|
||||
printf " --freeleaps-username -u [Optional] : Specifies the Freeleaps.com repository username.\n"
|
||||
printf " --freeleaps-password -x [Optional] : Specifies the Freeleaps.com repository password.\n"
|
||||
printf " --use-local-component -l [Optional] : Check if using local component or online dev environment. Default: false.\n"
|
||||
printf " --use-custom-repository -c [Optional] : Specifies the custom git repository for source code.\n"
|
||||
printf " --freeleaps-components -m [Optional] : Specifies the Freeleaps.com components to start in the DevBox container.\n"
|
||||
printf " --force -f [Optional] : Force initialization even if resources already exist.\n\n"
|
||||
|
||||
printf "Global Arguments\n"
|
||||
@ -457,6 +440,31 @@ check_docker_running() {
|
||||
return 1
|
||||
}
|
||||
|
||||
build_local_image() {
|
||||
local dockerfile_path="$1"
|
||||
echo "==> [Build] use Dockerfile: $(grep '^FROM' "$dockerfile_path")"
|
||||
|
||||
# Check if the image already exists
|
||||
docker rmi -f $devbox_full_image 2>/dev/null || true
|
||||
|
||||
# Build the image
|
||||
if ! docker buildx build \
|
||||
--platform linux/amd64 \
|
||||
--build-arg BUILDARCH="x86-64-v3" \
|
||||
--no-cache \
|
||||
-t $devbox_full_image \
|
||||
-f "$dockerfile_path" . 2>&1 | tee "$WORKING_HOME/build.log"; then
|
||||
echo "ERROR: Image build failed: $WORKING_HOME/build.log"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the image is built successfully
|
||||
if ! docker inspect $devbox_full_image | grep -q 'amd64'; then
|
||||
echo "ERROR:"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Define the local components and their corresponding ports
|
||||
local_components_ports_keys=("devsvc" "notification" "content" "central_storage" "chat" "authentication")
|
||||
|
||||
@ -481,6 +489,18 @@ get_port() {
|
||||
echo "$port"
|
||||
}
|
||||
|
||||
# Build the local image
|
||||
build_local_image() {
|
||||
local dockerfile_path="$1"
|
||||
echo "==> [BUILD] Building local image..."
|
||||
docker buildx build \
|
||||
--platform linux/amd64 \
|
||||
--build-arg BUILDARCH="x86-64-v3" \
|
||||
-t $devbox_full_image \
|
||||
-f "$dockerfile_path" .
|
||||
}
|
||||
|
||||
|
||||
# :command.command_functions
|
||||
# :command.function
|
||||
devbox_init_command() {
|
||||
@ -508,30 +528,7 @@ devbox_init_command() {
|
||||
|
||||
local USE_LOCAL_COMPONENT="$args_use_local_component" # --use-local-component
|
||||
|
||||
local DEVSVC_REPO="$args_devsvc_image_repo" # --devsvc-image-repo
|
||||
local DEVSVC_IMAGE="$args_devsvc_image_image" # --devsvc-image-image
|
||||
local DEVSVC_TAG="$args_devsvc_image_tag" # --devsvc-image-tag
|
||||
|
||||
|
||||
local CONTENT_REPO="$args_content_image_repo" # --content-image-repo
|
||||
local CONTENT_IMAGE="$args_content_image_image" # --content-image-image
|
||||
local CONTENT_TAG="$args_content_image_tag" # --content-image-tag
|
||||
|
||||
local CENTRAL_STORAGE_REPO="$args_central_storage_image_repo" # --central_storage-image-repo
|
||||
local CENTRAL_STORAGE_IMAGE="$args_central_storage_image_image" # --central_storage-image-image
|
||||
local CENTRAL_STORAGE_TAG="$args_central_storage_image_tag" # --central_storage-image-tag
|
||||
|
||||
local AUTHENTICATION_REPO="$args_authentication_image_repo" # --authentication-image-repo
|
||||
local AUTHENTICATION_IMAGE="$args_authentication_image_image" # --authentication-image-image
|
||||
local AUTHENTICATION_TAG="$args_authentication_image_tag" # --authentication-image-tag
|
||||
|
||||
local NOTIFICATION_REPO="$args_notification_image_repo" # --notification-image-repo
|
||||
local NOTIFICATION_IMAGE="$args_notification_image_image" # --notification-image-image
|
||||
local NOTIFICATION_TAG="$args_notification_image_tag" # --notification-image-tag
|
||||
|
||||
local CHAT_REPO="$args_chat_image_repo" # --chat-image-repo
|
||||
local CHAT_IMAGE="$args_chat_image_image" # --chat-image-image
|
||||
local CHAT_TAG="$args_chat_image_tag" # --chat-image-tag
|
||||
local FREELEAPS_COMPONENTS="$args_freeleaps_components" # --freeleaps-components
|
||||
|
||||
local USE_CUSTOM_REPOSITORY="$args_use_custom_repository" # --use-custom-repository
|
||||
|
||||
@ -551,24 +548,8 @@ devbox_init_command() {
|
||||
local FREELEAPS_USERNAME="$(get_arg '--freeleaps-username')"
|
||||
local FREELEAPS_PASSWORD="$(get_arg '--freeleaps-password')"
|
||||
local USE_LOCAL_COMPONENT="$(get_arg '--use-local-component')"
|
||||
local DEVSVC_REPO="$(get_arg '--devsvc-image-repo')"
|
||||
local DEVSVC_IMAGE="$(get_arg '--devsvc-image-name')"
|
||||
local DEVSVC_TAG="$(get_arg '--devsvc-image-tag')"
|
||||
local CONTENT_REPO="$(get_arg '--content-image-repo')"
|
||||
local CONTENT_IMAGE="$(get_arg '--content-image-name')"
|
||||
local CONTENT_TAG="$(get_arg '--content-image-tag')"
|
||||
local CENTRAL_STORAGE_REPO="$(get_arg '--central_storage-image-repo')"
|
||||
local CENTRAL_STORAGE_IMAGE="$(get_arg '--central_storage-image-name')"
|
||||
local CENTRAL_STORAGE_TAG="$(get_arg '--central_storage-image-tag')"
|
||||
local AUTHENTICATION_REPO="$(get_arg '--authentication-image-repo')"
|
||||
local AUTHENTICATION_IMAGE="$(get_arg '--authentication-image-name')"
|
||||
local AUTHENTICATION_TAG="$(get_arg '--authentication-image-tag')"
|
||||
local NOTIFICATION_REPO="$(get_arg '--notification-image-repo')"
|
||||
local NOTIFICATION_IMAGE="$(get_arg '--notification-image-name')"
|
||||
local NOTIFICATION_TAG="$(get_arg '--notification-image-tag')"
|
||||
local CHAT_REPO="$(get_arg '--chat-image-repo')"
|
||||
local CHAT_IMAGE="$(get_arg '--chat-image-name')"
|
||||
local CHAT_TAG="$(get_arg '--chat-image-tag')"
|
||||
|
||||
local FREELEAPS_COMPONENTS="$(get_arg '--freeleaps-components')"
|
||||
local USE_CUSTOM_REPOSITORY="$(get_arg '--use-custom-repository')"
|
||||
|
||||
local FORCE_INIT="$(get_arg '--force')"
|
||||
@ -588,57 +569,48 @@ devbox_init_command() {
|
||||
is_pull_all_components=false
|
||||
fi
|
||||
|
||||
echo "==> Checking parameters..."
|
||||
for component in "${components[@]}"; do
|
||||
if [[ -n "$(get_arg "--${component}-image-repo")" ]]; then
|
||||
is_pull_all_components=false
|
||||
start_components+=("${component}")
|
||||
# split FREELEAPS_COMPONENTS
|
||||
freeleaps_components=()
|
||||
if [[ -n "$FREELEAPS_COMPONENTS" ]]; then
|
||||
freeleaps_components=($(echo "$FREELEAPS_COMPONENTS" | tr ',' ' '))
|
||||
fi
|
||||
|
||||
# Check ARCH match default component tag value and justify the default Image tag value
|
||||
if [[ "$ARCH" == "amd64" && "$component" == "devsvc" ]]; then
|
||||
DEVSVC_TAG="latest-linux-amd64"
|
||||
elif [[ "$ARCH" == "arm64" && "$component" == "devsvc" ]]; then
|
||||
DEVSVC_TAG="latest-linux-arm64"
|
||||
# Check if freeleaps_components is not empty, then check if freeleaps_components is valid component
|
||||
if [ ${#freeleaps_components[@]} -gt 0 ]; then
|
||||
for component in "${freeleaps_components[@]}"; do
|
||||
found=false
|
||||
for valid_component in "${components[@]}"; do
|
||||
if [ "$component" = "$valid_component" ]; then
|
||||
found=true
|
||||
break
|
||||
fi
|
||||
|
||||
if [[ "$ARCH" == "amd64" && "$component" == "content" ]]; then
|
||||
CONTENT_TAG="latest-linux-amd64"
|
||||
elif [[ "$ARCH" == "arm64" && "$component" == "content" ]]; then
|
||||
CONTENT_TAG="latest-linux-arm64"
|
||||
fi
|
||||
|
||||
if [[ "$ARCH" == "amd64" && "$component" == "central_storage" ]]; then
|
||||
CENTRAL_STORAGE_TAG="latest-linux-amd64"
|
||||
elif [[ "$ARCH" == "arm64" && "$component" == "central_storage" ]]; then
|
||||
CENTRAL_STORAGE_TAG="latest-linux-arm64"
|
||||
fi
|
||||
|
||||
if [[ "$ARCH" == "amd64" && "$component" == "authentication" ]]; then
|
||||
AUTHENTICATION_TAG="latest-linux-amd64"
|
||||
elif [[ "$ARCH" == "arm64" && "$component" == "authentication" ]]; then
|
||||
AUTHENTICATION_TAG="latest-linux-arm64"
|
||||
fi
|
||||
|
||||
if [[ "$ARCH" == "amd64" && "$component" == "notification" ]]; then
|
||||
NOTIFICATION_TAG="latest-linux-amd64"
|
||||
elif [[ "$ARCH" == "arm64" && "$component" == "notification" ]]; then
|
||||
NOTIFICATION_TAG="latest-linux-arm64"
|
||||
fi
|
||||
|
||||
if [[ "$ARCH" == "amd64" && "$component" == "chat" ]]; then
|
||||
CHAT_TAG="latest-linux-amd64"
|
||||
elif [[ "$ARCH" == "arm64" && "$component" == "chat" ]]; then
|
||||
CHAT_TAG="latest-linux-arm64"
|
||||
done
|
||||
if [ "$found" = false ]; then
|
||||
echo "ERROR: Invalid component: $component"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
start_components=("${freeleaps_components[@]}")
|
||||
else
|
||||
start_components=("${components[@]}")
|
||||
fi
|
||||
|
||||
component_tag="latest-linux-arm64"
|
||||
if [[ "$ARCH" == "amd64" ]]; then
|
||||
component_tag="latest-linux-amd64"
|
||||
fi
|
||||
|
||||
# If is_pull_all_components is true, then pull all components
|
||||
if [[ "$is_pull_all_components" == true ]]; then
|
||||
start_components=("${components[@]}")
|
||||
echo "==> Pulling all components..."
|
||||
echo "==> start components: ${start_components[@]}"
|
||||
fi
|
||||
|
||||
# Remove duplicated components
|
||||
start_components=($(echo "${start_components[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
|
||||
|
||||
echo " ===================================================== "
|
||||
echo "Parameters:"
|
||||
echo " OS = $OS"
|
||||
@ -654,24 +626,7 @@ devbox_init_command() {
|
||||
echo " FREELEAPS_USERNAME= $FREELEAPS_USERNAME"
|
||||
echo " (FREELEAPS_PASSWORD is hidden for security)"
|
||||
echo " USE_LOCAL_COMPONENT= $USE_LOCAL_COMPONENT"
|
||||
echo " DEVSVC_REPO = $DEVSVC_REPO"
|
||||
echo " DEVSVC_IMAGE = $DEVSVC_IMAGE"
|
||||
echo " DEVSVC_TAG = $DEVSVC_TAG"
|
||||
echo " CONTENT_REPO = $CONTENT_REPO"
|
||||
echo " CONTENT_IMAGE = $CONTENT_IMAGE"
|
||||
echo " CONTENT_TAG = $CONTENT_TAG"
|
||||
echo " CENTRAL_STORAGE_REPO = $CENTRAL_STORAGE_REPO"
|
||||
echo " CENTRAL_STORAGE_IMAGE= $CENTRAL_STORAGE_IMAGE"
|
||||
echo " CENTRAL_STORAGE_TAG = $CENTRAL_STORAGE_TAG"
|
||||
echo " AUTHENTICATION_REPO = $AUTHENTICATION_REPO"
|
||||
echo " AUTHENTICATION_IMAGE= $AUTHENTICATION_IMAGE"
|
||||
echo " AUTHENTICATION_TAG = $AUTHENTICATION_TAG"
|
||||
echo " NOTIFICATION_REPO = $NOTIFICATION_REPO"
|
||||
echo " NOTIFICATION_IMAGE= $NOTIFICATION_IMAGE"
|
||||
echo " NOTIFICATION_TAG = $NOTIFICATION_TAG"
|
||||
echo " CHAT_REPO = $CHAT_REPO"
|
||||
echo " CHAT_IMAGE = $CHAT_IMAGE"
|
||||
echo " CHAT_TAG = $CHAT_TAG"
|
||||
echo " FREELEAPS_COMPONENTS= ${start_components[@]}"
|
||||
echo " FORCE_INIT = $FORCE_INIT"
|
||||
echo
|
||||
|
||||
@ -690,15 +645,20 @@ devbox_init_command() {
|
||||
fi
|
||||
|
||||
# Check ARCH match current device
|
||||
ARCH_MICRO=""
|
||||
if [[ "$ARCH" == "auto" ]]; then
|
||||
ARCH="$(uname -m)"
|
||||
if [[ "$ARCH" == "x86_64" ]]; then
|
||||
# Check if the CPU supports AVX2
|
||||
if grep -q avx2 /proc/cpuinfo; then
|
||||
ARCH="amd64"
|
||||
ARCH_MICRO="v3"
|
||||
echo "==> Detected AMD64 architecture."
|
||||
else
|
||||
ARCH="amd64"
|
||||
fi
|
||||
elif [[ "$ARCH" == "aarch64" ]]; then
|
||||
ARCH="arm64"
|
||||
else
|
||||
echo "ERROR: Unsupported architecture: $ARCH"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -752,6 +712,7 @@ devbox_init_command() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 3.5 Check if the user has permission to write to WORKING_HOME
|
||||
if [[ -f "$WORKING_HOME/.devbox-instance" && -z "$FORCE_INIT" ]]; then
|
||||
# Echo all start_components
|
||||
if [[ "${#start_components[@]}" -gt 0 ]]; then
|
||||
@ -768,9 +729,7 @@ devbox_init_command() {
|
||||
fi
|
||||
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# 5.1 pull and start DevBox container
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
local devbox_full_image="${DEVBOX_REPO}/${DEVBOX_IMAGE}:${DEVBOX_TAG}"
|
||||
|
||||
# Check local and remote version. User doesn’t need to rebuild devbox if local version is consistent with remote version
|
||||
@ -970,12 +929,12 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
|
||||
|
||||
echo ' ===> Using local components for Freeleaps services.'
|
||||
|
||||
export DEVSVC_IMAGE_TAG="$DEVSVC_TAG"
|
||||
export CONTENT_IMAGE_TAG="$CONTENT_TAG"
|
||||
export CENTRAL_STORAGE_IMAGE_TAG="$CENTRAL_STORAGE_TAG"
|
||||
export AUTHENTICATION_IMAGE_TAG="$AUTHENTICATION_TAG"
|
||||
export NOTIFICATION_IMAGE_TAG="$NOTIFICATION_TAG"
|
||||
export CHAT_IMAGE_TAG="$CHAT_TAG"
|
||||
export DEVSVC_IMAGE_TAG="$component_tag"
|
||||
export CONTENT_IMAGE_TAG="$component_tag"
|
||||
export CENTRAL_STORAGE_IMAGE_TAG="$component_tag"
|
||||
export AUTHENTICATION_IMAGE_TAG="$component_tag"
|
||||
export NOTIFICATION_IMAGE_TAG="$component_tag"
|
||||
export CHAT_IMAGE_TAG="$component_tag"
|
||||
|
||||
# Check if gitea_data_backup.tar.gz exists at current script directory, if not exit
|
||||
if [[ ! -f "gitea_data_backup.tar.gz" ]]; then
|
||||
@ -1032,6 +991,9 @@ 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"
|
||||
|
||||
@ -1060,13 +1022,19 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
|
||||
OWNER_GROUP=$(stat -c "%U:%G" "${WORKING_HOME}")
|
||||
fi
|
||||
|
||||
# Check all components are started
|
||||
for component in "${start_components[@]}"; do
|
||||
if [[ -z "$(docker ps -a --format '{{.Names}}' | grep "^$component\$")" ]]; then
|
||||
echo "ERROR: Failed to start $component container."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo '============================================'
|
||||
echo ' ===> Using online components for Freeleaps services.'
|
||||
echo '============================================'
|
||||
# Start Gitea, MongoDB, RabbitMQ containers
|
||||
docker-compose -f docker-compose.dev.arm64.new.yaml up -d mongodb rabbitmq redis
|
||||
echo "===> start components is $start_components"
|
||||
|
||||
# Save MongoDB and RabbitMQ container ids to .mongodb-instance and .rabbitmq-instance
|
||||
mongo_container_id=$(docker ps -a --format '{{.Names}}' | grep "^freeleaps2-mongodb\$")
|
||||
@ -1079,13 +1047,6 @@ else
|
||||
echo "$redis_container_id" > "$WORKING_HOME/.redis-instance"
|
||||
fi
|
||||
|
||||
# Check all components are started
|
||||
for component in "${start_components[@]}"; do
|
||||
if [[ -z "$(docker ps -a --format '{{.Names}}' | grep "^$component\$")" ]]; then
|
||||
echo "ERROR: Failed to start $component container."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# Save $USE_LOCAL_COMPONENT false/true to $WORKING_HOME/.use-local-component
|
||||
@ -1285,6 +1246,10 @@ if [ \$ATTEMPT -eq \$MAX_ATTEMPTS ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf /home/devbox/freeleaps/apps/backend_env.sh || true
|
||||
|
||||
echo "WebAPI service started successfully"
|
||||
|
||||
|
||||
echo '============================================'
|
||||
echo ' Start frontend service locally'
|
||||
@ -1330,7 +1295,6 @@ FRONTEND_PID=\$!
|
||||
echo "npm run dev has been started with PID: \$FRONTEND_PID"
|
||||
echo "\$FRONTEND_PID" > /home/devbox/.frontend.pid
|
||||
|
||||
|
||||
echo '============================================'
|
||||
|
||||
# Wait for the frontend service to start
|
||||
@ -1361,6 +1325,11 @@ if [ \$ATTEMPT -eq \$MAX_ATTEMPTS ]; then
|
||||
fi
|
||||
|
||||
|
||||
pushd /home/devbox/freeleaps
|
||||
git config --global --add safe.directory /home/devbox/freeleaps
|
||||
git reset --hard
|
||||
|
||||
|
||||
echo "Freeleaps services started successfully"
|
||||
EOF
|
||||
|
||||
@ -1505,10 +1474,11 @@ devbox_deinit_command() {
|
||||
|
||||
# Remove the working home directory
|
||||
echo "==> Removing working home directory: $WORKING_HOME"
|
||||
if [[ -d "$WORKING_HOME" ]]; then
|
||||
sudo chown -R $(whoami):$(whoami) "$WORKING_HOME"
|
||||
rm -rf "$WORKING_HOME" 2>/dev/null || true
|
||||
rmdir "$WORKING_HOME" 2>/dev/null || true
|
||||
|
||||
fi
|
||||
echo "==> Working home directory removed successfully."
|
||||
else
|
||||
REMOVE_WORKING_HOME=false
|
||||
@ -1648,9 +1618,11 @@ if [[ "$FREELEAPS_ENDPOINT" != "" ]]; then
|
||||
# Check if start backend service
|
||||
if [[ "${START_BACKEND}" == "true" ]]; then
|
||||
# Start the backend service
|
||||
|
||||
echo '============================================'
|
||||
echo ' Start backend service locally'
|
||||
echo '============================================'
|
||||
|
||||
pushd /home/devbox/freeleaps/apps
|
||||
|
||||
# CHeck if the virtual environment is created
|
||||
@ -1718,6 +1690,12 @@ if [[ "${START_FRONTEND}" == "true" ]]; then
|
||||
echo '============================================'
|
||||
pushd /home/devbox/freeleaps/frontend
|
||||
|
||||
# echo "==> Starting frontend service..."
|
||||
baseline_file=\$(mktemp)
|
||||
echo "==> Creating a baseline file for the frontend service..."
|
||||
git status -s > "\$baseline_file"
|
||||
echo "==> Baseline file created: \$baseline_file"
|
||||
|
||||
# Check if the frontend service is already running according to the package.json and pnpm-lock.yaml files timestamps
|
||||
if [[ ! -d "node_modules" || "package.json" -nt "node_modules" || "pnpm-lock.yaml" -nt "node_modules" ]]; then
|
||||
echo "==> Installing/Updating frontend dependencies..."
|
||||
@ -1726,7 +1704,7 @@ if [[ "${START_FRONTEND}" == "true" ]]; then
|
||||
rm -rf node_modules
|
||||
|
||||
# Install dependencies
|
||||
pnpm install --prefer-offline --frozen-lockfile || {
|
||||
pnpm install --prefer-offline || {
|
||||
echo "ERROR: Failed to install dependencies"
|
||||
exit 1
|
||||
}
|
||||
@ -1771,7 +1749,25 @@ if [[ "${START_FRONTEND}" == "true" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
current_file=\$(mktemp)
|
||||
git status -s > "\$current_file"
|
||||
|
||||
echo "==> Checking for modified files in the frontend service..."
|
||||
while read -r line; do
|
||||
# Print the file name
|
||||
echo "\$line"
|
||||
file=\$(echo "\$line" | awk '{print \$2}')
|
||||
echo "File: \$file"
|
||||
# Check if the file is not in the baseline file
|
||||
if ! grep -q "[[:space:]]\$file\$" "\$baseline_file"; then
|
||||
echo "==> File \$file has been modified. Resetting..."
|
||||
git reset HEAD "\$file"
|
||||
git checkout -- "\$file"
|
||||
fi
|
||||
done < \$current_file
|
||||
|
||||
# Remove the temporary files
|
||||
rm "\$baseline_file" "\$current_file"
|
||||
fi
|
||||
|
||||
echo "Freeleaps services started successfully"
|
||||
@ -1782,9 +1778,6 @@ EOF
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
echo "==> DevBox services started successfully."
|
||||
}
|
||||
|
||||
@ -2069,8 +2062,6 @@ if [[ "$FREELEAPS_ENDPOINT" != "" ]]; then
|
||||
docker exec -i "$devbox_container_id" bash <<EOF
|
||||
|
||||
if [[ "${START_BACKEND}" == "true" ]]; then
|
||||
echo "Starting backend services..."
|
||||
|
||||
# Start the backend service
|
||||
|
||||
echo '============================================'
|
||||
@ -2115,11 +2106,9 @@ if [[ "${START_BACKEND}" == "true" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test backend and frontend services
|
||||
echo "Testing backend and frontend services..."
|
||||
|
||||
# Test the backend service
|
||||
echo "Testing backend service..."
|
||||
|
||||
attempt=0
|
||||
max_attempts=10
|
||||
while [ \$attempt -lt \$max_attempts ]; do
|
||||
@ -2136,17 +2125,37 @@ if [[ "${START_BACKEND}" == "true" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Backend service is available (HTTP \$http_code)"
|
||||
fi
|
||||
|
||||
|
||||
if [[ "${START_FRONTEND}" == "true" ]]; then
|
||||
# Start the frontend service
|
||||
if [[ "${START_FRONTEND}" == "true" ]]; then
|
||||
|
||||
echo '============================================'
|
||||
echo ' Start frontend service locally'
|
||||
echo '============================================'
|
||||
pushd /home/devbox/freeleaps/frontend
|
||||
|
||||
# echo "==> Starting frontend service..."
|
||||
baseline_file=\$(mktemp)
|
||||
echo "==> Creating a baseline file for the frontend service..."
|
||||
git status -s > "\$baseline_file"
|
||||
echo "==> Baseline file created: \$baseline_file"
|
||||
|
||||
# Check if the frontend service is already running according to the package.json and pnpm-lock.yaml files timestamps
|
||||
if [[ ! -d "node_modules" || "package.json" -nt "node_modules" || "pnpm-lock.yaml" -nt "node_modules" ]]; then
|
||||
echo "==> Installing/Updating frontend dependencies..."
|
||||
|
||||
# Clean up old dependencies
|
||||
rm -rf node_modules
|
||||
|
||||
# Install dependencies
|
||||
pnpm install --prefer-offline || {
|
||||
echo "ERROR: Failed to install dependencies"
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
|
||||
npm run dev > /home/devbox/logs/frontend.logs 2>&1 &
|
||||
FRONTEND_PID=\$!
|
||||
|
||||
@ -2163,21 +2172,7 @@ if [[ "${START_FRONTEND}" == "true" ]]; then
|
||||
# Test the frontend service
|
||||
WEB_APP_ACCESS_PORT=\$(cat /home/devbox/.devbox-frontend-port)
|
||||
|
||||
# Check if the frontend service is already running according to the package.json and pnpm-lock.yaml files timestamps
|
||||
if [[ ! -d "node_modules" || "package.json" -nt "node_modules" || "pnpm-lock.yaml" -nt "node_modules" ]]; then
|
||||
echo "==> Installing/Updating frontend dependencies..."
|
||||
|
||||
# Clean up old dependencies
|
||||
rm -rf node_modules
|
||||
|
||||
# Install dependencies
|
||||
pnpm install --prefer-offline --frozen-lockfile || {
|
||||
echo "ERROR: Failed to install dependencies"
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
|
||||
echo "Testing frontend service..."
|
||||
echo "Testing frontend service... PORT: \$WEB_APP_ACCESS_PORT"
|
||||
attempt=0
|
||||
max_attempts=10
|
||||
while [ \$attempt -lt \$max_attempts ]; do
|
||||
@ -2196,6 +2191,26 @@ if [[ "${START_FRONTEND}" == "true" ]]; then
|
||||
echo "ERROR: Frontend service is not available after \$max_attempts attempts."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
current_file=\$(mktemp)
|
||||
git status -s > "\$current_file"
|
||||
|
||||
echo "==> Checking for modified files in the frontend service..."
|
||||
while read -r line; do
|
||||
# Print the file name
|
||||
echo "\$line"
|
||||
file=\$(echo "\$line" | awk '{print \$2}')
|
||||
echo "File: \$file"
|
||||
# Check if the file is not in the baseline file
|
||||
if ! grep -q "[[:space:]]\$file\$" "\$baseline_file"; then
|
||||
echo "==> File \$file has been modified. Resetting..."
|
||||
git reset HEAD "\$file"
|
||||
git checkout -- "\$file"
|
||||
fi
|
||||
done < \$current_file
|
||||
|
||||
# Remove the temporary files
|
||||
rm "\$baseline_file" "\$current_file"
|
||||
fi
|
||||
|
||||
echo "Freeleaps services started successfully"
|
||||
@ -2367,7 +2382,7 @@ devbox_init_parse_requirements() {
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--devbox-container-name | -N)
|
||||
--devbox-container-name | -n)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--devbox-container-name' "$2"
|
||||
@ -2378,7 +2393,7 @@ devbox_init_parse_requirements() {
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--devbox-container-port | -P)
|
||||
--devbox-container-port | -p)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--devbox-container-port' "$2"
|
||||
@ -2388,7 +2403,7 @@ devbox_init_parse_requirements() {
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
--devbox-frontend-port | -F)
|
||||
--devbox-frontend-port | -f)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--devbox-frontend-port' "$2"
|
||||
@ -2398,7 +2413,7 @@ devbox_init_parse_requirements() {
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
--devbox-backend-port | -B)
|
||||
--devbox-backend-port | -b)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--devbox-backend-port' "$2"
|
||||
@ -2409,7 +2424,7 @@ devbox_init_parse_requirements() {
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--devbox-image-repo | -D)
|
||||
--devbox-image-repo | -r)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--devbox-image-repo' "$2"
|
||||
@ -2420,7 +2435,7 @@ devbox_init_parse_requirements() {
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--devbox-image-name | -I)
|
||||
--devbox-image-name | -i)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--devbox-image-name' "$2"
|
||||
@ -2431,7 +2446,7 @@ devbox_init_parse_requirements() {
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--devbox-image-tag | -g)
|
||||
--devbox-image-tag | -t)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--devbox-image-tag' "$2"
|
||||
@ -2453,7 +2468,7 @@ devbox_init_parse_requirements() {
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--freeleaps-username | -U)
|
||||
--freeleaps-username | -u)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--freeleaps-username' "$2"
|
||||
@ -2464,7 +2479,7 @@ devbox_init_parse_requirements() {
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--freeleaps-password | -X)
|
||||
--freeleaps-password | -x)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--freeleaps-password' "$2"
|
||||
@ -2484,7 +2499,7 @@ devbox_init_parse_requirements() {
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--use-local-component | -u)
|
||||
--use-local-component | -l)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--use-local-component' "$2"
|
||||
shift 2
|
||||
@ -2493,187 +2508,12 @@ devbox_init_parse_requirements() {
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--devsvc-image-repo | -t)
|
||||
# :flag.case_arg
|
||||
--freeleaps-components | -m)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--devsvc-image-repo' "$2"
|
||||
add_arg '--freeleaps-components' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--devsvc-image-repo requires an argument: --devsvc-image-repo DEVSVC_IMAGE_REPO" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--devsvc-image-name | -M)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--devsvc-image-name' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--devsvc-image-name requires an argument: --devsvc-image-name DEVSVC_IMAGE_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--devsvc-image-tag | -G)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--devsvc-image-tag' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--devsvc-image-tag requires an argument: --devsvc-image-tag DEVSVC_IMAGE_TAG" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--notification-image-repo | -Y)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--notification-image-repo' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--notification-image-repo requires an argument: --notification-image-repo NOTIFICATION_IMAGE_REPO" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
--notification-image-name | -K)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--notification-image-name' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--notification-image-name requires an argument: --notification-image-name NOTIFICATION_IMAGE_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
--notification-image-tag | -Z)
|
||||
# :flag.case_arg
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--notification-image-tag' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--notification-image-tag requires an argument: --notification-image-tag NOTIFICATION_IMAGE_TAG" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--content-image-repo | -C)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--content-image-repo' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--content-image-repo requires an argument: --content-image-repo FREELEAPS_CONTENT_IMAGE_REPO" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--content-image-name | -E)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--content-image-name' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--content-image-name requires an argument: --content-image-name FREELEAPS_CONTENT_IMAGE_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--content-image-tag | -H)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--content-image-tag' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--content-image-tag requires an argument: --content-image-tag FREELEAPS_CONTENT_IMAGE_TAG" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--central_storage-image-repo | -S)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--central_storage-image-repo' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--central_storage-image-repo requires an argument: --central_storage-image-repo FREELEAPS_CENTRAL_STORAGE_IMAGE_REPO" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--central_storage-image-name | -J)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--central_storage-image-name' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--central_storage-image-name requires an argument: --central_storage-image-name FREELEAPS_CENTRAL_STORAGE_IMAGE_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--central_storage-image-tag | -Q)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--central_storage-image-tag' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--central_storage-image-tag requires an argument: --central_storage-image-tag FREELEAPS_CENTRAL_STORAGE_IMAGE_TAG" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--authentication-image-repo | -V)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--authentication-image-repo' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--authentication-image-repo requires an argument: --authentication-image-repo FREELEAPS_AUTHENTICATION_IMAGE_REPO" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--authentication-image-name | -L)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--authentication-image-name' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--authentication-image-name requires an argument: --authentication-image-name FREELEAPS_AUTHENTICATION_IMAGE_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--authentication-image-tag | -W)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--authentication-image-tag' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--authentication-image-tag requires an argument: --authentication-image-tag FREELEAPS_AUTHENTICATION_IMAGE_TAG" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--chat-image-repo | -R)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--chat-image-repo' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--chat-image-repo requires an argument: --chat-image-repo FREELEAPS_CHAT_IMAGE_REPO" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--chat-image-name | -N)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--chat-image-name' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--chat-image-name requires an argument: --chat-image-name FREELEAPS_CHAT_IMAGE_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
# :flag.case
|
||||
--chat-image-tag | -T)
|
||||
if [[ -n ${2+x} ]]; then
|
||||
add_arg '--chat-image-tag' "$2"
|
||||
shift 2
|
||||
else
|
||||
printf "%s\n" "--chat-image-tag requires an argument: --chat-image-tag FREELEAPS_CHAT_IMAGE_TAG" >&2
|
||||
printf "%s\n" "--freeleaps-components requires an argument: --freeleaps-components FREELEAPS_COMPONENTS" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user