microsoft / azure-container-apps

Roadmap and issues for Azure Container Apps
MIT License
356 stars 27 forks source link

Smaller/Focused CI/CD Tooling (Azure CLI size is unreasonable for CI/CD usage) #1218

Open mikeball opened 6 days ago

mikeball commented 6 days ago

Is your feature request related to a problem? Please describe.
The Azure CLI is far too large for reasonable use in CI/CD. It's size makes pipelines that update revisions slow. The size seems a little silly given we need to make I think 2 http calls. As I was installing azure cli I see it includes things like icon sets, etc... it's wasteful and slow to load stuff like that every time a build pipeline. Here's the command's I'm actually using.

az login --service-principal --tenant $AZAD_TENANT --username $AZAD_USERNAME --password $AZAD_PASSWORD
az containerapp update -n my-app-name -g my-resource-group --image $IMAGENAME

Describe the solution you'd like.
I would like a small focused ACA specific utility for CI/CD pipeline usage that is space and resource efficient.

Describe alternatives you've considered.
I looked at Azure rest endpoints and am considering building an app that uses API directly, and am curious if others might also have same needs, or if there is already an open tool out there somewhere.

https://learn.microsoft.com/en-us/rest/api/containerapps/container-apps/update?view=rest-containerapps-2024-03-01&tabs=HTTP

simonjj commented 6 days ago

Mike,

There's a official Github Action which gets configured automatically via the CI/CD workflow in the portal and CLI. Alternatively you can also do it manually. Official docs are available here: https://github.com/marketplace/actions/azure-container-apps-build-and-deploy. Source is available at: https://github.com/Azure/container-apps-deploy-action

Hope this helps? This uses the CLI behind the scenes but the heavy lifting has already been done for you.

mikeball commented 6 days ago

Hope this helps? This uses the CLI behind the scenes but the heavy lifting has already been done for you.

Unfortunately not much. We are using bitbucket pipelines, and sort of misses the core of the problem which avoiding the 1GB+ dependency of the azure-cli requirement to update a revision.

ahmelsayed commented 1 day ago

You could do

TOKEN=$(curl https://login.microsoftonline.com/${AZAD_TENANT}/oauth2/v2.0/token \
  -F "grant_type=client_credentials" \
  -F "scope=https://management.core.windows.net//.default" \
  -F "client_id=${AZAD_USERNAME}" \
  -F "client_secret=${AZAD_PASSWORD}" \
  | jq -r ".access_token")

curl -XPATCH https://management.azure.com/${APP_ID}?api-version=2024-03-01 \
  -H "Authorization: Bearer ${TOKEN}" \
  -H "Content-Type: application/json" \
  -d "{\"properties\": {\"template\": {\"containers\": [{\"name\": \"some-name\", \"image\": \"${IMAGENAME}\"}]}}}"

Though you wanna be careful as this will patch your entire .properties.template.container array, so you might wanna do a GET before the PATCH (or PUT) to make sure to set any other properties you might need there like resources, name, etc.

The PATCH returns a 202, so you might need to follow the response Location header if you need to know when the patch is complete. You might also need to poll the revision status if you need to wait for that.

mikeball commented 1 day ago

Thanks @ahmelsayed! I actually have already built on a little golang utility mimic the azure cli to do those same http calls and it's working excellent, was considering sharing. Using curl might be an even better idea and will give it a try, need to see if jq is available in ci/cd. This might be the best suggestion for ci/cd which needs to update revision with new image.