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

ci: add github actions workflow to test self hosted runner #282

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

anjannath
Copy link
Collaborator

@anjannath anjannath commented Aug 29, 2024

  • need to use a cloud storage for the backend, to be able to remove the instance after the job
  • Add mapt destroy job to remove provisioned instance

name: Test Self hosted runner addition

on:
workflow_call:
Copy link
Collaborator

Choose a reason for hiding this comment

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

We will need a strategy based on workflow_run to get access to secrets and test the binary build from the forked repo, with the current build you have here it will build it form the head of the main instead of from the PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we also have to store the backend in a cloud storage to be able to destroy the created resources later

Copy link
Collaborator

Choose a reason for hiding this comment

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

@anjannath ^^ Just added all required secrets for this:

  • ARM_TENANT_ID
  • ARM_SUBSCRIPTION_ID
  • ARM_CLIENT_ID
  • ARM_CLIENT_SECRET
  • AZURE_STORAGE_ACCOUNT
  • AZURE_STORAGE_KEY

Also to use the remote storage for backed-url the url would be something like (notice base name should exactly match mapt-gh-runner-mapt-state):

--backed-url azblob://mapt-gh-runner-mapt-state/${{ github.repository }}-${{ github.run_id }} 

Copy link
Collaborator Author

@anjannath anjannath Oct 4, 2024

Choose a reason for hiding this comment

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

Note: This event will only trigger a workflow run if the workflow file is on the default branch.

from: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_run

It seems workflow_run only works when the workflow is already in the main branch, so need to test this first on my fork and then update the PR, we'll have to initially merge something and then create follow up PR to fix if any issues found

@anjannath anjannath force-pushed the ghc-runner branch 5 times, most recently from 0b56135 to ec4f431 Compare October 4, 2024 12:26
@anjannath anjannath force-pushed the ghc-runner branch 4 times, most recently from 46188ca to ccf8ed1 Compare October 21, 2024 11:40
@adrianriobo
Copy link
Collaborator

Hey can we test selfhosted runner running crc on it. I am curious on the user running the agent.

I mean when I set up ssh I had to trick the user starting the service, as with default setup it is a system user (privileged) as so crc is not working. How is working with the gh agent?

@anjannath
Copy link
Collaborator Author

anjannath commented Oct 22, 2024

Hey can we test selfhosted runner running crc on it. I am curious on the user running the agent.

still not able to run jobs on the self-hosted runner from this repo, currently i am stuck with getting a runner registration token (this is a temporary token and only valid for 60mins) we need to have a way to fetch this token from withing the job itself, so we need to add a personal access token which has the permission to fetch the runner registration token for this repository

in the latest push i've added workflows to handle the above but still need to test, i'll need to first test the entire flow on my fork

I mean when I set up ssh I had to trick the user starting the service, as with default setup it is a system user (privileged) as so crc is not working. How is working with the gh agent?

the github runner agent is running as service using the nt authority\network service account, i did a test run here: https://github.com/anjannath/mapt/actions/runs/11459558776/job/31884314010

will have to try running crc start to see if it works with this user, the NetworkService is also a privileged user account i think

@adrianriobo
Copy link
Collaborator

Yeah my point is, if that is the case may we need to trick the agent (if possible) to start as a user process on startup

@anjannath anjannath force-pushed the ghc-runner branch 3 times, most recently from 4ee2cfb to 52d854b Compare October 25, 2024 08:42
@anjannath
Copy link
Collaborator Author

@adrianriobo the workflow_call strategy will pick the commit from the PR if we add a step for checkout code in the workflow job

so currently this PR adds to re-usable workflows, provision_hosted_runner and destroy_hosted_runner and a build_on_hosted_runner workflow that makes use of the reusable workflows, but currently it seems the secrets are not accessible to the workflows as they are not part of the repo main branch yet

the build-on-hosted-runner workflow additionally has to fetch a runner registration token which is needed to add a self hosted runner and is an input for the provision_hosted_runner workflow

@anjannath anjannath changed the title [wip] ci: add github actions workflow to test self hosted runner ci: add github actions workflow to test self hosted runner Oct 25, 2024
@adrianriobo adrianriobo changed the title ci: add github actions workflow to test self hosted runner WIP: ci: add github actions workflow to test self hosted runner Nov 4, 2024
this adds a workflow to provision a self hosted runner using mapt
on azure and run a simple job on that runner to test  self-hosted
runner feature of mapt
@anjannath anjannath changed the title WIP: ci: add github actions workflow to test self hosted runner ci: add github actions workflow to test self hosted runner Nov 6, 2024
@anjannath
Copy link
Collaborator Author

anjannath commented Nov 6, 2024

@adrianriobo this is finally ready for review again, got some successful runs on my fork, https://github.com/anjannath/mapt/actions/runs/11698979004

the new build-on-hosted-runner workflow will only run once we merge this PR and i have set the workflow to run only for PRs currently, maybe we should change that and test the self hosted feature only once changes are pushed to main (i.e PR is merged) and not for PRs?

Copy link
Collaborator

@adrianriobo adrianriobo left a comment

Choose a reason for hiding this comment

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

^^ @anjannath About your comment you can add a filter on PRs were any file of the util/ghactions is modified i.e. https://github.com/crc-org/ci-definitions/blob/main/.github/workflows/crc-builder-builder.yaml#L6C3-L8C79

Beyond that LGTM

--install-ghactions-runner --ghactions-runner-name "az-runner-${{inputs.operating_system}}-${{github.event.workflow_run.id}}" \
--ghactions-runner-repo "${{inputs.runner_repo}}" --ghactions-runner-token ${{steps.fetch_token.outputs.runner_token}}

- name: wait for runner to start accepting jobs
Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity why is this needed? I was expecting when it is ready the job test_run_selfhosted_runner will be executed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

during testing i found that when the job executed immediately the runner would never pick it up, couldn't figure out why this was happening

i just tried opening a second PR just to test by running a different workflow targeting that runner then it'd work and it'd also pickup the pending test_run_selfhosted_runner job, so figured that if there's a bit of delay between the runner getting added and the next job getting triggered it all works

@anjannath
Copy link
Collaborator Author

^^ @anjannath About your comment you can add a filter on PRs were any file of the util/ghactions is modified i.e. https://github.com/crc-org/ci-definitions/blob/main/.github/workflows/crc-builder-builder.yaml#L6C3-L8C79

Beyond that LGTM

actually this cannot be used, since we trigger the build-on-hosted-runner workflow based on if oci-build workflow is finished, and then on the job check if the event was a pull_request or not

@adrianriobo adrianriobo merged commit 7db5d30 into redhat-developer:main Nov 8, 2024
4 checks passed
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