Enable GitHub developers to create a new revision of Azure Container App for review by using GitHub Actions
Перейти к файлу
dependabot[bot] f79816d55a
Bump technote-space/release-github-actions from 8.0.1 to 8.0.2
Bumps [technote-space/release-github-actions](https://github.com/technote-space/release-github-actions) from 8.0.1 to 8.0.2.
- [Release notes](https://github.com/technote-space/release-github-actions/releases)
- [Changelog](https://github.com/technote-space/release-github-actions/blob/main/.releasegarc)
- [Commits](https://github.com/technote-space/release-github-actions/compare/v8.0.1...v8.0.2)

---
updated-dependencies:
- dependency-name: technote-space/release-github-actions
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-06 19:08:52 +00:00
.act Add .env and .secret sample for local runner 2022-09-16 19:16:35 +09:00
.devcontainer enable dind, add act 2022-09-12 11:39:26 +00:00
.github Bump technote-space/release-github-actions from 8.0.1 to 8.0.2 2022-12-06 19:08:52 +00:00
.vscode Edit comments and format 2022-09-16 19:19:22 +09:00
example Update README and example for marketplace release 2022-10-14 01:32:15 +09:00
lib Remove build artifact files 2022-09-05 13:28:00 +09:00
src Fix max revision name length 2022-09-27 05:42:54 +00:00
.gitignore Update .gitignore 2022-09-16 19:19:50 +09:00
.prettierignore init 2022-09-04 10:38:03 +09:00
CODE_OF_CONDUCT.md CODE_OF_CONDUCT.md committed 2022-09-03 18:36:16 -07:00
LICENSE LICENSE committed 2022-09-03 18:36:13 -07:00
README.md Update README.md 2022-10-14 01:50:29 +09:00
SECURITY.md Resolve duplicate basic files 2022-09-04 20:32:34 +09:00
SUPPORT.md SUPPORT.md committed 2022-09-03 18:36:17 -07:00
action.yml Update action.yml 2022-10-26 23:42:30 +09:00
azure-logo.svg Update Azure logo svg and action.yml setting 2022-09-05 13:01:23 +09:00
package-lock.json Update version to 0.2.0 #56 2022-09-27 15:47:10 +09:00
package.json Update version to 0.2.0 #56 2022-09-27 15:47:10 +09:00
tsconfig.json fix for local debugging 2022-09-12 03:50:30 +00:00

README.md

GitHub Action for Creating Azure Container App Revision

GitHub Actions provides the flexibility to build automated workflows for the software development lifecycle.

aca-review-app can be used to automate the workflow of creating a new revision of Azure Container App for review. This action runs the code contained in the GitHub pull request as an app in the Container App. The review application is then created as a new revision with a Weight of 0, each with a unique URL that can be shared. This is a great way to review and test code changes. This action allows deactivating an app for review that has been created, triggered by the close of a pull request.

image

aca-review-app can also be configured to launch automatically with each pull request. By integrating with other github actions, it is also possible not only to create revisions, but also to comment the URL of the created revision in a pull request. For more information, please refer to the eample workflow.

Let's get started today with a free Azure account!

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

End-to-End Sample Workflows

The example/ in this repository contains a sample project to get started. Please read the hands-on documentation and start building.

Dependencies on other GitHub Actions

  • Azure Login Login with your Azure Credentials for Authentication. Once login is done, the next set of Azure Actions in the workflow can re-use the same session within the job.

Azure Service Principal for RBAC

For using any credentials like Azure Service Principal in your workflow, add them as secrets in the GitHub Repository and then refer them in the workflow.

  1. Download Azure CLI from here, run az login to login with your Azure Credentials.
  2. Run Azure CLI command to create an Azure Service Principal for RBAC:
    az ad sp create-for-rbac --name "myApp" --role contributor \
                             --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group} \
                             --sdk-auth

    # Replace {subscription-id}, {resource-group} with the subscription, resource group details of the WebApp
    # The command should output a JSON object similar to this:

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

* You can further scope down the Azure Credentials to the Web App using scope attribute. For example,

 az ad sp create-for-rbac --name "myApp" --role contributor \
                          --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Web/sites/{app-name} \
                          --sdk-auth

# Replace {subscription-id}, {resource-group}, and {app-name} with the names of your subscription, resource group, and Azure Web App.
  1. Paste the json response from above Azure CLI to your GitHub Repository > Settings > Secrets > Add a new secret > AZURE_CREDENTIALS

  2. Now in the workflow file in your branch: .github/workflows/workflow.yml replace the secret in Azure login action with your secret (Refer to the example below)

Integration to leave comments on Pull Request

Sample Snipet for the Review Revision Creation

You can pass the app URL for review to subsequent actions as follows.

- name: Add revision to ACA
  uses: Azure/aca-review-apps@v0.2.0
  id: aca_new_revision
  with:
    resource-group: <YOUR_RESOURCE_GROUP>
    name: <YOUR_CONTAINER_APP_NAME>
    revision-name-suffix: <SHORT_HASH>
    image: <YOUR_CONTAINER_IMAGE>

- name: add new comment to PR
  uses: peter-evans/create-or-update-comment@v2
  with:
    issue-number: ${{ github.event.pull_request.number }}
    body: |
      Revision ${{ env.CONTAINERAPP_NAME }}--${{ env.SHORT_HASH }} is created.
      ${{ steps.aca_new_revision.outputs.app-url }}      

Sample Snipet for the Review Revision Deactivation

This action can also automatically deactivate revisions. However, this flow must be triggered only when the pull request is closed. For more information, see the sample implementation.

- name: Deactivate Preview revision on ACA
  uses: Azure/aca-review-apps@v0.2.0
  with:
    resource-group: <YOUR_RESOURCE_GROUP>
    name: <YOUR_CONTAINER_APP_NAME>
    revision-name-suffix: <SHORT_HASH>
    image: <YOUR_CONTAINER_IMAGE>
    deactivate-revision-mode: true #IMPORTANT!!

- name: Find Comment
  uses: peter-evans/find-comment@v2
  id: fc
  with:
    issue-number: ${{ github.event.pull_request.number }}
    comment-author: "github-actions[bot]"
    body-includes: Revision ${{ env.CONTAINERAPP_NAME }}--${{ env.SHORT_HASH }} is created.

- name: add new comment to PR
  if: steps.fc.outputs.comment-id != ''
  uses: peter-evans/create-or-update-comment@v2
  with:
    comment-id: ${{ steps.fc.outputs.comment-id }}
    edit-mode: replace
    body: |
      Revision ${{ env.CONTAINERAPP_NAME }}--${{ env.SHORT_HASH }} is deactivated.      

How to Develop/Test this Action

Debug with breakpoints on Visual Studio Code

This action can be tried on not only GitHub Actions workflow but also your local PC or GitHub Codespaces.

If you use Visual Studio Code, debugging this action with breakpoints can be used by running Launch Program configuration. image

Check workflow behavior without pushing to GitHub

Also, you can try to run your workflow with this action by executing npm run act on Visual Studio Code Remote-Container extension or GitHub Codespaces without pushing it to GitHub, because a devcontainer image for this repository includes Docker-in-Docker enabled devcontainer and act.

For more detail, refer to following links.

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.