-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Templatize and refactor 5.7+ entrypoint scripts #471
Conversation
update.sh
Outdated
# Copy entrypoint template | ||
templateVersions=( "5.7 8.0" ) | ||
for version in ${templateVersions}; do | ||
cp "template.Debian/docker-entrypoint.sh" "${version}/" |
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.
There's really not a whole lot that's different between these and 5.5/5.6 -- do you think it'd make sense to do some runtime detection and switch behavior in the scripts dynamically in order to hit all four versions? We could also have this script include the nuances for the lower versions and have it dynamically update the template when copying it to the lower versions.
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.
Yeah, you're right it's not that much work (we do this at https://github.com/mysql/mysql-docker/blob/mysql-server/gen_dockerfiles.sh).
@ltangvald is there anything @yosifkit and I can do to help you move this forward and/or support you better? 😄 |
Right now it's hanging on me, so only if you can find some more hours in the day :D |
Commits should resolve all conversations except the one about adding 5.5 and 5.6 to the template. We have this upstream, but the implementation results in chunks of dead code in the entrypoint scripts of the newer versions: https://github.com/mysql/mysql-docker/blob/mysql-server/5.7/docker-entrypoint.sh#L89. I also added one change for storing the root password in a file instead of on the command line, since mysqladmin also needs it. |
So this is ready for review again? Do you want us to wait while you do more work on it (such as consuming #448, MariaDB/mariadb-docker#183, etc)? (Wanting to move this forward if we can 💪) |
@tianon: Sorry, yes, it was meant to be review-ready :) We could add the other issues, but they could just as well be done after, and the templating should make future fixes easier to handle |
@yosifkit Good if you also take a look at the changes :) |
DATADIR="$(docker_get_config 'datadir' "$@")" | ||
|
||
if [ ! -d "$DATADIR/mysql" ]; then | ||
docker_file_env 'MYSQL_ROOT_PASSWORD' |
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.
why not move this block to subroutine as well?
My thoughts are along the lines that maybe this doesn't go far enough with functionalizing the entrypoint. This could be separate discussion, but I think if we are going to create functions in the entrypoint that users can use from initidb.d scripts, then we might as well go all the way to providing a consistent well-reasoned interface. If docker-library/postgres#496 seems reasonable, I'd like to get MySQL (and mariadb + percona) as similar as possible. I am definitely open to suggestions for improvement there; especially if it will make it work better for MySQL. This would allow users more places to hook in customization by sourcing the entrypoint script with their own script without us having to explicitly support more environment variables, an always run initidb.d directory (docker-library/percona#58), or an only run initdb.d (#357, #423). Where can we collaborate to bring to two ideas closer together? Would defining the function list (and possible arguments) be a good place to start? Here is what i have so far in the postgres rework: file_env
docker_create_database_dirs
docker_init_database_dir
docker_print_password_warning
docker_process_init_files
# maybe drop the `p`, or use docker_process_sql or something
docker_psql_run
docker_setup_database
docker_setup_env_vars
# there isn't really a MySQL equivalent of this one, so it should probably be unique to postgres
docker_setup_pg_hba
# perhaps these should be a more generic "docker_temporary_sqlserver_start"
docker_temporary_pgserver_start
docker_temporary_pgserver_stop |
Friendly ping @ltangvald ❤️ |
@tianon Working on moving as much logic as possible into functions, as yosifkit suggests :) |
@ltangvald there's still rather large block in global scope: mysql/.template.Debian/docker-entrypoint.sh Lines 270 to 318 in 94616c4
why not move that into function as well? |
That block is (almost) the entire script; Overriding it essentially means overriding the entire entrypoint. |
imho the only goal should not be override possibility, but code readability too. moving to function is more compact and allows using local variables. with that in mind, i tend to write my shell scripts nowadays as:
|
Yeah, that's a good point. I've added a docker_main function now (there was also a bug with trying to run anything other than mysqld, as it would still try to fetch server config) About local variables: I'm on somewhat shaky ground when it comes to bash scoping, but right now the script relies on global variables, e.g. docker_init_env sets DATADIR and SOCKET, which are used in numerous places. |
I thought about moving the helper functions to another file for postgres, but instead I just hid the main logic in a function and only run that function when the file is not sourced so that a user can source our one file and then choose which pieces they want to run. That way we don't have to worry about telling users about a second file that they can source to get our init steps. # check to see if this file is being run or sourced from another script
 _is_sourced() {
 # https://unix.stackexchange.com/a/215279
 [ "${FUNCNAME[${#FUNCNAME[@]} - 1]}" == 'source' ]
}
_main() {
# init logic
}
if !_is_sourced; then
_main "$@"
} Do you think this would be good to do in the MySQL image too? As for function names and usage, i'm still lining up the MySQL ones with the ones I proposed for PostgreSQL Server so that we can get a unified set (plus custom ones for each). |
I like that Pythonish is_main check ;) I think you're supposed to use |
It should really drop the (But if we're getting that picky, |
…obal for DATADIR SOCKET
- also remove bash generating bash
3b1eeaa
to
91785a5
Compare
Surely, surely, this is ready to go now. Last, little, push ... |
Agreed, let's take this across the finish line and dial in anything else in follow-ups. 👍 (I think we've discussed/evaluated the high level bits enough that we're relatively safe.) |
Changes: - docker-library/mysql@ddf116f: Merge pull request docker-library/mysql#479 from infosiftr/mysql.db-test - docker-library/mysql@0619155: Update "test" database deletion code with extra query from mysql_secure_installation - docker-library/mysql@b5a5d78: Merge pull request docker-library/mysql#471 from ltangvald/refactoring - docker-library/mysql@206541a: Adjust printf to be more resilient; use exit code directly instead of a variable - docker-library/mysql@91785a5: Add --dont-use-mysql-root-password flag for docker_process_sql - docker-library/mysql@8d01eea: Fix source detection for centos, call check_config first, explicit global for DATADIR SOCKET - docker-library/mysql@8a58acb: Adjustments from tianon's comments - docker-library/mysql@169471f: Apply update.sh to update each entrypoint; drop 5.5 from update.sh - docker-library/mysql@06acf82: A few entrypoint updates to increase usability - docker-library/mysql@bbf5d01: Remove empty function docker_wait_for_server - docker-library/mysql@125ac54: Replace function docker_init_client_command with docker_process_sql - docker-library/mysql@964f6c2: Merge function docker_load_tzinfo into docker_setup_db - docker-library/mysql@ce4d14d: Merge function docker_generate_root_password into docker_setup_db - docker-library/mysql@71962c5: Rename function docker_init_database_dir to docker_create_db_directories - docker-library/mysql@04b03e0: Merge functions mysql_write_password_file, docker_init_root_user and docker_setup_db_users into docker_setup_db - docker-library/mysql@880bb34: Rename docker_init_database_user to docker_setup_db_users - docker-library/mysql@dfa4cb4: Rename docker_expire_root_user to mysql_expire_root_user - docker-library/mysql@9b90b1c: Move old-mysql-only logic for waiting for server startup into function - docker-library/mysql@915c792: Rename functions for starting and stopping server - docker-library/mysql@f1abc95: Rename docker_main to _main - docker-library/mysql@c9600d2: Rename log functions from docker to mysql - docker-library/mysql@34ae313: Rename docker_init_env to docker_setup_env - docker-library/mysql@ae7b623: Rename docker_get_config to mysql_get_config - docker-library/mysql@5e10737: Rename docker_write_password_file to mysql_write_password_file - docker-library/mysql@67f2bd3: Rename docker_process_init_file to docker_process_init_files - docker-library/mysql@1503220: Rename docker_verify_env to docker_verify_minimum_env - docker-library/mysql@2fcb086: Rename docker_file_env to file_env - docker-library/mysql@ef9caa9: Rename docker_check_config to mysql_check_config - docker-library/mysql@9f77ea5: entrypoint: Make value checks more consistent - docker-library/mysql@33ba3e5: entrypoint: Only execute main function if the script is not sourced - docker-library/mysql@db2319e: entrypoint: Move main script functionality to function - docker-library/mysql@f9c185f: entrypoint: Move more logic into functions - docker-library/mysql@db12713: entrypoint: Use mktemp instead of install - docker-library/mysql@4672559: Prefix function names in entrypoint with "docker" - docker-library/mysql@eb2821b: Fix typo templaing->templating - docker-library/mysql@2242976: Move flag for password file to when the client command is first defined - docker-library/mysql@03bdbad: Add 5.5 and 5.6 to entrypoint templating - docker-library/mysql@a9e8576: Template: Use --daemonize for temporary server startup. - docker-library/mysql@9e51c81: Template: Use mysqladmin to stop temporary server - docker-library/mysql@ea73775: Template: Store root password in file - docker-library/mysql@a8aa1cf: Template: Create logging functions - docker-library/mysql@34f3ef2: Template: Rename template directory to be hidden - docker-library/mysql@afceb7f: Template: Create functions for starting and stopping server during init - docker-library/mysql@5a727ad: Make template for 5.7+ entrypoint script - docker-library/mysql@f16150e: Unify entrypoint scripts for 5.7 and 8.0 - docker-library/mysql@d56d41d: Update generated README - docker-library/mysql@68f5102: Merge pull request docker-library/mysql#580 from J0WI/https-update - docker-library/mysql@0f33848: Use https in update.sh
Changes: - docker-library/mysql@305192d: Merge pull request docker-library/mysql#599 from infosiftr/really_sourced - docker-library/mysql@2501cf3: Improve _is_sourced check - docker-library/mysql@ddf116f: Merge pull request docker-library/mysql#479 from infosiftr/mysql.db-test - docker-library/mysql@0619155: Update "test" database deletion code with extra query from mysql_secure_installation - docker-library/mysql@b5a5d78: Merge pull request docker-library/mysql#471 from ltangvald/refactoring - docker-library/mysql@206541a: Adjust printf to be more resilient; use exit code directly instead of a variable - docker-library/mysql@91785a5: Add --dont-use-mysql-root-password flag for docker_process_sql - docker-library/mysql@8d01eea: Fix source detection for centos, call check_config first, explicit global for DATADIR SOCKET - docker-library/mysql@8a58acb: Adjustments from tianon's comments - docker-library/mysql@169471f: Apply update.sh to update each entrypoint; drop 5.5 from update.sh - docker-library/mysql@06acf82: A few entrypoint updates to increase usability - docker-library/mysql@bbf5d01: Remove empty function docker_wait_for_server - docker-library/mysql@125ac54: Replace function docker_init_client_command with docker_process_sql - docker-library/mysql@964f6c2: Merge function docker_load_tzinfo into docker_setup_db - docker-library/mysql@ce4d14d: Merge function docker_generate_root_password into docker_setup_db - docker-library/mysql@71962c5: Rename function docker_init_database_dir to docker_create_db_directories - docker-library/mysql@04b03e0: Merge functions mysql_write_password_file, docker_init_root_user and docker_setup_db_users into docker_setup_db - docker-library/mysql@880bb34: Rename docker_init_database_user to docker_setup_db_users - docker-library/mysql@dfa4cb4: Rename docker_expire_root_user to mysql_expire_root_user - docker-library/mysql@9b90b1c: Move old-mysql-only logic for waiting for server startup into function - docker-library/mysql@915c792: Rename functions for starting and stopping server - docker-library/mysql@f1abc95: Rename docker_main to _main - docker-library/mysql@c9600d2: Rename log functions from docker to mysql - docker-library/mysql@34ae313: Rename docker_init_env to docker_setup_env - docker-library/mysql@ae7b623: Rename docker_get_config to mysql_get_config - docker-library/mysql@5e10737: Rename docker_write_password_file to mysql_write_password_file - docker-library/mysql@67f2bd3: Rename docker_process_init_file to docker_process_init_files - docker-library/mysql@1503220: Rename docker_verify_env to docker_verify_minimum_env - docker-library/mysql@2fcb086: Rename docker_file_env to file_env - docker-library/mysql@ef9caa9: Rename docker_check_config to mysql_check_config - docker-library/mysql@9f77ea5: entrypoint: Make value checks more consistent - docker-library/mysql@33ba3e5: entrypoint: Only execute main function if the script is not sourced - docker-library/mysql@db2319e: entrypoint: Move main script functionality to function - docker-library/mysql@f9c185f: entrypoint: Move more logic into functions - docker-library/mysql@db12713: entrypoint: Use mktemp instead of install - docker-library/mysql@4672559: Prefix function names in entrypoint with "docker" - docker-library/mysql@eb2821b: Fix typo templaing->templating - docker-library/mysql@2242976: Move flag for password file to when the client command is first defined - docker-library/mysql@03bdbad: Add 5.5 and 5.6 to entrypoint templating - docker-library/mysql@a9e8576: Template: Use --daemonize for temporary server startup. - docker-library/mysql@9e51c81: Template: Use mysqladmin to stop temporary server - docker-library/mysql@ea73775: Template: Store root password in file - docker-library/mysql@a8aa1cf: Template: Create logging functions - docker-library/mysql@34f3ef2: Template: Rename template directory to be hidden - docker-library/mysql@afceb7f: Template: Create functions for starting and stopping server during init - docker-library/mysql@5a727ad: Make template for 5.7+ entrypoint script - docker-library/mysql@f16150e: Unify entrypoint scripts for 5.7 and 8.0 - docker-library/mysql@d56d41d: Update generated README - docker-library/mysql@68f5102: Merge pull request docker-library/mysql#580 from J0WI/https-update - docker-library/mysql@0f33848: Use https in update.sh
Changes: - docker-library/mysql@5fa3526: Update to 5.7.28-1debian9 - docker-library/mysql@49bedb5: Update to 5.6.46-1debian9 - docker-library/mysql@367788b: Update to 8.0.18-1debian9 - docker-library/mysql@305192d: Merge pull request docker-library/mysql#599 from infosiftr/really_sourced - docker-library/mysql@2501cf3: Improve _is_sourced check - docker-library/mysql@ddf116f: Merge pull request docker-library/mysql#479 from infosiftr/mysql.db-test - docker-library/mysql@0619155: Update "test" database deletion code with extra query from mysql_secure_installation - docker-library/mysql@b5a5d78: Merge pull request docker-library/mysql#471 from ltangvald/refactoring - docker-library/mysql@206541a: Adjust printf to be more resilient; use exit code directly instead of a variable - docker-library/mysql@91785a5: Add --dont-use-mysql-root-password flag for docker_process_sql - docker-library/mysql@8d01eea: Fix source detection for centos, call check_config first, explicit global for DATADIR SOCKET - docker-library/mysql@8a58acb: Adjustments from tianon's comments - docker-library/mysql@169471f: Apply update.sh to update each entrypoint; drop 5.5 from update.sh - docker-library/mysql@06acf82: A few entrypoint updates to increase usability - docker-library/mysql@bbf5d01: Remove empty function docker_wait_for_server - docker-library/mysql@125ac54: Replace function docker_init_client_command with docker_process_sql - docker-library/mysql@964f6c2: Merge function docker_load_tzinfo into docker_setup_db - docker-library/mysql@ce4d14d: Merge function docker_generate_root_password into docker_setup_db - docker-library/mysql@71962c5: Rename function docker_init_database_dir to docker_create_db_directories - docker-library/mysql@04b03e0: Merge functions mysql_write_password_file, docker_init_root_user and docker_setup_db_users into docker_setup_db - docker-library/mysql@880bb34: Rename docker_init_database_user to docker_setup_db_users - docker-library/mysql@dfa4cb4: Rename docker_expire_root_user to mysql_expire_root_user - docker-library/mysql@9b90b1c: Move old-mysql-only logic for waiting for server startup into function - docker-library/mysql@915c792: Rename functions for starting and stopping server - docker-library/mysql@f1abc95: Rename docker_main to _main - docker-library/mysql@c9600d2: Rename log functions from docker to mysql - docker-library/mysql@34ae313: Rename docker_init_env to docker_setup_env - docker-library/mysql@ae7b623: Rename docker_get_config to mysql_get_config - docker-library/mysql@5e10737: Rename docker_write_password_file to mysql_write_password_file - docker-library/mysql@67f2bd3: Rename docker_process_init_file to docker_process_init_files - docker-library/mysql@1503220: Rename docker_verify_env to docker_verify_minimum_env - docker-library/mysql@2fcb086: Rename docker_file_env to file_env - docker-library/mysql@ef9caa9: Rename docker_check_config to mysql_check_config - docker-library/mysql@9f77ea5: entrypoint: Make value checks more consistent - docker-library/mysql@33ba3e5: entrypoint: Only execute main function if the script is not sourced - docker-library/mysql@db2319e: entrypoint: Move main script functionality to function - docker-library/mysql@f9c185f: entrypoint: Move more logic into functions - docker-library/mysql@db12713: entrypoint: Use mktemp instead of install - docker-library/mysql@4672559: Prefix function names in entrypoint with "docker" - docker-library/mysql@eb2821b: Fix typo templaing->templating - docker-library/mysql@2242976: Move flag for password file to when the client command is first defined - docker-library/mysql@03bdbad: Add 5.5 and 5.6 to entrypoint templating - docker-library/mysql@a9e8576: Template: Use --daemonize for temporary server startup. - docker-library/mysql@9e51c81: Template: Use mysqladmin to stop temporary server - docker-library/mysql@ea73775: Template: Store root password in file - docker-library/mysql@a8aa1cf: Template: Create logging functions - docker-library/mysql@34f3ef2: Template: Rename template directory to be hidden - docker-library/mysql@afceb7f: Template: Create functions for starting and stopping server during init - docker-library/mysql@5a727ad: Make template for 5.7+ entrypoint script - docker-library/mysql@f16150e: Unify entrypoint scripts for 5.7 and 8.0 - docker-library/mysql@d56d41d: Update generated README - docker-library/mysql@68f5102: Merge pull request docker-library/mysql#580 from J0WI/https-update - docker-library/mysql@0f33848: Use https in update.sh
👏 |
Changes: - docker-library/postgres@5beb1d4: Update to 9.4.25-1.pgdg90+1 - docker-library/postgres@a0ec4f5: Update to 9.5.20 - docker-library/postgres@6dfdc0e: Update to 11.6 - docker-library/postgres@2addeda: Update to 11.6-1.pgdg90+1 - docker-library/postgres@f13fbe5: Update to 9.6.16-1.pgdg90+1 - docker-library/postgres@f2596e6: Update to 10.11-1.pgdg90+1 - docker-library/postgres@c1e547b: Update to 10.11 - docker-library/postgres@cac7a60: Update to 9.6.16 - docker-library/postgres@1d43a9d: Update to 12.1 - docker-library/postgres@06a831c: Update to 9.5.20-1.pgdg90+1 - docker-library/postgres@138e959: Update to 9.4.25 - docker-library/postgres@4a82eb9: Update to 12.1-1.pgdg100+1 - docker-library/postgres@0c29c35: Merge pull request docker-library/postgres#496 from infosiftr/functionalization - docker-library/postgres@8fada98: Fixes from tianon's review - docker-library/postgres@7c84645: Apply update.sh for new entrypoint - docker-library/postgres@d1cc089: Improve _is_sourced check - docker-library/postgres@6e85168: Resync function interfaces with MySQL, improve comments - docker-library/postgres@2e70e71: Apply function name changes as discussed in docker-library/mysql#471 - docker-library/postgres@49fb876: Namespace functions for less conflict when sourced - docker-library/postgres@48f2ad1: Functionalize the entrypoint to allow outside sourcing for extreme customizing of startup
Note: May want to split this up, but putting everything in a single request for any discussions that may arise.
Unifies the entrypoint scripts for 5.7 and 8.0, since they do not need to be different at all, and adds them to a debian template that is copied into each directory by update.sh
Also refactors the entrypoint script by moving logic for starting and stopping the server into functions and adding timestamps and error levels to the echo lines.
Closes #490