Automate your GitHub workflows using Azure Action for MySQL
Перейти к файлу
aksm-ms ccc25d2410
Make database parameter optional. (#22) (#23)
By making the database optional opens the scenario where we just want
to issue commands on the server (eg: to create a database),

- Fix: If the database name had spaces `mysql` call would fail
- Pass the password as an environment variable instead of command line.
Eliminates warning that password method passing is insecure.
2020-10-14 15:18:25 +05:30
lib Make database parameter optional. (#22) (#23) 2020-10-14 15:18:25 +05:30
node_modules Bump @actions/core from 1.2.0 to 1.2.6 (#21) 2020-10-08 20:11:29 +05:30
src Make database parameter optional. (#22) (#23) 2020-10-14 15:18:25 +05:30
.gitignore Azure MySql action v1 (#6) 2019-11-05 13:43:02 +05:30
CODE_OF_CONDUCT.md Initial commit 2019-09-25 01:20:47 -07:00
LICENSE Initial commit 2019-09-25 01:20:48 -07:00
README.md Merging azure login mandate fix (#17) 2020-09-22 09:29:18 +05:30
SECURITY.md Initial commit 2019-09-25 01:20:49 -07:00
action.yml update yml description (#2) 2019-11-05 08:40:18 +05:30
jest.config.js Azure MySQL Action (#1) 2019-11-01 14:46:53 +05:30
package-lock.json Bump @actions/core from 1.2.0 to 1.2.6 (#21) 2020-10-08 20:11:29 +05:30
package.json Bump @actions/core from 1.2.0 to 1.2.6 (#21) 2020-10-08 20:11:29 +05:30
tsconfig.json Azure MySQL Action (#1) 2019-11-01 14:46:53 +05:30

README.md

GitHub Action for deploying updates to Azure Database for MySQL server

With the Azure MySQL Action for GitHub, you can automate your workflow to deploy updates to Azure Database for MySQL server.

Get started today with a free Azure account!

This repository contains GitHub Action for Azure database for MySQL server to deploy .

The action uses Connection String for authentication and SQL scripts to deploy to your MySQL database.

If you are looking for more Github Actions to deploy code or a customized image into an Azure Webapp or a Kubernetes service, consider using Azure Actions.

The definition of this Github Action is in action.yml.

End-to-End Sample Workflow

Dependencies on other Github Actions

For the action to run, the IP Address of the GitHub Action runner (automation agent) must be added to the 'Allowed IP Addresses' by setting MySQL server firewall rules in Azure. Without the firewall rules, the runner cannot communicate with Azure database for MySQL.

By default, the action would auto-detect the IP Address of the runner to automatically add firewall exception rule. These firewall rules will be deleted after the action executes.

However, this auto-provisioning of firewall rules needs a pre-req that the workflow includes an azure/login@v1 action before the azure/mysql-action@v1 action. Also, the service principal used in the Azure login action needs to have elevated permissions, i.e. membership in SQL Security Manager RBAC role, or a similarly high permission in the database to create the firewall rule.

Alternatively, if enough permissions are not granted on the service principal or login action is not included, then the firewall rules have to be explicitly managed by user using CLI/PS scripts.

Create an Azure database for MySQL server and deploy using GitHub Actions

  1. Follow the tutorial Azure Database for MySQL server Quickstart
  2. Pick the MySQL-on-Azure.yml template from https://github.com/Azure/actions-workflow-samples and place the template into .github/workflows/ within your project repository.
  3. Change server-name to your Azure MySQL Server name.
  4. Commit and push your project to GitHub repository, you should see a new GitHub Action initiated in Actions tab.

Configure GitHub Secrets with Azure Credentials and MySQL Connection Strings

For using any sensitive data/secrets like Azure Service Principal or MySQL Connection strings within an Action, add them as secrets in the GitHub repository and then use them in the workflow.

Follow the steps to configure the secret:

  • Define a new secret under your repository Settings > Secrets > Add a new secret menu
  • Paste the contents of the Secret (Example: Connection String) as Value
  • For Azure credentials, paste the output of the below az cli command as the value of secret variable, for example 'AZURE_CREDENTIALS'

   az ad sp create-for-rbac --name {server-name} --role contributor \
                            --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group} \
                            --sdk-auth
                            
  # Replace {subscription-id}, {resource-group} and {server-name} with the subscription, resource group and name of the Azure MySQL server
  
  # The command should output a JSON object similar to this:

  {
    "clientId": "<GUID>",
    "clientSecret": "<GUID>",
    "subscriptionId": "<GUID>",
    "tenantId": "<GUID>",
    (...)
  }
  

Sample workflow to deploy to an Azure database for MySQL server

# .github/workflows/mysql-deploy.yml
on: [push]

jobs:
  build:
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v1
    - uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}
    - uses: azure/mysql@v1
      with:
        server-name: REPLACE_THIS_WITH_YOUR_MYSQL_SERVER_NAME
        connection-string: ${{secrets.AZURE_MYSQL_CONNECTION_STRING }}
        sql-file: './sqlFile.sql'

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.