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

Create self-hosted runner for integration(-ish) CI tests #75

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2630e05
change recipe-test to test the runner
safoinme Aug 18, 2023
fc4b378
change recipe-test to test the runner
safoinme Aug 18, 2023
5a576e7
add clone repo step
safoinme Aug 18, 2023
60e48df
remove cloning step
safoinme Aug 18, 2023
1ea2aa8
initial code for creating a self-hosted runner on an azure vm to test…
safoinme Aug 18, 2023
2b4b2bc
add destroy
safoinme Aug 18, 2023
71919d5
fix repo url
safoinme Aug 18, 2023
329bb10
add terraform backend to store the state
safoinme Aug 18, 2023
28f6d64
change image
safoinme Aug 19, 2023
4c9efb8
return k3d-test to default runner
safoinme Aug 23, 2023
ad7b484
Merge branch 'develop' into feature/create-self-hosted-runner
safoinme Aug 23, 2023
862935d
Merge branch 'develop' into feature/create-self-hosted-runner
safoinme Aug 23, 2023
35114c2
Merge branch 'develop' into feature/create-self-hosted-runner
strickvl Aug 24, 2023
f3377e6
Update infrastructure/terraform.tf
safoinme Aug 24, 2023
6abcbb1
apply suggested reviews
safoinme Aug 24, 2023
2a6e8d0
Merge branch 'develop' into feature/create-self-hosted-runner
strickvl Aug 28, 2023
b0d112b
Merge branch 'develop' into feature/create-self-hosted-runner
strickvl Aug 30, 2023
923150d
Merge branch 'develop' into feature/create-self-hosted-runner
strickvl Aug 30, 2023
7cdb910
Apply suggestions from code review
safoinme Sep 4, 2023
9bbb119
Merge branch 'develop' into feature/create-self-hosted-runner
safoinme Sep 4, 2023
9ad516b
Merge branch 'develop' into feature/create-self-hosted-runner
safoinme Sep 24, 2023
3184c72
try new workflow to run on self-hosted runner
safoinme Sep 24, 2023
56cfc4d
Merge branch 'feature/create-self-hosted-runner' of github.com:zenml-…
safoinme Sep 24, 2023
e77ac3a
format
safoinme Sep 24, 2023
fc46012
fix destory yml
safoinme Sep 24, 2023
f88cf99
fix deploy yml
safoinme Sep 24, 2023
7d30049
add tags to resource groups
safoinme Sep 24, 2023
83734ba
update blob write and check
safoinme Sep 24, 2023
0e8d71d
update blob write and check
safoinme Sep 24, 2023
8c512b8
Merge branch 'develop' into feature/create-self-hosted-runner
safoinme Oct 5, 2023
7ca13a3
Merge branch 'develop' into feature/create-self-hosted-runner
strickvl Oct 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,16 @@ jobs:
(cd $dir && terraform plan -input=false)
done

provion-self-hosted-runner:
name: provion-self-hosted-runner
uses: ./.github/workflows/deploy-self-hosted-runner.yml
secrets: inherit

k3d_test:
name: k3d_test
runs-on: ubuntu-latest
runs-on: self-hosted
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. I'm curious though, how would GitHub know where/how you have self-hosted it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • The Azure storage is used as a lockdown mechanism to avoid the scenario where we have multiple runs at the same time in the VM and one finishes before the others, what the lock mechanism does is create a file with the run ID within the storage whenever a new run is called and before destroying the VM it first deletes the file that has the same run id and then does a check if there are any other files left, if none is left it allows the destroy if there is even one file left it means some run is still in progress and only last run would be allowed to destroy the VM
  • GH detects that because the VM is configured and connected to the GH action server and it has a Heartbeats test that checks that the self-hosted runner is still running and lunch the runs within that connected runner (the self-hosted is the default name to any runner so if there is multiple it will run on free one otherwise we can give specific names to each runner)

needs:
- provion-self-hosted-runner
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -217,3 +224,9 @@ jobs:
(cd $dir && terraform validate)
(cd $dir && terraform plan -input=false)
done

destory-self-hosted-runner:
name: destory-self-hosted-runner
needs: k3d_test
if: always()
uses: ./.github/workflows/destroy-self-hosted-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
MLSTACKS_ANALYTICS_OPT_IN=false
permissions:
contents: "read"
id-token: "write"
Expand All @@ -31,6 +30,14 @@ jobs:
- name: Checkout the Code
uses: actions/checkout@v3

- name: Install Azure CLI
run: |
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

- name: Login to Azure
run: |
az login --service-principal --username $ARM_CLIENT_ID --password $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2

Expand All @@ -49,4 +56,9 @@ jobs:

- run: terraform apply -auto-approve
env:
TF_VAR_github_runner_token: ${{ secrets.runner_token }}
TF_VAR_github_runner_token: ${{ secrets.runner_token }}

- name: Create blob
run: |
echo "Creating blob..."
az storage blob upload --account-name zenmlstorageaccount --container-name github-runner-tf --name github-run-${{ github.run_id }} --type block --data "${{ github.run_id }}"
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
MLSTACKS_ANALYTICS_OPT_IN=false
permissions:
contents: "read"
id-token: "write"
Expand Down Expand Up @@ -42,6 +41,18 @@ jobs:
id: validate
run: terraform validate -no-color

- run: terraform destroy -auto-approve -refresh=False
- name: Delete blob
run: |
az storage blob delete --account-name zenmlstorageaccount --container-name github-runner-tf --name ${{ github.run_id }}

- name: Check if any blobs left
id: check_blobs
run: |
blobs=$(az storage blob list --account-name zenmlstorageaccount --container-name github-runner-tf --query "[?starts_with(name, 'github-run')].name" --output tsv)
echo "BLOBS=$blobs" >> $GITHUB_ENV

- name: Destroy VM
run: terraform destroy -auto-approve -refresh=False
env:
TF_VAR_github_runner_token: ${{ secrets.runner_token }}
TF_VAR_github_runner_token: ${{ secrets.runner_token }}
if: env.BLOBS == ''
8 changes: 8 additions & 0 deletions infrastructure/deploy.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
resource "azurerm_resource_group" "example" {
name = "zenml-github-test"
location = "West Europe"

tags = {
z-env = "dev"
z-owner = "safoine-ext"
z-project = "testing"
z-team = "oss"
z-description = "resources for integration testing"
}
}

resource "azurerm_virtual_network" "example" {
Expand Down
9 changes: 0 additions & 9 deletions infrastructure/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,4 @@ terraform {

provider "azurerm" {
features {}
default_tags {
tags = {
z-env = "dev"
z-owner = "safoine-ext"
z-project = "testing"
z-team = "oss"
z-description = "resources for integration testing"
}
}
}
Loading