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

gh-actions: do runners #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions .github/workflows/do-destroy-runner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Destroy Digital Ocean runners

on:
workflow_call:
inputs:
name:
description: "Droplet name thats will be removed"
required: true
type: string

secrets:
access-token:
description: 'A token passed from the caller workflow'
required: true

do-access-token:
description: 'An API token to access DigitalOcean with'
required: true

jobs:
spin-up:
name: Destroy ${{ inputs.name }}
runs-on: ubuntu-latest

steps:
# Install Doctl
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.do-access-token }}

# Create the VM
- name: Delete vm ${{ inputs.name }}
run: doctl compute droplet delete ${{ inputs.name }} -f

- name: Delete the runner
run: |
RUNNER_ID=$(curl -s -X GET https://api.github.com/repos/${{ github.repository }}/actions/runners -H "accept: application/json" -H "authorization: token ${{ secrets.access-token }}" | jq -er '.runners[] | select(.name == "${{ inputs.name }}").id')
curl -s -X DELETE https://api.github.com/repos/${{ github.repository }}/actions/runners/$RUNNER_ID -H "accept: application/json" -H "authorization: token ${{ secrets.access-token }}"
92 changes: 92 additions & 0 deletions .github/workflows/do-make-runner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Make Digital Ocean runners

on:
workflow_call:
inputs:
name:
description: "Droplet name that will be created"
required: true
type: string

image:
description: "Droplet image"
required: false
default: ubuntu-22-04-x64
type: string

region:
description: "Droplet region"
required: false
default: fra1
type: string

size:
description: "Droplet size cpu/ram"
required: false
default: gd-4vcpu-16gb
type: string

label:
description: "Droplet labels"
required: true
type: string

secrets:
access-token:
description: 'A token passed from the caller workflow'
required: true

do-access-token:
description: 'An API token to access DigitalOcean with'
required: true

jobs:
spin-up:
name: Make ${{ inputs.name }}
runs-on: ubuntu-latest
outputs:
instance-name: ${{ steps.get-name.outputs.name }}

steps:
# Install Doctl
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.do-access-token }}

- name: Get instance name
id: get-name
run: echo "name=${{ inputs.name }}" >> $GITHUB_OUTPUT

# Template for cloud-init install vagrant and virtualbox
- name: Template out file
run: |
cat << EOF > ./user-data
#!/bin/bash
apt -y update
apt -y install jq curl unzip

useradd -m gha-runner
echo "gha-runner ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/gha-runner
export RUNNER_CFG_PAT="${{ secrets.access-token }}"
cd /home/gha-runner
curl -s https://raw.githubusercontent.com/actions/runner/main/scripts/create-latest-svc.sh | bash -s -- -s ${{ github.repository }} -u gha-runner -l ${{ inputs.label }}
EOF

# Create the VM
- name: Create vm for ${{ inputs.name }}
run: doctl compute droplet create ${{ inputs.name }} --image ${{ inputs.image }} --region ${{ inputs.region }} --size ${{ inputs.size }} --wait --user-data-file ./user-data > /dev/null

- name: Wait for VM to come online
run: |
sleep 30
for ATTEMPT in {1..10};
do
echo "#### Attempt $ATTEMPT ####"
if curl -s -X GET https://api.github.com/repos/${{ github.repository }}/actions/runners -H "accept: application/json" -H "authorization: token ${{ secrets.access-token }}" | jq -er '.runners[] | select(.name == "${{ inputs.name }}") | has("status")';
then
exit 0
fi
sleep 30
done
exit 1
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jobs:

Action for checking helm charts for compliance with the rules for formatting yaml files and for compliance with the configured rules for kubernetes manifests.

### k8s Deprecated recources validator
### Kubernetes Deprecated recources validator

Action for check deprecated api and other resources in k8s yaml manifests

### DigitalOcean make/destoy self-hosted runners

Action for make new Digital Ocean droplet with provided parameters, connect it like a self-hosted runner to repo, after job finished - remove self-hosted runner and destroy the droplet