forked from redhat-developer/mapt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add github actions workflow to test self hosted runner
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
- Loading branch information
Showing
4 changed files
with
152 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: build-on-hosted-runner | ||
|
||
on: | ||
workflow_run: | ||
workflows: | ||
- oci-builds | ||
types: | ||
- completed | ||
|
||
jobs: | ||
get_runner_registration_token: | ||
if: | | ||
github.event.workflow_run.conclusion == 'success' && | ||
github.event.workflow_run.event == 'pull_request' | ||
runs-on: ubuntu-24.04 | ||
outputs: | ||
runner_reg_token: ${{steps.fetch_token.outputs.token}} | ||
steps: | ||
- name: fetch token from API | ||
id: fetch_token | ||
run: | | ||
curl -L \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${{secrets.GH_PAT_TOKEN}}" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
https://api.github.com/repos/redhat-developer/mapt/actions/runners/registration-token > token | ||
token=$(cat token | jq .token | gpg --symmetric --quiet --batch --passphrase ${{secrets.GPG_PASS}} --output - | base64 -w0) | ||
echo "token=$token" >> "$GITHUB_OUTPUT" | ||
hosted_runner_provision: | ||
needs: get_runner_registration_token | ||
uses: ./.github/workflows/provision-hosted-runner.yaml | ||
with: | ||
runner_repo: "https://github.com/redhat-developer/mapt" | ||
operating_system: windows | ||
runner_registration_token: ${{needs.get_runner_registration_token.outputs.runner_reg_token}} | ||
secrets: inherit | ||
|
||
test_run_selfhosted_runner: | ||
runs-on: az-runner-ubuntu-${{github.even.workflow_run.id}} | ||
needs: hosted_runner_provision | ||
steps: | ||
- name: Code checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.21" | ||
- name: Build | ||
run: make build | ||
- name: Test | ||
run: go test -v ./... | ||
|
||
destroy_hosted_runner: | ||
needs: test_run_selfhosted_runner | ||
if: always() | ||
uses: ./.github/workflows/destroy-hosted-runner.yaml | ||
with: | ||
operating_system: ubuntu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: destroy-hosted-runner | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
operating_system: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
remove_cloud_instance: | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- name: Download mapt image from artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: mapt | ||
run-id: ${{ github.event.workflow_run.id }} | ||
github-token: ${{ github.token }} | ||
- name: Import mapt image | ||
run: | | ||
podman load -i mapt.tar | ||
podman images | ||
- name: Destroy instance | ||
run: | | ||
podman run -d --name mapt-destroy --rm \ | ||
-v ${PWD}:/workspace:z \ | ||
-e ARM_CLIENT_ID=${{secrets.ARM_CLIENT_ID}} \ | ||
-e ARM_CLIENT_SECRET=${{secrets.ARM_CLIENT_SECRET}} \ | ||
-e ARM_TENANT_ID=${{secrets.ARM_TENANT_ID}} \ | ||
-e ARM_SUBSCRIPTION_ID=${{secrets.ARM_SUBSCRIPTION_ID}} \ | ||
-e AZURE_SOTRAGE_ACCOUNT=${{secrets.AZURE_SOTRAGE_ACCOUNT}} \ | ||
-e AZURE_STORAGE_KEY=${{secrets.AZURE_STORAGE_KEY}} \ | ||
ghcr.io/redhat-developer/mapt:pr-${{github.event.number}} azure ${{inputs.operating_system}} \ | ||
destroy --project-name "az-ghrunner" \ | ||
--backed-url "azblob://mapt-gh-runner-mapt-state/${{github.repository}}-${{github.event.workflow_run.id}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: provision-hosted-runner | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
operating_system: | ||
required: true | ||
type: string | ||
runner_repo: | ||
required: true | ||
type: string | ||
runner_registration_token: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
provision_runner: | ||
name: provision-runner | ||
runs-on: ubuntu-24.04 | ||
env: | ||
B64_TOKEN: ${{inputs.runner_registration_token}} | ||
steps: | ||
- name: Download mapt image from artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: mapt | ||
run-id: ${{ github.event.workflow_run.id }} | ||
github-token: ${{ github.token }} | ||
- name: Import mapt image | ||
run: | | ||
podman load -i mapt.tar | ||
podman images | ||
- name: Run mapt | ||
run: | | ||
MAPT_IMAGE=$(cat mapt-image) | ||
echo "::add-mask::${B64_TOKEN}" | ||
token=$(echo -n ${B64_TOKEN} | base64 -d | gpg --decrypt --quiet --batch --passphrase ${{secrets.GPG_PASS}} --output -) | ||
echo "::add-mask::${token}" | ||
podman run --name mapt-create --rm \ | ||
-v ${PWD}:/workspace:z \ | ||
-e ARM_CLIENT_ID=${{secrets.ARM_CLIENT_ID}} \ | ||
-e ARM_CLIENT_SECRET=${{secrets.ARM_CLIENT_SECRET}} \ | ||
-e ARM_TENANT_ID=${{secrets.ARM_TENANT_ID}} \ | ||
-e ARM_SUBSCRIPTION_ID=${{secrets.ARM_SUBSCRIPTION_ID}} \ | ||
-e AZURE_SOTRAGE_ACCOUNT=${{secrets.AZURE_SOTRAGE_ACCOUNT}} \ | ||
-e AZURE_STORAGE_KEY=${{secrets.AZURE_STORAGE_KEY}} \ | ||
-e gh_runner_token=${token} \ | ||
${MAPT_IMAGE} azure ${{inputs.operating_system}} create \ | ||
--spot --project-name "az-ghrunner" \ | ||
--backed-url "azblob://mapt-gh-runner-mapt-state/${{github.repository}}-${{github.event.workflow_run.id}}" \ | ||
--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 "${gh_runner_token}" | ||