Skip to content

Commit

Permalink
Start selfhosted runner using ssh (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha0552 authored Mar 6, 2024
1 parent 0f29963 commit f4aca5b
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 35 deletions.
65 changes: 47 additions & 18 deletions .ci/template/sh-build-iso.yml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,30 @@ on:

jobs:
vm-start:
if: always()
runs-on: ubuntu-latest

steps:
- name: Start virtual machine
- name: Save ssh configuration
run: |
# FIXME
exit 0
# Create ssh directory
mkdir ~/.ssh
{% raw %}
# Save ssh config
echo "${{ secrets.SSH_CONFIG }}" | base64 -d > ~/.ssh/config

# Save ssh known hosts
echo "${{ secrets.SSH_KNOWN_HOSTS }}" | base64 -d > ~/.ssh/known_hosts

# Save ssh private key
echo "${{ secrets.SSH_PRIVATE_KEY }}" | base64 -d > /tmp/private.key
{% endraw %}
# Fix permissions for private key
chmod 600 /tmp/private.key

- name: Start Github Actions Runner VM
run: |
ssh runner "virsh start GithubActions"

build:
needs: vm-start
Expand Down Expand Up @@ -73,24 +90,36 @@ jobs:
name: archiso-output
path: out/

vm-shutdown:
if: "!cancelled()"
vm-stop:
if: always()
needs: build
runs-on: self-hosted

steps:
- name: Stop virtual machine
run: |
# Shutdown in 1 minute
sudo shutdown 1

vm-shutdown-wait:
if: "!cancelled()"
needs: vm-shutdown
runs-on: ubuntu-latest

steps:
- name: Wait until virtual machine is stopped
- name: Save ssh configuration
run: |
# Create ssh directory
mkdir ~/.ssh
{% raw %}
# Save ssh config
echo "${{ secrets.SSH_CONFIG }}" | base64 -d > ~/.ssh/config

# Save ssh known hosts
echo "${{ secrets.SSH_KNOWN_HOSTS }}" | base64 -d > ~/.ssh/known_hosts

# Save ssh private key
echo "${{ secrets.SSH_PRIVATE_KEY }}" | base64 -d > /tmp/private.key
{% endraw %}
# Fix permissions for private key
chmod 600 /tmp/private.key

- name: Stop Github Actions Runner VM
run: |
# Wait for 2 minutes
# Invoke regular shutdown
ssh runner "virsh shutdown GithubActions"

# Wait 2 minutes
sleep 120

# Force terminate if needed
ssh runner "virsh destroy GithubActions" || true
63 changes: 46 additions & 17 deletions .github/workflows/sh-build-iso-rocm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,30 @@ on:

jobs:
vm-start:
if: always()
runs-on: ubuntu-latest

steps:
- name: Start virtual machine
- name: Save ssh configuration
run: |
# FIXME
exit 0
# Create ssh directory
mkdir ~/.ssh
# Save ssh config
echo "${{ secrets.SSH_CONFIG }}" | base64 -d > ~/.ssh/config
# Save ssh known hosts
echo "${{ secrets.SSH_KNOWN_HOSTS }}" | base64 -d > ~/.ssh/known_hosts
# Save ssh private key
echo "${{ secrets.SSH_PRIVATE_KEY }}" | base64 -d > /tmp/private.key
# Fix permissions for private key
chmod 600 /tmp/private.key
- name: Start Github Actions Runner VM
run: |
ssh runner "virsh start GithubActions"
build:
needs: vm-start
Expand Down Expand Up @@ -71,24 +88,36 @@ jobs:
name: archiso-output
path: out/

vm-shutdown:
if: "!cancelled()"
vm-stop:
if: always()
needs: build
runs-on: self-hosted
runs-on: ubuntu-latest

steps:
- name: Stop virtual machine
- name: Save ssh configuration
run: |
# Shutdown in 1 minute
sudo shutdown 1
# Create ssh directory
mkdir ~/.ssh
vm-shutdown-wait:
if: "!cancelled()"
needs: vm-shutdown
runs-on: ubuntu-latest
# Save ssh config
echo "${{ secrets.SSH_CONFIG }}" | base64 -d > ~/.ssh/config
steps:
- name: Wait until virtual machine is stopped
# Save ssh known hosts
echo "${{ secrets.SSH_KNOWN_HOSTS }}" | base64 -d > ~/.ssh/known_hosts
# Save ssh private key
echo "${{ secrets.SSH_PRIVATE_KEY }}" | base64 -d > /tmp/private.key
# Fix permissions for private key
chmod 600 /tmp/private.key
- name: Stop Github Actions Runner VM
run: |
# Wait for 2 minutes
sleep 120
# Invoke regular shutdown
ssh runner "virsh shutdown GithubActions"
# Wait 2 minutes
sleep 120
# Force terminate if needed
ssh runner "virsh destroy GithubActions" || true

0 comments on commit f4aca5b

Please sign in to comment.