Update for change to use docker compose

This commit is contained in:
Tianyong Qiu 2025-02-11 16:54:13 +08:00
parent 30bfdf1fa2
commit 341b2a5042
2 changed files with 211 additions and 190 deletions

View File

@ -208,19 +208,19 @@ devbox_init_usage() {
printf " %s\n" "Default: latest" printf " %s\n" "Default: latest"
echo echo
# :flag.usage payment image repo # :flag.usage notification, image repo
printf " %s\n" "--payment-image-repo PAYMENT_IMAGE_REPO" printf " %s\n" "--notification-image-repo NOTIFICATION_IMAGE_REPO"
printf " Specifies the repository for payment component. (Optional)\n" printf " Specifies the repository for notification component. (Optional)\n"
echo echo
# :flag.usage payment image name # :flag.usage notification image name
printf " %s\n" "--payment-image-name PAYMENT_IMAGE_NAME" printf " %s\n" "--notification-image-name NOTIFICATION_IMAGE_NAME"
printf " Specifies the image name for payment component. (Optional)\n" printf " Specifies the image name for notification component. (Optional)\n"
echo echo
# :flag.usage payment image tag # :flag.usage notification image tag
printf " %s\n" "--payment-image-tag PAYMENT_IMAGE_TAG" printf " %s\n" "--notification-image-tag NOTIFICATION_IMAGE_TAG"
printf " Specifies the image tag for payment component. (Optional, default=latest)\n" printf " Specifies the image tag for notification component. (Optional, default=latest)\n"
printf " %s\n" "Default: latest" printf " %s\n" "Default: latest"
echo echo
@ -367,7 +367,7 @@ devbox_start_usage() {
# :command.usage_flags # :command.usage_flags
# :flag.usage # :flag.usage
printf " %s\n" "--component COMPONENT" printf " %s\n" "--component COMPONENT"
printf " Specifies the name of the component to start (e.g., mongodb, rabbitmq,\n backend, frontend, devsvc, payment, content, central_storage,\n authentication).\n" printf " Specifies the name of the component to start (e.g., mongodb, rabbitmq,\n backend, frontend, devsvc, content, central_storage,\n authentication).\n"
echo echo
# :command.usage_fixed_flags # :command.usage_fixed_flags
@ -407,7 +407,7 @@ devbox_stop_usage() {
# :command.usage_flags # :command.usage_flags
# :flag.usage # :flag.usage
printf " %s\n" "--component COMPONENT" printf " %s\n" "--component COMPONENT"
printf " Specifies the name of the component to stop (e.g., mongodb, rabbitmq,\n backend, frontend, devsvc, payment, content, central_storage,\n authentication).\n" printf " Specifies the name of the component to stop (e.g., mongodb, rabbitmq,\n backend, frontend, devsvc, content, central_storage,\n authentication).\n"
echo echo
# :command.usage_fixed_flags # :command.usage_fixed_flags
@ -687,9 +687,59 @@ check_docker_running() {
return 1 return 1
} }
start_local_gitea(){
echo "[INFO] Starting Gitea container..."
GITEA_CONTAINER_NAME="freeleaps2-gitea"
GITEA_IMAGE="gitea/gitea:latest"
# If a container with the same name exists, remove it
if docker ps -a --format '{{.Names}}' | grep -q "^${GITEA_CONTAINER_NAME}\$"; then
echo "==> Removing existing Gitea container..."
docker stop "${GITEA_CONTAINER_NAME}" &>/dev/null || true
docker rm "${GITEA_CONTAINER_NAME}" &>/dev/null || true
fi
# Pull the Gitea image
echo "==> Pulling Gitea image: ${GITEA_IMAGE}"
if ! docker pull "${GITEA_IMAGE}"; then
echo "ERROR: Failed to pull Gitea image: ${GITEA_IMAGE}"
exit 1
fi
# Run the Gitea container mapping port 3000
gitea_container_id=$(docker run -d --name "${GITEA_CONTAINER_NAME}" \
-v "${WORKING_HOME}/gitea:/data" \
-e "DISABLE_REGISTRATION=true" \
-e "REQUIRE_SIGNIN_VIEW=true" \
-p 3000:3000 "${GITEA_IMAGE}" )
if [[ -z "${gitea_container_id}" ]]; then
echo "ERROR: Failed to start Gitea container."
exit 1
fi
echo "Gitea container started successfully: ${gitea_container_id}"
# Allow Gitea some time to initialize
sleep 20
# Check Gitea health via curl
if curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 &>/dev/null; then
echo "Gitea health check passed."
else
echo "ERROR: Gitea health check failed."
exit 1
fi
echo "$gitea_container_id" > "$WORKING_HOME/.gitea-instance"
echo "[INFO] Completed Gitea container..."
}
start_local_mongodb() { start_local_mongodb() {
echo "==> Starting MongoDB service..." echo "==> Starting MongoDB service..."
MONGO_CONTAINER_NAME="freeleaps2-mongodb" MONGO_CONTAINER_NAME="freeleaps2-mongodb"
MONGO_IMAGE="mongo:latest" MONGO_IMAGE="mongo:latest"
@ -784,11 +834,11 @@ start_local_rabbitMQ(){
echo "[INFO] Completed RabbitMQ container..." echo "[INFO] Completed RabbitMQ container..."
} }
# 定义键和值数组 # Define the local components and their corresponding ports
local_components_ports_keys=("devsvc" "payment" "content" "central_storage" "authentication") local_components_ports_keys=("devsvc" "notification" "content" "central_storage" "authentication")
local_components_ports_values=("8007" "8006" "8013" "8005" "8004") local_components_ports_values=("8007" "8003" "8013" "8005" "8004")
# 根据组件名查找对应的端口 # Get the port number for a local component
get_port() { get_port() {
local comp="$1" local comp="$1"
local port="" local port=""
@ -822,6 +872,7 @@ devbox_init_command() {
local DEVBOX_IMAGE="$args_devbox_image_name" # --devbox-image-name local DEVBOX_IMAGE="$args_devbox_image_name" # --devbox-image-name
local DEVBOX_TAG="$args_devbox_image_tag" # --devbox-image-tag local DEVBOX_TAG="$args_devbox_image_tag" # --devbox-image-tag
local WORKING_HOME="${args_working_home:-${WORKING_HOME:-${HOME}/.devbox}}" local WORKING_HOME="${args_working_home:-${WORKING_HOME:-${HOME}/.devbox}}"
local FREELEAPS_USERNAME="$args_freeleaps_username" # --freeleaps-username local FREELEAPS_USERNAME="$args_freeleaps_username" # --freeleaps-username
local FREELEAPS_PASSWORD="$args_freeleaps_password" # --freeleaps-password local FREELEAPS_PASSWORD="$args_freeleaps_password" # --freeleaps-password
@ -832,10 +883,7 @@ devbox_init_command() {
local DEVSVC_IMAGE="$args_devsvc_image_image" # --devsvc-image-image local DEVSVC_IMAGE="$args_devsvc_image_image" # --devsvc-image-image
local DEVSVC_TAG="$args_devsvc_image_tag" # --devsvc-image-tag local DEVSVC_TAG="$args_devsvc_image_tag" # --devsvc-image-tag
local PAYMENT_REPO="$args_payment_image_repo" # --payment-image-repo
local PAYMENT_IMAGE="$args_payment_image_image" # --payment-image-image
local PAYMENT_TAG="$args_payment_image_tag" # --payment-image-tag
local CONTENT_REPO="$args_content_image_repo" # --content-image-repo local CONTENT_REPO="$args_content_image_repo" # --content-image-repo
local CONTENT_IMAGE="$args_content_image_image" # --content-image-image local CONTENT_IMAGE="$args_content_image_image" # --content-image-image
local CONTENT_TAG="$args_content_image_tag" # --content-image-tag local CONTENT_TAG="$args_content_image_tag" # --content-image-tag
@ -848,6 +896,10 @@ devbox_init_command() {
local AUTHENTICATION_IMAGE="$args_authentication_image_image" # --authentication-image-image local AUTHENTICATION_IMAGE="$args_authentication_image_image" # --authentication-image-image
local AUTHENTICATION_TAG="$args_authentication_image_tag" # --authentication-image-tag 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
# --force flag to overwrite existing resources # --force flag to overwrite existing resources
local FORCE_INIT="${args_force}" local FORCE_INIT="${args_force}"
@ -867,9 +919,6 @@ devbox_init_command() {
local DEVSVC_REPO="$(get_arg '--devsvc-image-repo')" local DEVSVC_REPO="$(get_arg '--devsvc-image-repo')"
local DEVSVC_IMAGE="$(get_arg '--devsvc-image-name')" local DEVSVC_IMAGE="$(get_arg '--devsvc-image-name')"
local DEVSVC_TAG="$(get_arg '--devsvc-image-tag')" local DEVSVC_TAG="$(get_arg '--devsvc-image-tag')"
local PAYMENT_REPO="$(get_arg '--payment-image-repo')"
local PAYMENT_IMAGE="$(get_arg '--payment-image-name')"
local PAYMENT_TAG="$(get_arg '--payment-image-tag')"
local CONTENT_REPO="$(get_arg '--content-image-repo')" local CONTENT_REPO="$(get_arg '--content-image-repo')"
local CONTENT_IMAGE="$(get_arg '--content-image-name')" local CONTENT_IMAGE="$(get_arg '--content-image-name')"
local CONTENT_TAG="$(get_arg '--content-image-tag')" local CONTENT_TAG="$(get_arg '--content-image-tag')"
@ -879,21 +928,58 @@ devbox_init_command() {
local AUTHENTICATION_REPO="$(get_arg '--authentication-image-repo')" local AUTHENTICATION_REPO="$(get_arg '--authentication-image-repo')"
local AUTHENTICATION_IMAGE="$(get_arg '--authentication-image-name')" local AUTHENTICATION_IMAGE="$(get_arg '--authentication-image-name')"
local AUTHENTICATION_TAG="$(get_arg '--authentication-image-tag')" 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 FORCE_INIT="$(get_arg '--force')" local FORCE_INIT="$(get_arg '--force')"
local is_pull_all_components=true local is_pull_all_components=true
local components=("devsvc" "payment" "content" "central_storage" "authentication") local components=("devsvc" "notification" "content" "central_storage" "authentication")
local start_components=()
echo "==> Checking parameters..." echo "==> Checking parameters..."
for component in "${components[@]}"; do for component in "${components[@]}"; do
echo "==> Checking ${component} image repo...value: $(get_arg "--${component}-image-repo")" echo "==> Checking ${component} image repo...value: $(get_arg "--${component}-image-repo")"
# if any component image repo is provided, then don't pull all components
if [[ -n "$(get_arg "--${component}-image-repo")" ]]; then if [[ -n "$(get_arg "--${component}-image-repo")" ]]; then
is_pull_all_components=false is_pull_all_components=false
break
else
start_components+=("${component}")
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"
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 fi
done done
echo "==> is_pull_all_components: $is_pull_all_components" echo "==> is_pull_all_components: $is_pull_all_components"
echo " ===================================================== " echo " ===================================================== "
@ -915,9 +1001,6 @@ devbox_init_command() {
echo " DEVSVC_REPO = $DEVSVC_REPO" echo " DEVSVC_REPO = $DEVSVC_REPO"
echo " DEVSVC_IMAGE = $DEVSVC_IMAGE" echo " DEVSVC_IMAGE = $DEVSVC_IMAGE"
echo " DEVSVC_TAG = $DEVSVC_TAG" echo " DEVSVC_TAG = $DEVSVC_TAG"
echo " PAYMENT_REPO = $PAYMENT_REPO"
echo " PAYMENT_IMAGE= $PAYMENT_IMAGE"
echo " PAYMENT_TAG = $PAYMENT_TAG"
echo " CONTENT_REPO = $CONTENT_REPO" echo " CONTENT_REPO = $CONTENT_REPO"
echo " CONTENT_IMAGE = $CONTENT_IMAGE" echo " CONTENT_IMAGE = $CONTENT_IMAGE"
echo " CONTENT_TAG = $CONTENT_TAG" echo " CONTENT_TAG = $CONTENT_TAG"
@ -927,6 +1010,9 @@ devbox_init_command() {
echo " AUTHENTICATION_REPO = $AUTHENTICATION_REPO" echo " AUTHENTICATION_REPO = $AUTHENTICATION_REPO"
echo " AUTHENTICATION_IMAGE= $AUTHENTICATION_IMAGE" echo " AUTHENTICATION_IMAGE= $AUTHENTICATION_IMAGE"
echo " AUTHENTICATION_TAG = $AUTHENTICATION_TAG" echo " AUTHENTICATION_TAG = $AUTHENTICATION_TAG"
echo " NOTIFICATION_REPO = $NOTIFICATION_REPO"
echo " NOTIFICATION_IMAGE= $NOTIFICATION_IMAGE"
echo " NOTIFICATION_TAG = $NOTIFICATION_TAG"
echo " FORCE_INIT = $FORCE_INIT" echo " FORCE_INIT = $FORCE_INIT"
echo echo
@ -1014,10 +1100,6 @@ devbox_init_command() {
exit 1 exit 1
fi fi
# 如有 --force 且存在旧容器,则可在此删除旧容器/文件(也可在下面先检查容器再删)
# ...
# ------------------------------------------------------------------- # -------------------------------------------------------------------
# 5.1 pull and start DevBox container # 5.1 pull and start DevBox container
# ------------------------------------------------------------------- # -------------------------------------------------------------------
@ -1041,6 +1123,20 @@ devbox_init_command() {
fi fi
DEVBOX_FREELEAPS2_NETWORK="devbox_freeleaps2-network"
echo '==> [INIT] Starting DevBox environment initialization...'
# Check if docker network create devbox_freeleaps2-network
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
echo '==> [INIT] Starting DevBox container...'
# Create and start DevBox container # Create and start DevBox container
local container_id local container_id
container_id="$( container_id="$(
@ -1051,6 +1147,7 @@ devbox_init_command() {
-p "${DEVBOX_BACKEND_PORT}:8002" \ -p "${DEVBOX_BACKEND_PORT}:8002" \
-v "$WORKING_HOME:/home/.devbox" \ -v "$WORKING_HOME:/home/.devbox" \
-v /var/run/docker.sock:/var/run/docker.sock \ -v /var/run/docker.sock:/var/run/docker.sock \
--network "$DEVBOX_FREELEAPS2_NETWORK" \
"$devbox_full_image" 2>/dev/null "$devbox_full_image" 2>/dev/null
)" )"
@ -1070,98 +1167,67 @@ devbox_init_command() {
echo "==> [INIT] Starting Freeleaps services... Use Local component $USE_LOCAL_COMPONENT" echo "==> [INIT] Starting Freeleaps services... Use Local component $USE_LOCAL_COMPONENT"
if [[ "$(lower "$USE_LOCAL_COMPONENT")" == "true" ]]; then if [[ "$(lower "$USE_LOCAL_COMPONENT")" == "true" ]]; then
# 3.Create and start MongoDB container
echo "Step 3. [INFO] Starting MongoDB container..."
start_local_mongodb
# 4. Pull and start RabbitMQ container
start_local_rabbitMQ
echo ' ===> Using local components for Freeleaps services.' echo ' ===> Using local components for Freeleaps services.'
export ARCH="$ARCH"
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"
# Local components for Freeleaps services (devsvc, payment, content, central_storage, authentication) # Start local components by docker compose file and start up specified services. docker compose file is in the same directory as the script (docker-compose.dev.arm64.new.yaml)
for component in "${components[@]}"; do # start component service from start_components array
repo_var="$(upper "$component")_REPO" docker-compose -f docker-compose.dev.arm64.new.yaml up -d mongodb rabbitmq gitea "${start_components[@]}"
image_var="$(upper "$component")_IMAGE" echo "==> Starting Gitea, MongoDB, RabbitMQ containers..."
tag_var="$(upper "$component")_TAG"
gitea_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-gitea$" --format "{{.ID}}")
echo "$gitea_container_id" > "$WORKING_HOME/.gitea-instance"
# Get the component's repo, image, and tag mongo_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-mongodb$" --format "{{.ID}}")
COMPONENT_REPO="${!repo_var}" echo "$mongo_container_id" > "$WORKING_HOME/.mongodb-instance"
COMPONENT_IMAGE="${!image_var}"
COMPONENT_TAG="${!tag_var}"
echo "Component: $component"
echo " Repo: $COMPONENT_REPO"
echo " Image: $COMPONENT_IMAGE"
echo " Tag: $COMPONENT_TAG"
# check if is_pull_all_components is false and component repo and component image parameter not empty rabbitmq_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-rabbitmq$" --format "{{.ID}}")
if [[ "$is_pull_all_components" == false && -n "${!COMPONENT_REPO}" && -n "${!COMPONENT_IMAGE}" ]]; then echo "$rabbitmq_container_id" > "$WORKING_HOME/.rabbitmq-instance"
echo "==> Using local components for Freeleaps services. For $component, COMPONENT_REPO - '$COMPONENT_REPO', COMPONENT_IMAGE - '$COMPONENT_IMAGE'"
continue
fi
component_full_image="" # Get all components container ids and save to .component-instance file
for component in "${start_components[@]}"; do
if [[ "$is_pull_all_components" == true ]]; then tmp_container_id=$(docker ps --no-trunc -a --filter "name=^$component$" --format "{{.ID}}")
component_full_image="docker.io/freeleaps/$component:$arch_tag" echo "$tmp_container_id" > "$WORKING_HOME/.${component}-instance"
else done
component_full_image="${!COMPONENT_REPO}/${!COMPONENT_IMAGE}:${!COMPONENT_TAG}"
fi
echo "==> Pulling ${component} image: $component_full_image"
if ! docker pull "$component_full_image"; then
echo "WARNING: Failed to pull ${component} image: $component_full_image, please Check the image and specify it to initialize the component."
fi
# if container with same name exists, remove it
if docker ps -a --format '{{.Names}}' | grep -q "^${component}\$"; then
if [[ -n "$FORCE_INIT" ]]; then
echo "==> Removing existing container named $component ..."
docker stop "$component" &>/dev/null || true
docker rm "$component" &>/dev/null || true
else
echo "WARNING: Container named $component already exists. Use --force to remove it."
fi
fi
DEFAULT_IP=$(docker network inspect bridge | grep -m1 '"Gateway":' | sed -E 's/.*"Gateway": "([^"]+)".*/\1/')
echo "Default gateway IP: $DEFAULT_IP"
port=$(get_port $component)
echo "==> Creating and starting ${component} container... ${port}"
local component_container_id
component_container_id="$(
docker run -d \
--name "$component" \
--link "$DEVBOX_NAME" \
-p "${port}:${port}" \
-v /var/run/docker.sock:/var/run/docker.sock \
-e SERVICE_API_ACCESS_PORT=${port} \
-e SERVICE_API_ACCESS_HOST=0.0.0.0 \
-e MONGODB_URI="mongodb://$DEFAULT_IP:27017" \
"$component_full_image" \
uvicorn webapi.main:app --reload --port ${port} --host 0.0.0.0 2>/dev/null
)"
if [[ -z "$component_container_id" ]]; then
echo "WARNING: Failed to create ${component} container. please Check the image and specify it to initialize the component."
fi
echo "$component_container_id" > "$WORKING_HOME/.${component}-instance"
echo "${component} container created: $component_container_id" echo "${component} container created: $component_container_id"
done
else else
echo '============================================' echo '============================================'
echo ' ===> Using online components for Freeleaps services.' echo ' ===> Using online components for Freeleaps services.'
echo '============================================' echo '============================================'
# Start Gitea, MongoDB, RabbitMQ containers
local_components_docker_compose_output=$(docker-compose -f docker-compose.dev.arm64.new.yaml up -d mongodb rabbitmq)
if [[ -z "$local_components_docker_compose_output" ]]; then
echo "ERROR: Failed to start MongoDB, RabbitMQ containers."
exit 1
fi
# Save MongoDB and RabbitMQ container ids to .mongodb-instance and .rabbitmq-instance
mongo_container_id=$(docker ps -a --format '{{.Names}}' | grep "^freeleaps2-mongodb\$")
echo "$mongo_container_id" > "$WORKING_HOME/.mongodb-instance"
rabbitmq_container_id=$(docker ps -a --format '{{.Names}}' | grep "^freeleaps2-rabbitmq\$")
echo "$rabbitmq_container_id" > "$WORKING_HOME/.rabbitmq-instance"
fi fi
pushd $WORKING_HOME pushd $WORKING_HOME
# Make a user input (Y/N) to continue pull freeleaps.com code and start if N then exit
read -p "Do you want to continue to pull freeleaps.com code and start the services? (Y/N): " user_input
if [[ "$user_input" == "N" || "$user_input" == "n" ]]; then
# Echo as init job completed and exit
echo "==> [INIT] DevBox environment initialization completed."
exit 0
fi
# Check if freeleaps2-frontend exists, if not git clone it # Check if freeleaps2-frontend exists, if not git clone it
if [ ! -d $WORKING_HOME/freeleaps ]; then if [ ! -d $WORKING_HOME/freeleaps ]; then
echo "Git cloning freeleaps.com:3443/products/freeleaps.git" echo "Git cloning freeleaps.com:3443/products/freeleaps.git"
@ -1169,8 +1235,6 @@ if [ ! -d $WORKING_HOME/freeleaps ]; then
git clone --depth 5 $FRONTEND_GIT_URL git clone --depth 5 $FRONTEND_GIT_URL
else else
pushd $WORKING_HOME/freeleaps pushd $WORKING_HOME/freeleaps
pwd
ls -la
echo "Git pulling freeleaps.com:3443/products/freeleaps.git" echo "Git pulling freeleaps.com:3443/products/freeleaps.git"
git pull git pull
fi fi
@ -1193,7 +1257,7 @@ echo "step 2: Update /home/.devbox/freeleaps/apps/.env"
DEFAULT_IP=\$(ip route | grep default | sed -n 's/.*default via \([^ ]*\).*/\1/p') DEFAULT_IP=\$(ip route | grep default | sed -n 's/.*default via \([^ ]*\).*/\1/p')
if [[ "\$(lower "\$USE_LOCAL_COMPONENT")" == "true" ]]; then if [[ "\$(lower "\$USE_LOCAL_COMPONENT")" == "true" ]]; then
echo "==> Using local components" echo "==> Using local components"
# Local components for Freeleaps services (devsvc, payment, content, central_storage, authentication) # Local components for Freeleaps services (devsvc, notification, content, central_storage, authentication)
cat << 'EOFinner' > /home/.devbox/freeleaps/apps/.env cat << 'EOFinner' > /home/.devbox/freeleaps/apps/.env
# Online endpoint info # Online endpoint info
export MONGODB_NAME=freeleaps2 export MONGODB_NAME=freeleaps2
@ -1210,7 +1274,7 @@ if [[ "\$(lower "\$USE_LOCAL_COMPONENT")" == "true" ]]; then
export SITE_URL_ROOT=http://\$DEFAULT_IP/ export SITE_URL_ROOT=http://\$DEFAULT_IP/
export FREELEAPS_DEVSVC_ENDPOINT=http://\$DEFAULT_IP:8007/api/devsvc/ export FREELEAPS_DEVSVC_ENDPOINT=http://\$DEFAULT_IP:8007/api/devsvc/
export FREELEAPS_CONTENT_ENDPOINT=http://\$DEFAULT_IP:8013/api/content/ export FREELEAPS_CONTENT_ENDPOINT=http://\$DEFAULT_IP:8013/api/content/
export FREELEAPS_PAYMENT_ENDPOINT=http://\$DEFAULT_IP:8006/api/payment/ export FREELEAPS_NOTIFICATION_ENDPOINT=http://\$DEFAULT_IP:8003/api/notification/
export FREELEAPS_CENTRAL_STORAGE_ENDPOINT=http://\$DEFAULT_IP:8005/api/central_storage/ export FREELEAPS_CENTRAL_STORAGE_ENDPOINT=http://\$DEFAULT_IP:8005/api/central_storage/
export FREELEAPS_AUTHENTICATION_ENDPOINT=http://\$DEFAULT_IP:8004/api/auth/ export FREELEAPS_AUTHENTICATION_ENDPOINT=http://\$DEFAULT_IP:8004/api/auth/
export FREELEAPS_AILAB_ENDPOINT=https://as010-w2-re-vm.mathmast.com:8009/api/ export FREELEAPS_AILAB_ENDPOINT=https://as010-w2-re-vm.mathmast.com:8009/api/
@ -1233,7 +1297,7 @@ else
export SITE_URL_ROOT=http://localhost/ export SITE_URL_ROOT=http://localhost/
export FREELEAPS_DEVSVC_ENDPOINT=http://52.149.3.85:8007/api/devsvc/ export FREELEAPS_DEVSVC_ENDPOINT=http://52.149.3.85:8007/api/devsvc/
export FREELEAPS_CONTENT_ENDPOINT=http://52.149.35.244:8013/api/content/ export FREELEAPS_CONTENT_ENDPOINT=http://52.149.35.244:8013/api/content/
export FREELEAPS_PAYMENT_ENDPOINT=http://52.149.35.244:8006/api/payment/ export FREELEAPS_NOTIFICATION_ENDPOINT=http://52.149.35.244:8003/api/notification/
export FREELEAPS_CENTRAL_STORAGE_ENDPOINT=http://52.149.35.244:8005/api/central_storage/ export FREELEAPS_CENTRAL_STORAGE_ENDPOINT=http://52.149.35.244:8005/api/central_storage/
export FREELEAPS_AUTHENTICATION_ENDPOINT=http://52.149.35.244:8004/api/auth/ export FREELEAPS_AUTHENTICATION_ENDPOINT=http://52.149.35.244:8004/api/auth/
export FREELEAPS_AILAB_ENDPOINT=https://as010-w2-re-vm.mathmast.com:8009/api/ export FREELEAPS_AILAB_ENDPOINT=https://as010-w2-re-vm.mathmast.com:8009/api/
@ -1405,8 +1469,7 @@ EOF
echo echo
echo "===========================================================" echo "==========================================================="
echo "DevBox init completed successfully!" echo "DevBox init completed successfully!"
echo " DevBox container ID: $container_id" echo " DevBox container ID: $WORKING_HOME/.devbox-instance"
[[ -f "${WORKING_HOME}/.devbox-instance" ]] && echo " devbox container ID: $(cat "${WORKING_HOME}/.devbox-instance")"
echo " Repository cloned to: $WORKING_HOME/freeleaps" echo " Repository cloned to: $WORKING_HOME/freeleaps"
echo " Backend logs: $WORKING_HOME/logs/backend.logs" echo " Backend logs: $WORKING_HOME/logs/backend.logs"
echo " Frontend logs: $WORKING_HOME/logs/frontend.logs" echo " Frontend logs: $WORKING_HOME/logs/frontend.logs"
@ -1472,6 +1535,15 @@ devbox_deinit_command() {
rm -f "$WORKING_HOME/.frontend.pid" rm -f "$WORKING_HOME/.frontend.pid"
fi fi
if [[ -f "$WORKING_HOME/.gitea-instance" ]]; then
local gitea_container_id
gitea_container_id=$(cat "$WORKING_HOME/.gitea-instance")
echo "==> Stopping and removing Gitea container: $gitea_container_id"
docker stop "$gitea_container_id" &>/dev/null || true
docker rm "$gitea_container_id" &>/dev/null || true
rm -f "$WORKING_HOME/.gitea-instance"
fi
# Stop and remove MongoDB container # Stop and remove MongoDB container
if [[ -f "$WORKING_HOME/.mongodb-instance" ]]; then if [[ -f "$WORKING_HOME/.mongodb-instance" ]]; then
local mongodb_container_id local mongodb_container_id
@ -1493,7 +1565,7 @@ devbox_deinit_command() {
fi fi
# Stop and remove other components # Stop and remove other components
local components=("devsvc" "payment" "content" "central_storage" "authentication") local components=("devsvc" "notification" "content" "central_storage" "authentication")
for component in "${components[@]}"; do for component in "${components[@]}"; do
if [[ -f "$WORKING_HOME/.${component}-instance" ]]; then if [[ -f "$WORKING_HOME/.${component}-instance" ]]; then
local component_container_id local component_container_id
@ -1540,7 +1612,7 @@ devbox_start_command() {
# If no component is specified, start all components # If no component is specified, start all components
if [[ -z "$COMPONENT" ]]; then if [[ -z "$COMPONENT" ]]; then
COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend" "devsvc" "payment" "content" "central_storage" "authentication") COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend" "devsvc" "content" "central_storage" "authentication")
else else
COMPONENTS=("$COMPONENT") COMPONENTS=("$COMPONENT")
fi fi
@ -1757,7 +1829,7 @@ EOF
fi fi
EOF EOF
;; ;;
"devsvc" | "payment" | "content" | "central_storage" | "authentication") "devsvc" | "content" | "central_storage" | "authentication")
echo "==> Starting $comp service..." echo "==> Starting $comp service..."
# Check if the component container file exists # Check if the component container file exists
local component_container_id_file_path="${WORKING_HOME}/.${comp}-instance" local component_container_id_file_path="${WORKING_HOME}/.${comp}-instance"
@ -1801,7 +1873,7 @@ devbox_stop_command() {
# If the DevBox container is not running, exit # If the DevBox container is not running, exit
if [[ -z "$COMPONENT" ]]; then if [[ -z "$COMPONENT" ]]; then
COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend" "devsvc" "payment" "content" "central_storage" "authentication") COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend" "devsvc" "content" "central_storage" "authentication")
else else
COMPONENTS=("$COMPONENT") COMPONENTS=("$COMPONENT")
fi fi
@ -1849,7 +1921,7 @@ devbox_stop_command() {
echo "==> Frontend service is not running." echo "==> Frontend service is not running."
fi fi
;; ;;
"devsvc" | "payment" | "content" | "central_storage" | "authentication") "devsvc" | "content" | "central_storage" | "authentication")
echo "==> Stopping $comp service..." echo "==> Stopping $comp service..."
if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then
local container_id local container_id
@ -1893,7 +1965,7 @@ devbox_status_command() {
# If no component is specified, check all components # If no component is specified, check all components
if [[ -z "$COMPONENT" ]]; then if [[ -z "$COMPONENT" ]]; then
COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend" "devsvc" "payment" "content" "central_storage" "authentication") COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend" "devsvc" "content" "central_storage" "authentication")
else else
COMPONENTS=("$COMPONENT") COMPONENTS=("$COMPONENT")
fi fi
@ -1990,20 +2062,6 @@ devbox_status_command() {
echo "[RESULT]: devsvc container is not running." echo "[RESULT]: devsvc container is not running."
fi fi
;; ;;
"payment")
echo "==> Checking payment service status..."
if [[ -f "${WORKING_HOME}/.payment-instance" ]]; then
local container_id
container_id=$(cat "${WORKING_HOME}/.payment-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
echo "[RESULT]: payment container is running."
else
echo "[RESULT]: payment container is not running."
fi
else
echo "[RESULT]: payment container is not running."
fi
;;
"content") "content")
echo "==> Checking content service status..." echo "==> Checking content service status..."
if [[ -f "${WORKING_HOME}/.content-instance" ]]; then if [[ -f "${WORKING_HOME}/.content-instance" ]]; then
@ -2084,7 +2142,7 @@ devbox_restart_command() {
fi fi
if [[ -z "$COMPONENT" ]]; then if [[ -z "$COMPONENT" ]]; then
COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend" "devsvc" "payment" "content" "central_storage" "authentication") COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend" "devsvc" "content" "central_storage" "authentication")
else else
COMPONENTS=("$COMPONENT") COMPONENTS=("$COMPONENT")
fi fi
@ -2132,7 +2190,7 @@ devbox_restart_command() {
echo "==> Frontend service is not running." echo "==> Frontend service is not running."
fi fi
;; ;;
"devsvc" | "payment" | "content" | "central_storage" | "authentication") "devsvc" | "content" | "central_storage" | "authentication")
echo "==> Stopping $comp service..." echo "==> Stopping $comp service..."
if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then
local container_id local container_id
@ -2329,7 +2387,7 @@ EOF
echo "==> Frontend service is not running." echo "==> Frontend service is not running."
fi fi
;; ;;
"devsvc" | "payment" | "content" | "central_storage" | "authentication") "devsvc" | "content" | "central_storage" | "authentication")
echo "==> Restarting $comp service..." echo "==> Restarting $comp service..."
if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then
local container_id local container_id
@ -2683,39 +2741,6 @@ devbox_init_parse_requirements() {
fi fi
;; ;;
# :flag.case
--payment-image-repo)
if [[ -n ${2+x} ]]; then
add_arg '--payment-image-repo' "$2"
shift 2
else
printf "%s\n" "--payment-image-repo requires an argument: --payment-image-repo FREELEAPS_PAYMENT_IMAGE_REPO" >&2
exit 1
fi
;;
# :flag.case
--payment-image-name)
if [[ -n ${2+x} ]]; then
add_arg '--payment-image-name' "$2"
shift 2
else
printf "%s\n" "--payment-image-name requires an argument: --payment-image-name FREELEAPS_PAYMENT_IMAGE_NAME" >&2
exit 1
fi
;;
# :flag.case
--payment-image-tag)
if [[ -n ${2+x} ]]; then
add_arg '--payment-image-tag' "$2"
shift 2
else
printf "%s\n" "--payment-image-tag requires an argument: --payment-image-tag FREELEAPS_PAYMENT_IMAGE_TAG" >&2
exit 1
fi
;;
# :flag.case # :flag.case
--content-image-repo) --content-image-repo)
if [[ -n ${2+x} ]]; then if [[ -n ${2+x} ]]; then
@ -2892,10 +2917,6 @@ devbox_init_parse_requirements() {
add_arg '--devsvc-image-tag' "latest-linux-arm64" add_arg '--devsvc-image-tag' "latest-linux-arm64"
fi fi
if [ -z "$(get_arg '--payment-image-tag')" ]; then
add_arg '--payment-image-tag' "latest-linux-arm64"
fi
if [ -z "$(get_arg '--content-image-tag')" ]; then if [ -z "$(get_arg '--content-image-tag')" ]; then
add_arg '--content-image-tag' "latest-linux-arm64" add_arg '--content-image-tag' "latest-linux-arm64"
fi fi

View File

@ -2,7 +2,7 @@ services:
gitea: gitea:
# For apple chip, add: platform: linux/amd64 # For apple chip, add: platform: linux/amd64
container_name: freeleaps2-gitea container_name: freeleaps2-gitea
platform: linux/arm64 platform: linux/${ARCH:-arm64}
image: gitea/gitea:latest image: gitea/gitea:latest
restart: always restart: always
ports: ports:
@ -19,8 +19,8 @@ services:
# For apple chip, add: platform: linux/amd64 # For apple chip, add: platform: linux/amd64
# For apple chip, you may want to downgrade to public mongo:4.4 for log support # For apple chip, you may want to downgrade to public mongo:4.4 for log support
container_name: freeleaps2-mongodb container_name: freeleaps2-mongodb
platform: linux/arm64 platform: linux/${ARCH:-arm64}
image: freeleaps.azurecr.io/mongo:latest-linux-arm64 image: mongo:latest
restart: always restart: always
ports: ports:
- "27017:27017" - "27017:27017"
@ -31,7 +31,7 @@ services:
rabbitmq: rabbitmq:
# For apple chip, add: platform: linux/amd64 # For apple chip, add: platform: linux/amd64
platform: linux/arm64 platform: linux/${ARCH:-arm64}
container_name: freeleaps2-rabbitmq container_name: freeleaps2-rabbitmq
image: rabbitmq:latest image: rabbitmq:latest
restart: always restart: always
@ -45,7 +45,7 @@ services:
devsvc: devsvc:
container_name: devsvc container_name: devsvc
image: freeleaps.azurecr.io/devsvc:1.0.0 image: freeleaps/devsvc:${DEVSVC_IMAGE_TAG:-latest-linux-arm64}
restart: always restart: always
environment: environment:
- APP_NAME=devsvc - APP_NAME=devsvc
@ -79,9 +79,9 @@ services:
central_storage: central_storage:
container_name: central_storage container_name: central_storage
image: freeleaps.azurecr.io/central_storage:latest-linux-arm64 image: freeleaps/central_storage:${CENTRAL_STORAGE_IMAGE_TAG:-latest-linux-arm64}
# profiles: [ prod, alpha, dev ] # profiles: [ prod, alpha, dev ]
platform: linux/arm64 platform: linux/${ARCH:-arm64}
restart: always restart: always
environment: environment:
- APP_NAME=central_storage - APP_NAME=central_storage
@ -111,9 +111,9 @@ services:
authentication: authentication:
container_name: authentication container_name: authentication
image: freeleaps.azurecr.io/authentication:latest-linux-arm64 image: freeleaps/authentication:${AUTHENTICATION_IMAGE_TAG:-latest-linux-arm64}
# profiles: [ prod, alpha, dev ] # profiles: [ prod, alpha, dev ]
platform: linux/arm64 platform: linux/${ARCH:-arm64}
restart: always restart: always
environment: environment:
- APP_NAME=authentication - APP_NAME=authentication
@ -145,9 +145,9 @@ services:
content: content:
container_name: content container_name: content
image: freeleaps.azurecr.io/content:latest-linux-arm64 image: freeleaps/content:${CONTENT_IMAGE_TAG:-latest-linux-arm64}
# profiles: [ prod, alpha, dev ] # profiles: [ prod, alpha, dev ]
platform: linux/arm64 platform: linux/${ARCH:-arm64}
restart: always restart: always
environment: environment:
- APP_NAME=content - APP_NAME=content
@ -176,9 +176,9 @@ services:
notification: notification:
container_name: notification container_name: notification
image: freeleaps.azurecr.io/notification:latest-linux-arm64 image: freeleaps/notification:${NOTIFICATION_IMAGE_TAG:-latest-linux-arm64}
# profiles: [ prod, alpha, dev ] # profiles: [ prod, alpha, dev ]
platform: linux/arm64 platform: linux/${ARCH:-arm64}
restart: always restart: always
environment: environment:
- APP_NAME=notification - APP_NAME=notification