Skip to content

Commit

Permalink
Supports more options
Browse files Browse the repository at this point in the history
Now supports root superuser, ports and charset options.
  • Loading branch information
mirromutth committed Sep 6, 2019
1 parent 9e1c6ff commit 73a5ef7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
30 changes: 25 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
33 changes: 28 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 73a5ef7

Please sign in to comment.