forked from freeleaps/freeleaps-pub
Update for gitea data initialize
This commit is contained in:
parent
9b2c914736
commit
dd10b3b062
@ -446,6 +446,43 @@ get_port() {
|
|||||||
echo "$port"
|
echo "$port"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_jq() {
|
||||||
|
# 从参数中获取 OS 和 ARCH,默认值分别为 auto
|
||||||
|
local target_os target_arch
|
||||||
|
target_os="$(get_arg '--os' 'auto')"
|
||||||
|
target_arch="$(get_arg '--arch' 'auto')"
|
||||||
|
|
||||||
|
if ! command -v jq >/dev/null 2>&1; then
|
||||||
|
echo "[INFO] 'jq' is not installed. Installing jq..."
|
||||||
|
case "$target_os" in
|
||||||
|
darwin)
|
||||||
|
if command -v brew >/dev/null 2>&1; then
|
||||||
|
brew install jq
|
||||||
|
else
|
||||||
|
echo "[ERROR] brew not found. Please install jq manually."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
linux | wsl2 | auto)
|
||||||
|
if command -v apt-get >/dev/null 2>&1; then
|
||||||
|
sudo apt-get update && sudo apt-get install -y jq
|
||||||
|
elif command -v yum >/dev/null 2>&1; then
|
||||||
|
sudo yum install -y epel-release && sudo yum install -y jq
|
||||||
|
else
|
||||||
|
echo "[ERROR] apt-get or yum not found. Please install jq manually."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "[ERROR] Unsupported OS: $target_os"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
echo "[INFO] 'jq' is already installed."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# :command.command_functions
|
# :command.command_functions
|
||||||
# :command.function
|
# :command.function
|
||||||
devbox_init_command() {
|
devbox_init_command() {
|
||||||
@ -800,10 +837,39 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
|
|||||||
export AUTHENTICATION_IMAGE_TAG="$AUTHENTICATION_TAG"
|
export AUTHENTICATION_IMAGE_TAG="$AUTHENTICATION_TAG"
|
||||||
export NOTIFICATION_IMAGE_TAG="$NOTIFICATION_TAG"
|
export NOTIFICATION_IMAGE_TAG="$NOTIFICATION_TAG"
|
||||||
|
|
||||||
# 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)
|
# Check if gitea_data_backup.tar.gz exists at current script directory, if not exit
|
||||||
# start component service from start_components array
|
if [[ ! -f "gitea_data_backup.tar.gz" ]]; then
|
||||||
docker-compose -f docker-compose.dev.arm64.new.yaml up -d mongodb rabbitmq gitea "${start_components[@]}"
|
echo "ERROR: gitea_data_backup.tar.gz not found. Please make sure it exists in the current directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Sudo force sudo tar -xzvf gitea_data_backup.tar.gz
|
||||||
|
sudo tar -xzvf gitea_data_backup.tar.gz
|
||||||
|
|
||||||
|
# Check if data/git, data/gitea, data/ssh directories exist after extracting gitea_data_backup.tar.gz
|
||||||
|
if [[ ! -d "data/git" || ! -d "data/gitea" || ! -d "data/ssh" ]]; then
|
||||||
|
echo "ERROR: Failed to extract gitea data backup."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Check if jq is installed, if not install it
|
||||||
|
check_jq
|
||||||
|
|
||||||
|
# Get Gitea data volume mount point
|
||||||
|
GITEA_DATA=$(docker volume inspect devbox_freeleaps2-gitea-data | jq -r '.[0].Mountpoint')
|
||||||
|
|
||||||
|
echo "Gitea data volume mount point: $GITEA_DATA"
|
||||||
|
|
||||||
echo "==> Starting Gitea, MongoDB, RabbitMQ containers..."
|
echo "==> Starting Gitea, MongoDB, RabbitMQ containers..."
|
||||||
|
# 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)
|
||||||
|
docker-compose -f docker-compose.dev.arm64.new.yaml up -d mongodb rabbitmq gitea
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
# start component service from start_components array
|
||||||
|
docker-compose -f docker-compose.dev.arm64.new.yaml up -d "${start_components[@]}"
|
||||||
|
|
||||||
|
|
||||||
gitea_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-gitea$" --format "{{.ID}}")
|
gitea_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-gitea$" --format "{{.ID}}")
|
||||||
echo "$gitea_container_id" > "$WORKING_HOME/.gitea-instance"
|
echo "$gitea_container_id" > "$WORKING_HOME/.gitea-instance"
|
||||||
@ -814,6 +880,7 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
|
|||||||
rabbitmq_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-rabbitmq$" --format "{{.ID}}")
|
rabbitmq_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-rabbitmq$" --format "{{.ID}}")
|
||||||
echo "$rabbitmq_container_id" > "$WORKING_HOME/.rabbitmq-instance"
|
echo "$rabbitmq_container_id" > "$WORKING_HOME/.rabbitmq-instance"
|
||||||
|
|
||||||
|
|
||||||
# Get all components container ids and save to .component-instance file
|
# Get all components container ids and save to .component-instance file
|
||||||
for component in "${start_components[@]}"; do
|
for component in "${start_components[@]}"; do
|
||||||
tmp_container_id=$(docker ps --no-trunc -a --filter "name=^$component$" --format "{{.ID}}")
|
tmp_container_id=$(docker ps --no-trunc -a --filter "name=^$component$" --format "{{.ID}}")
|
||||||
@ -821,6 +888,44 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
|
|||||||
done
|
done
|
||||||
|
|
||||||
echo "${component} container created: $component_container_id"
|
echo "${component} container created: $component_container_id"
|
||||||
|
|
||||||
|
# Check if devbox_freeleaps2-gitea-data exists, if not create a docker volume for gitea data, if exists then remove it and create a new one
|
||||||
|
if docker volume ls | grep -q "devbox_freeleaps2-gitea-data"; then
|
||||||
|
docker volume rm devbox_freeleaps2-gitea-data
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker volume create devbox_freeleaps2-gitea-data || {
|
||||||
|
echo "ERROR: Failed to create volume devbox_freeleaps2-gitea-data."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check volume created successfully
|
||||||
|
if ! docker volume ls | grep -q "devbox_freeleaps2-gitea-data"; then
|
||||||
|
echo "ERROR: Failed to create volume devbox_freeleaps2-gitea-data."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -d "${GITEA_DATA}/gitea" ]]; then
|
||||||
|
echo "Gitea data exist, skipping..."
|
||||||
|
else
|
||||||
|
echo "Gitea data not exist, copying..."
|
||||||
|
sudo rm -rf ${GITEA_DATA}/git
|
||||||
|
sudo rm -rf ${GITEA_DATA}/gitea
|
||||||
|
sudo rm -rf ${GITEA_DATA}/ssh
|
||||||
|
sudo mv data/git ${GITEA_DATA}/
|
||||||
|
sudo mv data/gitea ${GITEA_DATA}/
|
||||||
|
sudo mv data/ssh ${GITEA_DATA}/
|
||||||
|
sudo chown -R freedev:freedev ${GITEA_DATA}
|
||||||
|
echo "Gitea data copying is done"
|
||||||
|
# Check if gitea data copied successfully
|
||||||
|
if [[ ! -d "${GITEA_DATA}/gitea" ]]; then
|
||||||
|
echo "ERROR: Failed to copy gitea data."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# restart gitea container
|
||||||
|
docker-compose -f docker-compose.dev.arm64.new.yaml restart gitea
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo '============================================'
|
echo '============================================'
|
||||||
echo ' ===> Using online components for Freeleaps services.'
|
echo ' ===> Using online components for Freeleaps services.'
|
||||||
@ -902,6 +1007,7 @@ else
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Run banckend service and frontend service in the container
|
# Run banckend service and frontend service in the container
|
||||||
docker exec -i "$DEVBOX_NAME" bash <<EOF
|
docker exec -i "$DEVBOX_NAME" bash <<EOF
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user