diff --git a/tools/migration/Dockerfile b/tools/migration/Dockerfile index 5579bd95f..c30db8d89 100644 --- a/tools/migration/Dockerfile +++ b/tools/migration/Dockerfile @@ -16,6 +16,4 @@ WORKDIR /harbor-migration COPY ./ ./ -RUN ./prepare.sh - ENTRYPOINT ["./run.sh"] diff --git a/tools/migration/alembic.tpl b/tools/migration/alembic.tpl index 548c6028d..985db808e 100644 --- a/tools/migration/alembic.tpl +++ b/tools/migration/alembic.tpl @@ -30,7 +30,7 @@ script_location = migration_harbor # are written from script.py.mako # output_encoding = utf-8 -sqlalchemy.url = mysql://$db_username:$db_password@localhost:$db_port/$db_name +sqlalchemy.url = mysql://$DB_USR:$DB_PWD@localhost:3306/registry # Logging configuration [loggers] diff --git a/tools/migration/migration.cfg b/tools/migration/migration.cfg deleted file mode 100644 index a383853ac..000000000 --- a/tools/migration/migration.cfg +++ /dev/null @@ -1,4 +0,0 @@ -db_username="root" -db_password="root123" -db_port="3306" -db_name="registry" diff --git a/tools/migration/prepare.sh b/tools/migration/prepare.sh deleted file mode 100755 index 4d707407c..000000000 --- a/tools/migration/prepare.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -source ./migration.cfg -source ./alembic.tpl > ./alembic.ini diff --git a/tools/migration/run.sh b/tools/migration/run.sh index d3a5a5b8e..82fc09d87 100755 --- a/tools/migration/run.sh +++ b/tools/migration/run.sh @@ -1,15 +1,19 @@ #!/bin/bash export PYTHONPATH=$PYTHONPATH:/harbor-migration +if [ -z "$DB_USR" -o -z "$DB_PWD" ]; then + echo "DB_USR or DB_PWD not set, exiting..." + exit 1 +fi -source ./migration.cfg +source ./alembic.tpl > ./alembic.ini WAITTIME=60 -DBCNF="-hlocalhost -u${db_username}" +DBCNF="-hlocalhost -u${DB_USR}" #prevent shell to print insecure message -export MYSQL_PWD="${db_password}" +export MYSQL_PWD="${DB_PWD}" if [[ $1 = "help" || $1 = "h" || $# = 0 ]]; then echo "Usage:" @@ -21,7 +25,7 @@ if [[ $1 = "help" || $1 = "h" || $# = 0 ]]; then exit 0 fi -if [[ $1 = "up" || $1 = "upgrade" ]]; then +if [[ ( $1 = "up" || $1 = "upgrade" ) && ${SKIP_CONFIRM} != "y" ]]; then echo "Please backup before upgrade." read -p "Enter y to continue updating or n to abort:" ans case $ans in @@ -39,7 +43,7 @@ fi echo 'Trying to start mysql server...' DBRUN=0 -nohup mysqld 2>&1 > ./mysqld.log& +mysqld & for i in $(seq 1 $WAITTIME); do echo "$(/usr/sbin/service mysql status)" if [[ "$(/usr/sbin/service mysql status)" =~ "not running" ]]; then