diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..79ecd2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +### MacOS + +.DS_Store diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..171763c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM docker:stable + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index e26f2bd..368d1c7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,23 @@ -# mysql-action -GitHub Action to setup a MySQL database +# MySQL GitHub Action + +This [GitHub Action](https://github.com/features/actions) sets up a MySQL database. + +## Usage + +```yaml +steps: +- uses: mirromutth/mysql-action@v1 + with: + mysql password: ${{ secrets.databasePassword }} # Required, the password of the superuser for the specified database + mysql user: 'developer' # Optional, default value is "test", the superuser for the specified database. Of course you can use secrets, too + mysql version: '8.0' # Optional, default value is "latest", the version of the MySQL in Docker + mysql database: 'some_test' # Optional, default value is "test", the specified database which will be create +``` + +See [Docker Hub](https://hub.docker.com/_/mysql) for available versions. + +See [Creating and using secrets (encrypted variables)](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) for hiding database password. + +## License + +This project is released under the [MIT License](LICENSE). diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..a3e8f54 --- /dev/null +++ b/action.yml @@ -0,0 +1,26 @@ +name: 'Setup MySQL' +description: 'Setup a MySQL database' +author: 'Mirro Mutth' +branding: + icon: 'database' + color: 'orange' +inputs: + # See https://hub.docker.com/_/mysql for supported versions and further details on input environment variables + mysql version: + description: 'Version of MySQL to use' + required: false + default: 'latest' + mysql database: + description: 'MYSQL_DATABASE - name for the default database that is created' + required: false + default: 'test' + mysql user: + description: 'MYSQL_USER - create the specified user with superuser power for created database' + required: false + default: 'test' + mysql password: + description: 'MYSQL_PASSWORD - superuser password' + required: true +runs: + using: 'docker' + image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..a3cda84 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,9 @@ +#!/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" + +sh -c "$docker_run"