-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95cb320
commit edb566f
Showing
6 changed files
with
455 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,21 @@ | |
|
||
[GitHub Actions](https://help.github.com/en/articles/about-github-actions) provides the flexibility to build automated workflows for the software development lifecycle. | ||
|
||
GitHub Actions can be used to automate the workflow of creating a new revision of [Azure Container App](https://azure.microsoft.com/en-us/services/container-apps/). | ||
The aca-review-app runs the code contained in the GitHub pull request as an app in the Container App. The review app 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. | ||
**aca-review-app** can be used to automate the workflow of creating a new revision of [Azure Container App](https://azure.microsoft.com/en-us/services/container-apps/) 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. | ||
|
||
Review apps can also be configured to launch automatically with each pull request. Also, when combined with `peter-evans/create-or-update-comment@v2` or similar, you can not only create a revision, but also comment the URL of the created Revision in the Pull Request. | ||
<img width="640" alt="image" src="https://user-images.githubusercontent.com/15963767/195657236-54a6af81-61a2-4638-81c9-5e2313ddd6ed.png"> | ||
|
||
**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](./example/). | ||
|
||
Let's get started today with a [free Azure account](https://azure.com/free/open-source)! | ||
|
||
The definition of this GitHub Action is in [action.yml](./action.yml). | ||
|
||
## End-to-End Sample Workflows | ||
|
||
The **[```example/```](./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](https://github.com/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. | ||
|
@@ -55,98 +59,65 @@ For using any credentials like Azure Service Principal in your workflow, add the | |
|
||
1. 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) | ||
|
||
### Build and Deploy a Node.JS App to Azure Container App | ||
### Integration to leave comments on Pull Request | ||
|
||
```yaml | ||
#### Sample Snipet for the Review Revision Creation | ||
|
||
on: [push] | ||
name: Linux_Container_Workflow | ||
You can pass the app URL for review to subsequent actions as follows. | ||
|
||
SAMPLE WORKFLOW WILL BE HERE | ||
```yaml | ||
- name: Add revision to ACA | ||
uses: Azure/[email protected] | ||
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 }} | ||
``` | ||
### Example YAML Snippets | ||
|
||
#### Basic sample to create a revision | ||
#### Sample Snipet for the Review Revision Deactivation | ||
```yaml | ||
on: [push, pull_request] | ||
name: Preview Deployment | ||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
env: | ||
RESOURCE_GROUP: <YOUR_RESOURCE_GROUP_NAME> | ||
CONTAINER_APP_NAME: <YOUR_CONTAINER_APP_NAME> | ||
DOCKER_IMAGE_NAME: <YOUR_DOCKER_IMAGE_NAME> | ||
# REVISION_NAME_SUFFIX: <YOUR_REVISION_NAME_SUFFIX> # Optional: Default is github commit hash | ||
steps: | ||
- name: 'Checkout GitHub Action' | ||
uses: actions/checkout@master | ||
- name: 'Login via Azure CLI' | ||
uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZURE_CREDENTIALS }} | ||
- name: 'Create a new Container App revision' | ||
uses: azure/[email protected] | ||
with: | ||
resource-group: ${{ env.RESOURCE_GROUP }} | ||
name: ${{ env.CONTAINER_APP_NAME }} | ||
image: ${{ env.DOCKER_IMAGE_NAME }} | ||
``` | ||
##### Using customize suffice instead of git commit hash | ||
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](./example/) implementation. | ||
```yaml | ||
- name: 'Create a new Container App revision' | ||
uses: azure/aca-preview@v0.1 | ||
- name: Deactivate Preview revision on ACA | ||
uses: Azure/aca-review-apps@v0.2.0 | ||
with: | ||
resource-group: ${{ env.RESOURCE_GROUP }} | ||
name: ${{ env.CONTAINER_APP_NAME }} | ||
image: ${{ env.DOCKER_IMAGE_NAME }} | ||
revision-name-suffix: ${{ env.REVISION_NAME_SUFFIX }} | ||
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. | ||
|
||
#### Create and Deactivate an action | ||
```yaml | ||
on: [push, pull_request] | ||
name: Preview Deployment | ||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
env: | ||
RESOURCE_GROUP: <YOUR_RESOURCE_GROUP_NAME> | ||
CONTAINER_APP_NAME: <YOUR_CONTAINER_APP_NAME> | ||
DOCKER_IMAGE_NAME: <YOUR_DOCKER_IMAGE_NAME> | ||
steps: | ||
- name: 'Checkout GitHub Action' | ||
uses: actions/checkout@master | ||
- name: 'Login via Azure CLI' | ||
uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZURE_CREDENTIALS }} | ||
# Revision Creation | ||
- name: 'Create a new Container App revision' | ||
uses: azure/[email protected] | ||
with: | ||
resource-group: ${{ env.RESOURCE_GROUP }} | ||
name: ${{ env.CONTAINER_APP_NAME }} | ||
image: ${{ env.DOCKER_IMAGE_NAME }} | ||
# Revision Deactivation | ||
- name: Deactivate Preview Deployment | ||
if: github.event.action == 'closed' | ||
uses: azure/[email protected] | ||
with: | ||
deactivate-revision-mode: ture | ||
resource-group: ${{ env.RESOURCE_GROUP }} | ||
name: ${{ env.CONTAINER_APP_NAME }} | ||
image: ${{ env.DOCKER_IMAGE_NAME }} | ||
- 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 | ||
### How to Develop/Test this Action | ||
#### Debug with breakpoints on Visual Studio Code | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
example/.github/workflows/build-deploy-deactivate-revision.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
name: Build, Deploy and Deactivate ACA revision | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, closed] | ||
|
||
permissions: | ||
# for `create-or-update-comment` action | ||
pull-requests: write | ||
issues: write | ||
|
||
# for Azure login with OIDC | ||
# id-token: write | ||
|
||
env: | ||
CONTAINER_REGISTRY: acracapreview.azurecr.io # TODO: container registry name like `foobar.azurecr.io` | ||
RESOURCE_GROUP_NAME: aca-preview-hands-on-rg # TODO: resource group name where the target Azure Container Apps resource in | ||
CONTAINERAPP_NAME: aca-preview-app # TODO: Azure Container Apps resource name | ||
|
||
jobs: | ||
add-revision: | ||
runs-on: ubuntu-18.04 | ||
if: github.event.action != 'closed' | ||
|
||
steps: | ||
- name: Checkout to the branch | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Set repository name to env | ||
run: | | ||
echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" >> $GITHUB_ENV | ||
echo "SHORT_HASH=${COMMIT_HASH:0:7}" >> $GITHUB_ENV | ||
env: | ||
COMMIT_HASH: ${{ github.event.pull_request.head.sha }} | ||
|
||
- name: Log in to container registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ${{ env.CONTAINER_REGISTRY }} | ||
username: ${{ secrets.CONTAINER_REGISTRY_USERNAME }} | ||
password: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }} | ||
|
||
- name: Build and push container image to registry | ||
uses: docker/build-push-action@v2 | ||
with: | ||
push: true | ||
tags: ${{ env.CONTAINER_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ github.event.pull_request.head.sha }} | ||
file: ./Dockerfile | ||
context: ./ | ||
|
||
- name: Azure Login | ||
uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZURE_CREDENTIALS }} | ||
|
||
- name: Add revision to ACA | ||
uses: Azure/[email protected] | ||
id: aca_new_revision | ||
with: | ||
resource-group: ${{ env.RESOURCE_GROUP_NAME }} | ||
name: ${{ env.CONTAINERAPP_NAME }} | ||
revision-name-suffix: ${{ env.SHORT_HASH }} | ||
image: ${{ env.CONTAINER_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ github.event.pull_request.head.sha }} | ||
|
||
- 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 }} | ||
deactivate-revision: | ||
runs-on: ubuntu-18.04 | ||
if: github.event.action != 'opened' | ||
|
||
steps: | ||
- name: Set short version of Commit hash to env | ||
run: | | ||
echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" >> $GITHUB_ENV | ||
echo "SHORT_HASH=${COMMIT_HASH:0:7}" >> $GITHUB_ENV | ||
env: | ||
COMMIT_HASH: | | ||
${{ | ||
github.event.action == 'closed' && github.event.pull_request.head.sha || | ||
github.event.action == 'synchronize' && github.event.before | ||
}} | ||
- name: Azure Login | ||
uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZURE_CREDENTIALS }} | ||
|
||
- name: Deactivate Preview revision on ACA | ||
uses: Azure/[email protected] | ||
with: | ||
resource-group: ${{ env.RESOURCE_GROUP_NAME }} | ||
name: ${{ env.CONTAINERAPP_NAME }} | ||
revision-name-suffix: ${{ env.SHORT_HASH }} | ||
deactivate-revision-mode: true | ||
image: "THIS_VALUE_IS_IGNORED_IN_DEACTIVATION_MODE" | ||
|
||
- 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM mcr.microsoft.com/azuredocs/containerapps-helloworld:latest |
Oops, something went wrong.