diff --git a/docker/dev/find_fastest_resources.sh b/docker/dev/find_fastest_resources.sh index 4d87597276..eeb6247289 100755 --- a/docker/dev/find_fastest_resources.sh +++ b/docker/dev/find_fastest_resources.sh @@ -1,4 +1,5 @@ #!/bin/bash + # Copyright 2020 The SQLFlow Authors. All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -36,7 +37,7 @@ function get_domain_from_url() { # Find the fastest URL. The parameter consists of URLS separated by whitespace. function find_fastest_url() { - local speed=99999.9 + local speed=99999 # shellcheck disable=SC2068 for i in $@; do local domain @@ -48,10 +49,11 @@ function find_fastest_url() { cur_speed=$(ping -c 4 -W 2 "$domain" | tail -1 \ | grep "/avg/" | awk '{print $4}'\ | cut -d '/' -f 2) - cur_speed=${cur_speed:-99999.9} + cur_speed=${cur_speed:-99999} + cur_speed=${cur_speed/.*/} # c.f. https://stackoverflow.com/a/31087503/724872 - if (( $(echo "$cur_speed < $speed" | bc -l) )); then + if [[ $cur_speed -lt $speed ]]; then local best_domain="$i" speed="$cur_speed" fi @@ -245,3 +247,17 @@ function choose_fastest_pip_source() { find_fastest_pip_mirror > "$HOME"/.pip/pip.conf } +function choose_fastest_alpine_source() { + default="http://dl-cdn.alpinelinux.org" + read -r -d '\t' urls </dev/null + VOLUME /var/lib/mysql ARG MYSQL_PORT="3306" diff --git a/docker/mysql/install-mysql-server.bash b/docker/mysql/install-mysql-server.bash deleted file mode 100755 index d16b234666..0000000000 --- a/docker/mysql/install-mysql-server.bash +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -# Copyright 2020 The SQLFlow Authors. All rights reserved. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -e - -source find_fastest_resources.sh -choose_fastest_apt_source - -echo "Install MySQL server without a password prompt ..." -echo 'mysql-server mysql-server/root_password password root' | \ - debconf-set-selections -echo 'mysql-server mysql-server/root_password_again password root' | \ - debconf-set-selections -apt-get -qq update > /dev/null -apt-get -qq install -y mysql-server > /dev/null -mkdir -p /var/run/mysqld -mkdir -p /var/lib/mysql -chown mysql:mysql /var/run/mysqld -chown mysql:mysql /var/lib/mysql -mkdir -p /docker-entrypoint-initdb.d diff --git a/docker/mysql/start.bash b/docker/mysql/start.bash index e776effd06..49a646508f 100755 --- a/docker/mysql/start.bash +++ b/docker/mysql/start.bash @@ -1,4 +1,5 @@ -#!/bin/bash +#!/bin/sh + # Copyright 2020 The SQLFlow Authors. All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,14 +15,38 @@ set -e + +echo "Init mysqld if needed ..." +if [[ -d "/docker-entrypoint-initdb.d" ]]; then + echo "Skip" +else + mkdir -p /var/run/mysqld + mkdir -p /var/lib/mysql + chown mysql:mysql /var/run/mysqld + chown mysql:mysql /var/lib/mysql + mkdir -p /docker-entrypoint-initdb.d + + mysql_install_db --user=mysql --datadir=/var/lib/mysql >dev/null + mysqld --user=mysql --bootstrap --verbose=0 \ + --skip-name-resolve --skip-networking=0 >/dev/null </dev/null 2>&1 & +sleep 2 echo "Sleep until MySQL server is ready ..." @@ -31,26 +56,16 @@ until mysql -u root -proot \ --port "$MYSQL_PORT" \ -e ";" ; do sleep 1 - read -r -p "Can't connect, retrying..." + echo "Can't connect, retrying..." done -# Grant all privileges to all the remote hosts so that the sqlflow -# server can be scaled to more than one replicas. -# -# NOTE: should notice this authorization on the production -# environment, it's not safe. -mysql -uroot -proot \ - -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'' IDENTIFIED BY 'root' WITH GRANT OPTION;" - - -# FIXME(typhoonzero): should let docker-entrypoint.sh do this work +echo "Populate datasets ..." for f in /datasets/*; do - echo "Populate datasets $f ..." - mysql -uroot -proot \ - --host "$MYSQL_HOST" --port "$MYSQL_PORT" \ - < "$f" + echo "$f" + mysql -uroot -proot < "$f" done +echo "Done." # If we run the contaienr with -v host_dir:/work, then the following @@ -59,4 +74,10 @@ done # file using the trick https://unix.stackexchange.com/a/185370/325629. mkdir -p /work && touch /work/mysql-inited -sleep infinity + +# c.f. https://stackoverflow.com/questions/2935183/bash-infinite-sleep-infinite-blocking for BusyBox +echo "Serving ..." +while true; + do sleep 1d; +done + diff --git a/pkg/workflow/argo/fetch_test.go b/pkg/workflow/argo/fetch_test.go index 0f39bb9c0b..01e5709037 100644 --- a/pkg/workflow/argo/fetch_test.go +++ b/pkg/workflow/argo/fetch_test.go @@ -215,9 +215,9 @@ func TestFetch(t *testing.T) { a.Contains(concatedLogs, "SQLFlow Step: [3/3] Status: Succeeded") // confirm columns and rows of sql: SELECT 1; a.Equal([]string{"1"}, columns) - v := &wrappers.Int64Value{} + v := &wrappers.Int32Value{} a.NoError(ptypes.UnmarshalAny(rows[0][0], v)) - a.Equal(v.GetValue(), int64(1)) + a.Equal(v.GetValue(), int32(1)) } func waitUntilPodRunning(podID string) error {