Skip to content

Commit b3b82bb

Browse files
committed
feat(ci): implement mock-ACPI workflow
This commit introduces a workflow for testing ACPI functionality using Equinix self-hosted runners. The workflow deploys Kepler using mock-acpi compose setup and runs validator to ensure functionality. Key-features: - Workflow is triggered on pull requests that include a specific commit message `/test-acpi`. - Environment setup is handled by ansible. Signed-off-by: Vibhu Prashar <[email protected]>
1 parent 58ac66f commit b3b82bb

File tree

4 files changed

+218
-0
lines changed

4 files changed

+218
-0
lines changed

.github/workflows/mock_acpi.yml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# This workflow will run mock-acpi compose on self-hosted equinix runners and run validator tool
2+
name: Mock ACPI
3+
4+
on: # yamllint disable-line rule:truthy
5+
issue_comment:
6+
types: [created]
7+
8+
jobs:
9+
create-runner:
10+
if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
11+
name: Create Runner
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: metal-runner-action
16+
uses: equinix-labs/[email protected]
17+
with:
18+
github_token: ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }}
19+
metal_auth_token: ${{ secrets.EQUINIX_API_TOKEN }}
20+
metal_project_id: ${{ secrets.EQUINIX_PROJECT_ID }}
21+
metro: da
22+
plan: c3.small.x86
23+
os: ubuntu_20_04
24+
25+
setup-runner:
26+
if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
27+
name: Setup Runner
28+
needs: create-runner
29+
runs-on: self-hosted
30+
continue-on-error: true # This is done to release equinix runners irrespective of failure
31+
outputs:
32+
runner-name: ${{ runner.name }}
33+
playbook-status: ${{ steps.run-playbook.outcome }}
34+
35+
steps:
36+
- name: Configure SSH
37+
run: |
38+
echo "Configuring SSH for runner"
39+
sudo ssh-keygen -t rsa -b 4096 -f /root/.ssh/ansible_rsa -N ''
40+
sudo cat ~/.ssh/ansible_rsa.pub >> ~/.ssh/authorized_keys
41+
sudo echo "StrictHostKeyChecking no" >> ~/.ssh/config
42+
43+
- name: Install Dependencies
44+
run: |
45+
echo "Installing Ansible and Docker module"
46+
sudo apt install software-properties-common -y
47+
sudo add-apt-repository --yes --update ppa:ansible/ansible
48+
sudo apt install -y ansible python3-pip
49+
sudo ansible-galaxy collection install community.docker
50+
51+
- name: Checkout code
52+
uses: actions/checkout@v3
53+
54+
- name: Run playbook
55+
id: run-playbook
56+
run: |
57+
echo "Setting up the infra"
58+
cd ${GITHUB_WORKSPACE}/ansible
59+
ansible-playbook -vv -i inventory.yaml setup.yaml
60+
echo "Launching Mock ACPI compose and running validator"
61+
ansible-playbook -vv -i inventory.yaml mock_acpi_playbook.yaml -e "pr_number=${{ github.event.issue.number }}"
62+
63+
- name: Set failure status if playbook failed
64+
if: steps.run-playbook.outcome == 'failure'
65+
run: echo "failure_status=true" >> $GITHUB_ENV
66+
67+
cleanup:
68+
if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
69+
name: Cleanup
70+
runs-on: ubuntu-latest
71+
needs: [setup-runner]
72+
steps:
73+
- name: delete runner
74+
uses: rootfs/metal-delete-action@main
75+
with:
76+
authToken: ${{ secrets.EQUINIX_API_TOKEN }}
77+
projectID: ${{ secrets.EQUINIX_PROJECT_ID }}
78+
runnerName: ${{ needs.setup-runner.outputs.runner-name }}
79+
80+
# Marking the workflow as failed if the playbook fails
81+
mark-workflow-failed:
82+
if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
83+
name: Mark workflow as failed
84+
runs-on: ubuntu-latest
85+
needs: [setup-runner]
86+
steps:
87+
- name: Mark workflow as failed if playbook failed
88+
if: needs.setup-runner.outputs.playbook-status == 'failure'
89+
run: |
90+
echo "Playbook failed, marking workflow as failed"
91+
exit 1

ansible/inventory.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
all:
2+
hosts:
3+
localhost:
4+
ansible_connection: local
5+
ansible_ssh_private_key_file: ~/.ssh/ansible_rsa

ansible/mock_acpi_playbook.yaml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
- name: Deploy and run the Kepler Mock ACPI Compose
3+
hosts: localhost
4+
become: true
5+
vars:
6+
kepler_repo: https://github.com/sustainable-computing-io/kepler.git
7+
kepler_dir: /opt/kepler
8+
validator_dir: /opt/kepler/e2e/tools/validator
9+
compose_dir: /opt/kepler/manifests/compose
10+
pr_number: ""
11+
tasks:
12+
- name: Clone kepler repo
13+
git:
14+
repo: "{{ kepler_repo }}"
15+
dest: "{{ kepler_dir }}"
16+
version: main
17+
18+
- name: Fetch and checkout the specific pull request
19+
shell: |
20+
cd {{ kepler_dir }}
21+
git fetch origin pull/{{ pr_number }}/head:pr-{{ pr_number }}
22+
git checkout pr-{{ pr_number }}
23+
24+
- name: Get latest commit details
25+
shell: |
26+
cd {{ kepler_dir }}
27+
git log -n 1
28+
29+
- name: Start Docker compose services
30+
community.docker.docker_compose_v2:
31+
project_src: "{{ compose_dir }}/mock-acpi"
32+
build: always
33+
files: compose.yaml
34+
state: present
35+
36+
- name: Wait for Prometheus metrics to become available
37+
pause:
38+
seconds: 180
39+
40+
- name: Check Prometheus metrics
41+
shell: |
42+
curl http://localhost:9090/api/v1/query -G -d query='kepler_exporter_build_info' | jq
43+
curl http://localhost:9090/api/v1/query -G -d query='kepler_node_info' | jq
44+
register: prometheus_metrics
45+
failed_when: |
46+
('status' not in prometheus_metrics.stdout) or
47+
('success' not in prometheus_metrics.stdout) or
48+
('"result": []' in prometheus_metrics.stdout)
49+
50+
- name: Run mock-acpi validator
51+
shell: |
52+
cd {{ validator_dir }}
53+
hatch run validator -f ./validator.mock-acpi.yaml validate-acpi -d 1m
54+
when: prometheus_metrics is success
55+
register: mock_acpi_validator
56+
failed_when: |
57+
('error' in mock_acpi_validator.stdout.lower()) or
58+
('mse exceeded' in mock_acpi_validator.stdout.lower()) or
59+
('mape exceeded' in mock_acpi_validator.stderr.lower())

ansible/setup.yaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
- name: Setup infrastructure with necessary packages, Docker and Hatch
3+
hosts: localhost
4+
become: true
5+
vars:
6+
ansible_user: root
7+
tasks:
8+
- name: Ensure necessary packages are installed
9+
apt:
10+
name:
11+
- ca-certificates
12+
- curl
13+
- jq
14+
state: present
15+
update_cache: true
16+
17+
- name: Install hatch via pip
18+
pip:
19+
name: hatch
20+
state: latest
21+
22+
- name: Add Docker official GPG key
23+
apt_key:
24+
url: https://download.docker.com/linux/ubuntu/gpg
25+
state: present
26+
27+
- name: Set up Docker stable repository
28+
apt_repository:
29+
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable
30+
state: present
31+
32+
- name: Update the apt package index
33+
apt:
34+
update_cache: true
35+
36+
- name: Install Docker Engine and related packages
37+
apt:
38+
name:
39+
- docker-ce
40+
- docker-ce-cli
41+
- containerd.io
42+
- docker-compose-plugin
43+
- docker-buildx-plugin
44+
state: latest
45+
46+
- name: Ensure Docker service is running
47+
service:
48+
name: docker
49+
state: started
50+
51+
- name: Add user to Docker group
52+
user:
53+
name: "{{ ansible_user }}"
54+
groups: docker
55+
append: true
56+
57+
- name: Verify Docker installation
58+
command: docker --version
59+
register: docker_version
60+
61+
- name: Display Docker version
62+
debug:
63+
msg: "{{ docker_version.stdout }}"

0 commit comments

Comments
 (0)