From ad585499a081d5f01c2fac39c9e46a428e88e72a Mon Sep 17 00:00:00 2001 From: Tan Jiang Date: Thu, 26 Oct 2017 17:08:12 +0800 Subject: [PATCH] Move DB migrator image to be based on Maria DB on photon --- tools/migration/Dockerfile | 19 +++++++------------ tools/migration/alembic.tpl | 2 +- tools/migration/run.sh | 17 ++++++----------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/tools/migration/Dockerfile b/tools/migration/Dockerfile index c30db8d89e..c20665d781 100644 --- a/tools/migration/Dockerfile +++ b/tools/migration/Dockerfile @@ -1,16 +1,11 @@ -FROM mysql:5.6 +FROM vmware/mariadb-photon:10.2.8 -MAINTAINER bhe@vmware.com - -RUN sed -i -e 's/us.archive.ubuntu.com/archive.ubuntu.com/g' /etc/apt/sources.list - -RUN apt-get update - -RUN apt-get install -y curl python python-pip git python-mysqldb - -RUN pip install alembic - -RUN mkdir -p /harbor-migration +RUN tdnf distro-sync || echo \ + && tdnf install -y mariadb-devel python2 python2-devel python-pip gcc\ + linux-api-headers glibc-devel binutils zlib-devel openssl-devel \ + && pip install mysqlclient alembic \ + && tdnf clean all \ + && mkdir -p /harbor-migration WORKDIR /harbor-migration diff --git a/tools/migration/alembic.tpl b/tools/migration/alembic.tpl index 985db808e0..6dc1b0515d 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_USR:$DB_PWD@localhost:3306/registry +sqlalchemy.url = mysql://$DB_USR:$DB_PWD@localhost:3306/registry?unix_socket=/var/run/mysqld/mysqld.sock # Logging configuration [loggers] diff --git a/tools/migration/run.sh b/tools/migration/run.sh index c4141b87f7..fdbe38c3fd 100755 --- a/tools/migration/run.sh +++ b/tools/migration/run.sh @@ -8,8 +8,6 @@ fi source ./alembic.tpl > ./alembic.ini -WAITTIME=60 - DBCNF="-hlocalhost -u${DB_USR}" #prevent shell to print insecure message @@ -44,24 +42,21 @@ fi echo 'Trying to start mysql server...' DBRUN=0 mysqld & -for i in $(seq 1 $WAITTIME); do - echo "$(/usr/sbin/service mysql status)" - if [[ "$(/usr/sbin/service mysql status)" =~ "not running" ]]; then - sleep 1 - else - DBRUN=1 +for i in {60..0}; do + mysqladmin -u$DB_USR -p$DB_PWD processlist >/dev/null 2>&1 + if [ $? = 0 ]; then break fi + echo 'Waiting for MySQL start...' + sleep 1 done - -if [[ $DBRUN -eq 0 ]]; then +if [ "$i" = 0 ]; then echo "timeout. Can't run mysql server." if [[ $1 = "test" ]]; then echo "test failed." fi exit 1 fi - if [[ $1 = "test" ]]; then echo "test passed." exit 0