-
Notifications
You must be signed in to change notification settings - Fork 0
Added spinup-destroy.yml workflow #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| name: Configure Azure environment | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [labeled] | ||
|
|
||
| env: | ||
| IMAGE_REGISTRY_URL: ghcr.io | ||
| AZURE_RESOURCE_GROUP: cd-with-actions | ||
| AZURE_APP_PLAN: actions-ttt-deployment | ||
| AZURE_LOCATION: '"East US"' | ||
| ############################################### | ||
| ### Replace <username> with GitHub username ### | ||
| ############################################### | ||
| AZURE_WEBAPP_NAME: <username>-ttt-app | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The I suggest using the GitHub user's ID or the pull request number in combination with the username to ensure uniqueness. For example, you could use AZURE_WEBAPP_NAME: ${{ github.actor }}-${{ github.event.pull_request.number }}-ttt-app |
||
|
|
||
| jobs: | ||
| setup-up-azure-resources: | ||
| runs-on: ubuntu-latest | ||
| if: contains(github.event.pull_request.labels.*.name, 'spin up environment') | ||
| steps: | ||
|
Comment on lines
+18
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The workflow fires on every Useful? React with 👍 / 👎. |
||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Azure login | ||
| uses: azure/login@v2 | ||
| with: | ||
| creds: ${{ secrets.AZURE_CREDENTIALS_MSA741 }} | ||
|
|
||
| - name: Create Azure resource group | ||
| if: success() | ||
| run: | | ||
| az group create --location ${{env.AZURE_LOCATION}} --name ${{env.AZURE_RESOURCE_GROUP}} --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} | ||
|
|
||
| - name: Create Azure app service plan | ||
| if: success() | ||
| run: | | ||
| az appservice plan create --resource-group ${{env.AZURE_RESOURCE_GROUP}} --name ${{env.AZURE_APP_PLAN}} --is-linux --sku F1 --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} | ||
|
|
||
| - name: Create webapp resource | ||
| if: success() | ||
| run: | | ||
| az webapp create --resource-group ${{ env.AZURE_RESOURCE_GROUP }} --plan ${{ env.AZURE_APP_PLAN }} --name ${{ env.AZURE_WEBAPP_NAME }} --deployment-container-image-name nginx --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} | ||
|
|
||
| - name: Configure webapp to use GHCR | ||
| if: success() | ||
| run: | | ||
| az webapp config container set --docker-custom-image-name nginx --docker-registry-server-password ${{secrets.CR_PAT}} --docker-registry-server-url https://${{env.IMAGE_REGISTRY_URL}} --docker-registry-server-user ${{github.actor}} --name ${{ env.AZURE_WEBAPP_NAME }} --resource-group ${{ env.AZURE_RESOURCE_GROUP }} --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} | ||
|
|
||
| destroy-azure-resources: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| if: contains(github.event.pull_request.labels.*.name, 'destroy environment') | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Azure login | ||
| uses: azure/login@v2 | ||
| with: | ||
| creds: ${{ secrets.AZURE_CREDENTIALS_MSA741 }} | ||
|
|
||
| - name: Destroy Azure environment | ||
| if: success() | ||
| run: | | ||
| az group delete --name ${{env.AZURE_RESOURCE_GROUP}} --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} --yes | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
AZURE_LOCATIONis hardcoded as'"East US"'. While this works, it might be beneficial to allow users to configure this via a repository secret or workflow input. This would provide more flexibility and allow the workflow to be used in different Azure regions. Consider making this configurable.