diff --git a/action.yml b/action.yml index a3e8f54..5aa2617 100644 --- a/action.yml +++ b/action.yml @@ -5,22 +5,42 @@ branding: icon: 'database' color: 'orange' inputs: - # See https://hub.docker.com/_/mysql for supported versions and further details on input environment variables + host port: + description: 'The port of host' + required: false + default: 3306 + container port: + description: 'The port of container' + required: false + default: 3306 + character set server: + description: '--character-set-server - The character set of MySQL server' + required: false + default: 'utf8mb4' + collation server: + description: '--collation-server - The character collation of MySQL server' + required: false + default: 'utf8mb4_general_ci' mysql version: description: 'Version of MySQL to use' required: false default: 'latest' + mysql root password: + description: 'MYSQL_ROOT_PASSWORD - root superuser password' + required: false + default: '' mysql database: description: 'MYSQL_DATABASE - name for the default database that is created' required: false - default: 'test' + default: '' mysql user: description: 'MYSQL_USER - create the specified user with superuser power for created database' required: false - default: 'test' + default: '' mysql password: - description: 'MYSQL_PASSWORD - superuser password' - required: true + description: 'MYSQL_PASSWORD - specified superuser password which user is power for created database' + required: false + default: '' runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index a3cda84..bc1d184 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,9 +1,32 @@ #!/bin/sh -docker_run="docker run -e MYSQL_RANDOM_ROOT_PASSWORD=true" -docker_run="$docker_run -e MYSQL_DATABASE=$INPUT_MYSQL_DATABASE" -docker_run="$docker_run -e MYSQL_USER=$INPUT_MYSQL_USER" -docker_run="$docker_run -e MYSQL_PASSWORD=$INPUT_MYSQL_PASSWORD" -docker_run="$docker_run -d -p 3306:3306 mysql:$INPUT_MYSQL_VERSION" +docker_run="docker run" + +if [ -n "$INPUT_MYSQL_ROOT_PASSWORD" ]; then + echo "Root password not empty, use root superuser" + + docker_run="$docker_run -e MYSQL_ROOT_PASSWORD=$INPUT_MYSQL_ROOT_PASSWORD" +elif [ -n "$INPUT_MYSQL_USER" ]; then + if [ -z "$INPUT_MYSQL_PASSWORD" ]; then + echo "The mysql password must not be empty when mysql user exists" + exit 1 + fi + + echo "Use specified user and password" + + docker_run="$docker_run -e MYSQL_RANDOM_ROOT_PASSWORD=true -e MYSQL_USER=$INPUT_MYSQL_USER -e MYSQL_PASSWORD=$INPUT_MYSQL_PASSWORD" +else + echo "Both root password and superuser are empty, must contains one superuser" + exit 1 +fi + +if [ -n "$INPUT_MYSQL_DATABASE" ]; then + echo "Use specified database" + + docker_run="$docker_run -e MYSQL_DATABASE=$INPUT_MYSQL_DATABASE" +fi + +docker_run="$docker_run -d -p $INPUT_HOST_PORT:$INPUT_CONTAINER_PORT mysql:$INPUT_MYSQL_VERSION --port=$INPUT_CONTAINER_PORT" +docker_run="$docker_run --character-set-server=$INPUT_CHARACTER_SET_SERVER --collation-server=$INPUT_COLLATION_SERVER" sh -c "$docker_run"