-
Notifications
You must be signed in to change notification settings - Fork 705
Minimize docker image #2526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minimize docker image #2526
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 \ | ||
|
|
@@ -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 && \ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we merge these two |
||
| choose_fastest_alpine_source" | ||
|
|
||
| RUN apk add --no-cache mysql mysql-client >/dev/null | ||
|
|
||
| VOLUME /var/lib/mysql | ||
|
|
||
| ARG MYSQL_PORT="3306" | ||
|
|
||
This file was deleted.
| 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. | ||
|
|
@@ -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 ..." | ||
|
|
@@ -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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The voted answer is
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To minimize the image size, we did not install the |
||
| echo "Serving ..." | ||
| while true; | ||
| do sleep 1d; | ||
| done | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok