Skip to content
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

Self-hosted runner cleanup: use Ubuntu instead of azure/cli action #96

Merged
merged 2 commits into from
Sep 23, 2024

Conversation

dennisameling
Copy link
Contributor

@dennisameling dennisameling commented Sep 18, 2024

The azure/cli GitHub Action runs in a Docker container with Alpine or Azure Linux, meaning that many tools like node and gh (which we rely on) aren't available.

Since the Azure CLI is available in the GitHub-hosted ubuntu-latest image anyway, let's leverage that instead. In the end, it has all the other tools we need as well.

Ref: https://github.com/actions/runner-images/blob/ce2a3e8e67858dc8c3dd77aca6b29e2956d934ed/images/ubuntu/Ubuntu2404-Readme.md?plain=1#L105

@dennisameling dennisameling marked this pull request as ready for review September 18, 2024 20:24
@dennisameling
Copy link
Contributor Author

@dscho I need some help here regarding the Azure Credentials. Currently, you have an AZURE_CREDENTIALS secret in this repo/org, which is most likely a JSON payload, as mentioned here. It'll look something like this:

{
    "clientSecret":  "******",
    "subscriptionId":  "******",
    "tenantId":  "******",
    "clientId":  "******"
}

If we want to invoke az login directly, which I did in this PR, we'll need to pass all of these individually. I'd opt for having them in dedicated secrets, allowing us to use them like this:

az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
az account set --subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }}

Would it be possible for you to set up those secrets? If not (or if it's too much work to do), I can most likely just extract the individual values from the JSON using jq, but I'm worried that GitHub might not mask those individual extracted values in the logs unless we do an ::add-mask::{value} for each individual value first. Having them in separate secrets just feels a bit cleaner and easier to work with to me, but it can be worked around for sure.

WDYT?

Also, here's a sample run, which obviously failed because of the missing secrets.

@dscho
Copy link
Member

dscho commented Sep 19, 2024

@dscho I need some help here regarding the Azure Credentials. Currently, you have an AZURE_CREDENTIALS secret in this repo/org, which is most likely a JSON payload, as mentioned here. It'll look something like this:

{
    "clientSecret":  "******",
    "subscriptionId":  "******",
    "tenantId":  "******",
    "clientId":  "******"
}

If we want to invoke az login directly, which I did in this PR, we'll need to pass all of these individually. I'd opt for having them in dedicated secrets, allowing us to use them like this:

az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
az account set --subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }}

Would it be possible for you to set up those secrets? If not (or if it's too much work to do), I can most likely just extract the individual values from the JSON using jq, but I'm worried that GitHub might not mask those individual extracted values in the logs unless we do an ::add-mask::{value} for each individual value first. Having them in separate secrets just feels a bit cleaner and easier to work with to me, but it can be worked around for sure.

That's too bad... the problem is that the JSON is produced when registering with Azure, and I'd like to keep it copy-pasteable.

How about using a github-script step to extract those values instead of using jq? That should take care of the masking very easily, as well as of setting the values as step outputs.

@dennisameling dennisameling force-pushed the cleanup-self-hosted-runners-built-in-azure-cli branch from 9ef3dab to a3a3cc3 Compare September 22, 2024 12:26
The `azure/cli` GitHub Action runs in a Docker container with Alpine or Azure Linux, meaning that many tools like `node` and `gh` (which we rely on) aren't available.

Since the Azure CLI is available in the GitHub-hosted `ubuntu-latest` image anyway, let's leverage that instead. In the end, it has all the other tools we need as well.

Ref: https://github.com/actions/runner-images/blob/ce2a3e8e67858dc8c3dd77aca6b29e2956d934ed/images/ubuntu/Ubuntu2404-Readme.md?plain=1#L105
Signed-off-by: Dennis Ameling <[email protected]>
It doesn't make sense to run this scheduled job on forks, because they don't have the required secrets.

Signed-off-by: Dennis Ameling <[email protected]>
@dennisameling dennisameling force-pushed the cleanup-self-hosted-runners-built-in-azure-cli branch from a3a3cc3 to 72a1b0d Compare September 22, 2024 14:33
@dennisameling
Copy link
Contributor Author

How about using a github-script step to extract those values instead of using jq? That should take care of the masking very easily, as well as of setting the values as step outputs.

@dscho great suggestion! I've applied the changes. Here's a successful workflow run. Starting another workflow run confirmed that no VMs are left after the cleanup 👍🏼

Copy link
Member

@dscho dscho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@dscho dscho merged commit 2ad3c61 into main Sep 23, 2024
2 checks passed
@dscho dscho deleted the cleanup-self-hosted-runners-built-in-azure-cli branch September 23, 2024 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants