-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add autdev pr #20
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
Changes from 5 commits
75dd475
2e424d2
4cd8f05
095f8c0
9d55a2f
adfd94a
a36df65
d887012
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,168 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| name: Azure Container Apps PR Deployment | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||||||||||||
| pull_request: | ||||||||||||||||||||||||||||||||||||||||||||||||
| types: [opened, reopened, synchronize, closed] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||||||||||||||||||||||
| id-token: write | ||||||||||||||||||||||||||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||||||||||||||||||||||||||
| pull-requests: write | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||||||||||||||||
| AZURE_CONTAINER_REGISTRY: dotinc.azurecr.io | ||||||||||||||||||||||||||||||||||||||||||||||||
| AZURE_RESOURCE_GROUP: rg-brease-pr-${{ github.event.number }} | ||||||||||||||||||||||||||||||||||||||||||||||||
| AZURE_LOCATION: westeurope | ||||||||||||||||||||||||||||||||||||||||||||||||
| API_APP_NAME: brease-api-pr-${{ github.event.number }} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||||||||||||
| deploy: | ||||||||||||||||||||||||||||||||||||||||||||||||
| if: github.event.action != 'closed' | ||||||||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||||||
| concurrency: | ||||||||||||||||||||||||||||||||||||||||||||||||
| group: pr-${{ github.event.number }} | ||||||||||||||||||||||||||||||||||||||||||||||||
| cancel-in-progress: true | ||||||||||||||||||||||||||||||||||||||||||||||||
| outputs: | ||||||||||||||||||||||||||||||||||||||||||||||||
| api-url: ${{ steps.get-api-url.outputs.url }} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Checkout code | ||||||||||||||||||||||||||||||||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Debug OIDC token | ||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "GitHub context:" | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Event: ${{ github.event_name }}" | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Ref: ${{ github.ref }}" | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "SHA: ${{ github.sha }}" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Azure Login | ||||||||||||||||||||||||||||||||||||||||||||||||
| uses: azure/login@v2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||
| client-id: ${{ secrets.AZ_SP_CLIENT_ID }} | ||||||||||||||||||||||||||||||||||||||||||||||||
| tenant-id: ${{ secrets.AZ_SP_TENANT_ID }} | ||||||||||||||||||||||||||||||||||||||||||||||||
| subscription-id: ${{ secrets.AZ_SUBSCRIPTION_ID }} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Set up Docker Buildx | ||||||||||||||||||||||||||||||||||||||||||||||||
| uses: docker/setup-buildx-action@v3 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Log in to Azure Container Registry | ||||||||||||||||||||||||||||||||||||||||||||||||
| run: az acr login --name dotinc | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Build and push API image | ||||||||||||||||||||||||||||||||||||||||||||||||
| uses: docker/build-push-action@v6 | ||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||
| context: ./apps/api | ||||||||||||||||||||||||||||||||||||||||||||||||
| push: true | ||||||||||||||||||||||||||||||||||||||||||||||||
| file: ./apps/api/Dockerfile | ||||||||||||||||||||||||||||||||||||||||||||||||
| tags: ${{ env.AZURE_CONTAINER_REGISTRY }}/brease-api:pr-${{ github.event.number }} | ||||||||||||||||||||||||||||||||||||||||||||||||
| cache-from: type=gha | ||||||||||||||||||||||||||||||||||||||||||||||||
| cache-to: type=gha,mode=max | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Create resource group | ||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||
| az group create \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --name ${{ env.AZURE_RESOURCE_GROUP }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --location ${{ env.AZURE_LOCATION }} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Deploy API service | ||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||
| az containerapp up \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --name ${{ env.API_APP_NAME }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --resource-group ${{ env.AZURE_RESOURCE_GROUP }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --location ${{ env.AZURE_LOCATION }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --image ${{ env.AZURE_CONTAINER_REGISTRY }}/brease-api:pr-${{ github.event.number }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --registry-server ${{ env.AZURE_CONTAINER_REGISTRY }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --ingress external \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --target-port 4400 \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --secrets \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| infisicalClientId=${{ secrets.INFISICAL_CLIENT_ID }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| infisicalClientSecret=${{ secrets.INFISICAL_CLIENT_SECRET }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --env-vars \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| PORT=4400 \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| NODE_ENV=staging \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| INFISICAL_PROJECT_ID=642ed4939db25595ac7eb9cd \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| INFISICAL_ENVIRONMENT=staging \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| INFISICAL_CLIENT_ID=secretref:infisicalClientId \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| INFISICAL_CLIENT_SECRET=secretref:infisicalClientSecret | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Get API URL | ||||||||||||||||||||||||||||||||||||||||||||||||
| id: get-api-url | ||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||
| URL=$(az containerapp show \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --name ${{ env.API_APP_NAME }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --resource-group ${{ env.AZURE_RESOURCE_GROUP }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --query properties.configuration.ingress.fqdn \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --output tsv) | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "url=https://$URL" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+97
to
+107
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. 🛠️ Refactor suggestion
- URL=$(az containerapp show \
+ for i in {1..10}; do
+ URL=$(az containerapp show \
--name ${{ env.API_APP_NAME }} \
--resource-group ${{ env.AZURE_RESOURCE_GROUP }} \
--query properties.configuration.ingress.fqdn \
--output tsv)
+ [ -n "$URL" ] && break
+ sleep 15
+ done
echo "url=https://$URL" >> $GITHUB_OUTPUT📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Comment on PR | ||||||||||||||||||||||||||||||||||||||||||||||||
| uses: marocchino/sticky-pull-request-comment@v2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||
| header: pr-deployment | ||||||||||||||||||||||||||||||||||||||||||||||||
| message: | | ||||||||||||||||||||||||||||||||||||||||||||||||
| ## 🚀 Brease PR Environment Deployed Successfully! | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| **API Service**: ${{ steps.get-api-url.outputs.url }} | ||||||||||||||||||||||||||||||||||||||||||||||||
| **OpenAPI Docs**: ${{ steps.get-api-url.outputs.url }}/docs | ||||||||||||||||||||||||||||||||||||||||||||||||
| **Health Check**: ${{ steps.get-api-url.outputs.url }}/health | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| **Resources Created:** | ||||||||||||||||||||||||||||||||||||||||||||||||
| - Resource Group: `${{ env.AZURE_RESOURCE_GROUP }}` | ||||||||||||||||||||||||||||||||||||||||||||||||
| - API Service: `${{ env.API_APP_NAME }}` (with managed environment) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| **API Testing:** | ||||||||||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||||||||||
| # Test the API endpoint | ||||||||||||||||||||||||||||||||||||||||||||||||
| curl ${{ steps.get-api-url.outputs.url }}/health | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # View OpenAPI documentation | ||||||||||||||||||||||||||||||||||||||||||||||||
| open ${{ steps.get-api-url.outputs.url }}/docs | ||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| > 💡 This environment will be automatically cleaned up when the PR is merged or closed. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| cleanup: | ||||||||||||||||||||||||||||||||||||||||||||||||
| if: github.event.action == 'closed' | ||||||||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Azure Login | ||||||||||||||||||||||||||||||||||||||||||||||||
| uses: azure/login@v2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||
| client-id: ${{ secrets.AZ_SP_CLIENT_ID }} | ||||||||||||||||||||||||||||||||||||||||||||||||
| tenant-id: ${{ secrets.AZ_SP_TENANT_ID }} | ||||||||||||||||||||||||||||||||||||||||||||||||
| subscription-id: ${{ secrets.AZ_SUBSCRIPTION_ID }} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Delete resource group | ||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||
| if az group exists --name ${{ env.AZURE_RESOURCE_GROUP }}; then | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Deleting resource group: ${{ env.AZURE_RESOURCE_GROUP }}" | ||||||||||||||||||||||||||||||||||||||||||||||||
| az group delete \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --name ${{ env.AZURE_RESOURCE_GROUP }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --yes \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --no-wait | ||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Resource group ${{ env.AZURE_RESOURCE_GROUP }} does not exist" | ||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Clean up container images | ||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||
| # Delete PR-specific images from ACR | ||||||||||||||||||||||||||||||||||||||||||||||||
| az acr repository delete \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --name dotinc \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --repository brease-api \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --tag pr-${{ github.event.number }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --yes || true | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Comment on PR | ||||||||||||||||||||||||||||||||||||||||||||||||
| uses: marocchino/sticky-pull-request-comment@v2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||
| header: pr-deployment | ||||||||||||||||||||||||||||||||||||||||||||||||
| message: | | ||||||||||||||||||||||||||||||||||||||||||||||||
| ## 🧹 Brease PR Environment Cleaned Up | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| All Azure resources for this PR have been deleted: | ||||||||||||||||||||||||||||||||||||||||||||||||
| - Resource Group: `${{ env.AZURE_RESOURCE_GROUP }}` | ||||||||||||||||||||||||||||||||||||||||||||||||
| - Container image: `brease-api:pr-${{ github.event.number }}` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| > ✅ Cleanup completed successfully. | ||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,5 @@ | ||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||
| set -e | ||||||||||||||||||||||||||||||
|
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. 🛠️ Refactor suggestion Harden the script with Fail fast on unset variables and pipe errors for more predictable behaviour. -set -e
+set -euo pipefail🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| echo "Fetching secrets from Infisical..." | ||||||||||||||||||||||||||||||
| export INFISICAL_TOKEN=$(infisical login --method=universal-auth --client-id=$INFISICAL_CLIENT_ID --client-secret=$INFISICAL_CLIENT_SECRET --plain --silent) | ||||||||||||||||||||||||||||||
|
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. 🛠️ Refactor suggestion Fix SC2155 and quote sensitive expansions Declare then export and always quote to avoid word-splitting / injection. -export INFISICAL_TOKEN=$(infisical login --method=universal-auth --client-id=$INFISICAL_CLIENT_ID --client-secret=$INFISICAL_CLIENT_SECRET --plain --silent)
+INFISICAL_TOKEN=$(infisical login \
+ --method=universal-auth \
+ --client-id="$INFISICAL_CLIENT_ID" \
+ --client-secret="$INFISICAL_CLIENT_SECRET" \
+ --plain --silent)
+export INFISICAL_TOKEN📝 Committable suggestion
Suggested change
🧰 Tools🪛 Shellcheck (0.10.0)[warning] 4-4: Declare and assign separately to avoid masking return values. (SC2155) 🤖 Prompt for AI AgentsThere 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. 🛠️ Refactor suggestion Quote variables & split assignment to avoid masked return value Capturing the token in the same -export INFISICAL_TOKEN=$(infisical login --method=universal-auth --client-id=$INFISICAL_CLIENT_ID --client-secret=$INFISICAL_CLIENT_SECRET --plain --silent)
+INFISICAL_TOKEN="$(infisical login \
+ --method=universal-auth \
+ --client-id="$INFISICAL_CLIENT_ID" \
+ --client-secret="$INFISICAL_CLIENT_SECRET" \
+ --plain --silent)"
+export INFISICAL_TOKENAdds quoting, preserves exit-code, and keeps the script safety guarantees already implied by 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Shellcheck (0.10.0)[warning] 4-4: Declare and assign separately to avoid masking return values. (SC2155) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| infisical run --projectId=$INFISICAL_PROJECT_ID --env=staging brease | ||||||||||||||||||||||||||||||
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.
Unrestricted PR trigger exposes Azure resources to untrusted fork code
Running this workflow for every
pull_requestevent allows code from forks to execute arbitraryaz *commands with the federated service-principal, giving write access to the subscription. Restrict deployments to trusted actors, e.g.or gate the jobs behind a protected
environmentthat requires manual approval.📝 Committable suggestion
🤖 Prompt for AI Agents