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
16 changes: 11 additions & 5 deletions fallback_to_5.6.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Source the Docker Compose utility functions
source "$(dirname "$0")/scripts/docker_compose_utils.sh"

# Store the appropriate docker compose command
DOCKER_COMPOSE_CMD=$(get_docker_compose_cmd)

#Pre Step changes image of Mysql back to 5.6 in docker-compose.yml

if [ ! -d ./mysql_backup ]
Expand All @@ -8,9 +14,9 @@ fi

#step 1 Stopping the database if it is already running
echo " Stop the database if running"
docker-compose stop database
$DOCKER_COMPOSE_CMD stop database

docker-compose rm -f database
$DOCKER_COMPOSE_CMD rm -f database


#Step 2 Remove the data/mysql/*
Expand All @@ -28,15 +34,15 @@ cp -f old_configs/nginx.conf ./etc/
cp -f old_configs/1-user.sql initializers/docker-entrypoint-initdb.d/1-user.sql

#start the database container
docker-compose up -d database
$DOCKER_COMPOSE_CMD up -d database

echo "Sleeping for 30 seconds"
sleep 30

# Stop the containers
echo " Stopping all containers"
docker-compose stop
$DOCKER_COMPOSE_CMD stop

echo "********************************************"
echo "Change the TAG in .env file as v20.6"
echo "After this change bring up the containers using docker-compose up -d"
echo "After this change bring up the containers using $DOCKER_COMPOSE_CMD up -d"
34 changes: 20 additions & 14 deletions migrate202012.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
source .env
source env/database.env

# Source the Docker Compose utility functions
source "$(dirname "$0")/scripts/docker_compose_utils.sh"

# Store the appropriate docker compose command
DOCKER_COMPOSE_CMD=$(get_docker_compose_cmd)

if [ -s dump_5.6.sql ]
then
echo "Migration is already done"
Expand All @@ -9,16 +15,16 @@ exit 1
fi

# Step 1: dump mysql data
docker-compose exec -T database mysqldump -uroot -p${MYSQL_ROOT_PASSWORD} --create-options --add-drop-table --single-transaction --databases s3_auths s3_cdets s3_communications s3_controller s3_genie s3_groups s3_history s3_jenkinsengine s3_laas s3_labvpn s3_management s3_monitors s3_plugins s3_qmgr s3_registry s3_requests s3_results s3_sessions s3_testbeds s3_topoman s3_users --skip-comments > dump_5.6.sql
$DOCKER_COMPOSE_CMD exec -T database mysqldump -uroot -p${MYSQL_ROOT_PASSWORD} --create-options --add-drop-table --single-transaction --databases s3_auths s3_cdets s3_communications s3_controller s3_genie s3_groups s3_history s3_jenkinsengine s3_laas s3_labvpn s3_management s3_monitors s3_plugins s3_qmgr s3_registry s3_requests s3_results s3_sessions s3_testbeds s3_topoman s3_users --skip-comments > dump_5.6.sql

if [ -s dump_5.6.sql ]
then
echo "Dump file is not empty, continuing migration..."
# Step 2: stopping database service
docker-compose stop database
$DOCKER_COMPOSE_CMD stop database

# Step 3: rm data bases container
docker-compose rm -f database
$DOCKER_COMPOSE_CMD rm -f database

# Step 4: copy mysql data into a new dir
echo "Backing up mysql data dir"
Expand All @@ -36,45 +42,45 @@ else
fi

# Step 7: starting database with mysql 8.0
docker-compose up -d database
$DOCKER_COMPOSE_CMD up -d database

echo "Sleeping 90 seconds for the database to be up..."
sleep 90

# Step 8: restoring data to mysql 8.0
echo "Restoring MySQL data back to database..."
docker-compose exec -T database mysql -u root -p${MYSQL_ROOT_PASSWORD} < dump_5.6.sql
$DOCKER_COMPOSE_CMD exec -T database mysql -u root -p${MYSQL_ROOT_PASSWORD} < dump_5.6.sql

# Step 9: results migration
docker pull ${DOCKER_REGISTRY}/pyats-web-results:${TAG}
docker-compose stop results results-celery results-beat
$DOCKER_COMPOSE_CMD stop results results-celery results-beat
sleep 10
docker-compose rm -f results results-celery results-beat
$DOCKER_COMPOSE_CMD rm -f results results-celery results-beat
echo "Sleeping 30 seconds for results service to stop"
sleep 30
docker-compose up -d management results
$DOCKER_COMPOSE_CMD up -d management results
echo "Sleeping 40 seconds for results service to start"
sleep 40
docker-compose exec results python manage.py generate_snapshot
$DOCKER_COMPOSE_CMD exec results python manage.py generate_snapshot
mkdir -p logs/results2 && mv logs/results/result_snapshot.json logs/results2/result_snapshot.json
mv data/archives/cached data/archives/cached_old && mkdir data/archives/cached
echo "Results service migration is done!"

# Step 10: stop all services
docker-compose stop
$DOCKER_COMPOSE_CMD stop

# Step 11: pull new images
docker-compose pull
$DOCKER_COMPOSE_CMD pull

# sleep a few seconds
sleep 5

# Step 12: start all services
docker-compose up -d
$DOCKER_COMPOSE_CMD up -d

# Step 13: stop old results service
docker-compose stop results results-celery results-beat
docker-compose rm -f results results-celery results-beat
$DOCKER_COMPOSE_CMD stop results results-celery results-beat
$DOCKER_COMPOSE_CMD rm -f results results-celery results-beat

# Step 14: pull pyats-image-builder docker image
docker pull ${DOCKER_REGISTRY}/image-builder:${TAG}
34 changes: 20 additions & 14 deletions migrate_to_21.8.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
source .env
source env/database.env

# Source the Docker Compose utility functions
source "$(dirname "$0")/scripts/docker_compose_utils.sh"

# Store the appropriate docker compose command
DOCKER_COMPOSE_CMD=$(get_docker_compose_cmd)

echo "Take Backup of existing Data in DB"

if [[ -f backup_before_migration.sql ]]; then
Expand All @@ -17,42 +23,42 @@ sleep 2

#first stepto update or add REDIS_AUTH

docker-compose exec -T requests curl -X PATCH -H "Content-Type: application/json" -d '{"CELERY_REDIS_PASSWORD": "'"$REDIS_PASS"'"}' http://management:8000/management/api/v1/settings/common
$DOCKER_COMPOSE_CMD exec -T requests curl -X PATCH -H "Content-Type: application/json" -d '{"CELERY_REDIS_PASSWORD": "'"$REDIS_PASS"'"}' http://management:8000/management/api/v1/settings/common

sleep 2

docker-compose exec -T requests curl -X PATCH -H "Content-Type: application/json" -d '{"CELERY_BROKER_PASSWORD": "'"$REDIS_PASS"'"}' http://management:8000/management/api/v1/settings/common
$DOCKER_COMPOSE_CMD exec -T requests curl -X PATCH -H "Content-Type: application/json" -d '{"CELERY_BROKER_PASSWORD": "'"$REDIS_PASS"'"}' http://management:8000/management/api/v1/settings/common

sleep 2

docker-compose exec -T requests curl -X PATCH -H "Content-Type: application/json" -d '{"REDIS": {"DB":0, "PORT":6379, "password": "'"${REDIS_PASS}"'" ,"PASSWORD": "'"${REDIS_PASS}"'","HOST": "cache"}}' http://management:8000/management/api/v1/settings/common
$DOCKER_COMPOSE_CMD exec -T requests curl -X PATCH -H "Content-Type: application/json" -d '{"REDIS": {"DB":0, "PORT":6379, "password": "'"${REDIS_PASS}"'" ,"PASSWORD": "'"${REDIS_PASS}"'","HOST": "cache"}}' http://management:8000/management/api/v1/settings/common


docker-compose down
docker-compose down
$DOCKER_COMPOSE_CMD down
$DOCKER_COMPOSE_CMD down

echo "Waiting for complete shutdown...."

sleep 10

echo "Bringing Database up"

docker-compose up -d database cache elasticsearch
$DOCKER_COMPOSE_CMD up -d database cache elasticsearch

echo "Wait for Database up and running..."

sleep 50


docker-compose up -d management
$DOCKER_COMPOSE_CMD up -d management


echo "Wait for management to be Up..."

sleep 60

echo "Bringing up all remaining ones..."
docker-compose up -d
$DOCKER_COMPOSE_CMD up -d


echo "Wait for all services to be UP ...."
Expand All @@ -62,7 +68,7 @@ sleep 150

echo "Migrate data from old results.."

docker-compose exec -T results2 curl -L -X GET http://results2:8000/results/api/v1/results?limit=9999999 --output /s3/logs/output.json
$DOCKER_COMPOSE_CMD exec -T results2 curl -L -X GET http://results2:8000/results/api/v1/results?limit=9999999 --output /s3/logs/output.json

if [[ -f ./logs/results2/output.json ]]; then

Expand All @@ -72,14 +78,14 @@ if [[ -f ./logs/results2/output.json ]]; then

echo "continue..."

docker-compose exec -T results2 python /s3/logs/generate_mapping.py /s3/logs/output.json
$DOCKER_COMPOSE_CMD exec -T results2 python /s3/logs/generate_mapping.py /s3/logs/output.json

sleep 5

if [[ -f ./logs/results2/mapping.json ]]; then
cp ./logs/results2/mapping.json ./logs/requests/
echo "Migrate old data in requests...."
docker-compose exec -T requests python manage.py shell --command="from request_result_migration import *;migrate();update_elastic()"
$DOCKER_COMPOSE_CMD exec -T requests python manage.py shell --command="from request_result_migration import *;migrate();update_elastic()"
else
echo "Mapping file not created"
exit
Expand All @@ -94,9 +100,9 @@ echo "Migrate old data in resources..."
sleep 10

cp migration_scripts/migrate_resources.sh ./logs/resources/
docker-compose exec -T resources cp /s3/logs/migrate_resources.sh .
docker-compose exec -T resources bash ./migrate_resources.sh
$DOCKER_COMPOSE_CMD exec -T resources cp /s3/logs/migrate_resources.sh .
$DOCKER_COMPOSE_CMD exec -T resources bash ./migrate_resources.sh

sleep 5

docker-compose exec -T cache redis-cli -a ${REDIS_PASS} flushall
$DOCKER_COMPOSE_CMD exec -T cache redis-cli -a ${REDIS_PASS} flushall
21 changes: 21 additions & 0 deletions scripts/docker_compose_utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# Function to detect and return the appropriate Docker Compose command
get_docker_compose_cmd() {
# Check if the new 'docker compose' command is available
if docker compose version &>/dev/null; then
echo "docker compose"
else
# Fall back to the old 'docker-compose' command
echo "docker-compose"
fi
}

# Export the function so it's available in sourced scripts
export -f get_docker_compose_cmd

# If this script is executed directly rather than sourced
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
# Output the appropriate command
get_docker_compose_cmd
fi
10 changes: 7 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ BLUE='\033[0;34m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Source the Docker Compose utility functions
source "$(dirname "$0")/scripts/docker_compose_utils.sh"

# Store the appropriate docker compose command
DOCKER_COMPOSE_CMD=$(get_docker_compose_cmd)

echo -e "ADVERTISED_URL: ${BLUE}$1${NC}";
[ -z "$1" ] && echo "ADVERTISED_URL not set. Enter the host url you would like to advertise." && exit;
Expand Down Expand Up @@ -62,14 +66,14 @@ done
echo -e "${GREEN}Initialization of Setup complete!${NC}";

echo -e "${YLW}Bringing up the database....${NC}";
docker-compose up -d database cache elasticsearch
$DOCKER_COMPOSE_CMD up -d database cache elasticsearch

sleep 50

echo -e "${YLW}Bringing up the management service....${NC}";

docker-compose up -d management
$DOCKER_COMPOSE_CMD up -d management

sleep 20

echo -e "${GREEN}run: 'docker-compose up -d' to start xpresso.${NC}";
echo -e "${GREEN}run: '$DOCKER_COMPOSE_CMD up -d' to start xpresso.${NC}";