Skip to content
Merged
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
22 changes: 19 additions & 3 deletions docker/dev/find_fastest_resources.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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/.*/}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a comment here explaining this Bash syntax.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok


# 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
Expand Down Expand Up @@ -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 <<EOM
$default
http://mirrors.tuna.tsinghua.edu.cn
\t
EOM

best=$(find_fastest_url $urls)
if [[ "$best" != "$default" ]]; then
sed -i "s=http://dl-cdn.alpinelinux.org=$best=g" /etc/apk/repositories
fi
}

13 changes: 7 additions & 6 deletions docker/mysql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@
# populating datasets, and the container running sqlflow:ci can use
# inotifywait to wait for the creation of this file before it go on
# running tests.
FROM ubuntu:18.04

COPY docker/dev/find_fastest_resources.sh /usr/local/bin/

COPY docker/mysql/install-mysql-server.bash /
RUN /install-mysql-server.bash
FROM alpine:3.12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a comment here to note how much space does this change save.


# Install sample datasets for CI and demo.
COPY doc/datasets/popularize_churn.sql \
Expand All @@ -37,6 +32,12 @@ COPY doc/datasets/popularize_churn.sql \
doc/datasets/create_model_db.sql \
/datasets/

COPY docker/dev/find_fastest_resources.sh /usr/local/bin/
RUN /bin/sh -c "source find_fastest_resources.sh && \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge these two RUN command lines?

choose_fastest_alpine_source"

RUN apk add --no-cache mysql mysql-client >/dev/null

VOLUME /var/lib/mysql

ARG MYSQL_PORT="3306"
Expand Down
32 changes: 0 additions & 32 deletions docker/mysql/install-mysql-server.bash

This file was deleted.

61 changes: 41 additions & 20 deletions docker/mysql/start.bash
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 <<EOF
FLUSH PRIVILEGES;
DELETE FROM mysql.user;
GRANT ALL ON *.* TO 'root'@'%' identified by 'root' WITH GRANT OPTION;
DROP DATABASE IF EXISTS test;
FLUSH PRIVILEGES;
EOF
fi


echo "Start mysqld ..."
# Important to make mysqld bind to 0.0.0.0 -- all IPs. I explained
# the reason in https://stackoverflow.com/a/61887788/724872.
MYSQL_HOST=${MYSQL_HOST:-0.0.0.0}
MYSQL_PORT=${MYSQL_PORT:-3306}
sed -i "s/.*bind-address.*/bind-address = $MYSQL_HOST/" \
/etc/mysql/mysql.conf.d/mysqld.cnf
service mysql start

nohup mysqld --user=mysql --console \
--skip-name-resolve --skip-networking=0 >/dev/null 2>&1 &
sleep 2


echo "Sleep until MySQL server is ready ..."
Expand All @@ -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
Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The voted answer is sleep infinity from the URL, can you please add more comment to explain why remove sleep infinity?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To minimize the image size, we did not install the bash, so we can't use sleep infinity here.

echo "Serving ..."
while true;
do sleep 1d;
done

4 changes: 2 additions & 2 deletions pkg/workflow/argo/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down