Skip to content

Commit

Permalink
common: a playbook for GHA self-hosted runner configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Gromadzki <tomasz.gromadzki@intel.com>
  • Loading branch information
grom72 committed Jun 23, 2023
1 parent 21f6289 commit 0ff9c34
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 19 deletions.
64 changes: 45 additions & 19 deletions utils/ansible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
This is utils/ansible/README.md.

The scripts in this directory allow you to set up a RockyLinux and OpenSUSE
environment on a real hardware and build a PMDK project on it.
environment on a real hardware to be able build a PMDK project on it or use the
node as a self-hosted runner for pmem/pmdk repository.

# Installing Ansible
To use playbooks it is required to install Ansible first. It must be done
Expand Down Expand Up @@ -72,6 +73,29 @@ ansible-playbook -i $TARGET_IP, configure-pmem.yml \
testUser=pmdkuser"
```

# Installing a GitHub Action self-hosted runner using Ansible palybook
The sequence of commands below setup a new server, with persistent memory and
a CI environment already installed, to be used as a self-hosted runner in
the pmem/pmdk repository.

```sh
export TARGET_IP= # ip of the target
export ROOT_PASSWORD= # a password of root on the target
export GHA_TOKEN= # GitHub token generated for a new self-hosted runner
export HOST_NAME= # host's name that will be visible on GitHub
export LABELS= # rhel or opensuse
export VARS_GHA= # e.g. proxy settings: http_proxy=http://proxy-dmz.XXX.com:911,https_proxy=http://proxy-dmz.XXX.com:912
ansible-playbook -i $TARGET_IP, configure-self-hosted-runner.yml --extra-vars
"host=all ansible_user=root ansible_password=$ROOT_PASSWORD testUser=pmdkuser \
runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA"
```
**Note**: To obtain a token for a new self hosted runer visit
[Create self-hosted runner](https://gib.com/pmem/pmdk/settings/actions/runners/new)
.

**Note**: In case of any problems, please refer to
[Adding self-hosted runners](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners) documentation.

# Provisioning from the target platform itself
It is possible to run playbooks directly on the target platform.
To run playbooks inside the platform please comment out the line:
Expand Down Expand Up @@ -116,20 +140,27 @@ cd pmdk/utils/ansible
```
Update playbooks to be used directly on the target as described [above](#provisioning-from-the-target-platform-itself)
and execute:
```
```sh
# as root:
ansible-playbook ./rockylinux-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass"
ansible-playbook rockylinux-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass"
# reboot shall be performed only if the playbook requests to do it.
reboot
# ...
cd pmdk/utils/ansible
ansible-playbook ./rockylinux-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass"
ansible-playbook ./configure-pmem.yml --extra-vars "newRegions=true"
ansible-playbook rockylinux-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass"
ansible-playbook configure-pmem.yml --extra-vars "newRegions=true"
reboot
# ...
cd pmdk/utils/ansible
# note - no newRegions=true when running the playbook after the reboot
ansible-playbook ./configure-pmem.yml --extra-vars "testUser=pmdkuser"
ansible-playbook configure-pmem.yml --extra-vars "testUser=pmdkuser"

export GHA_TOKEN= # GitHub token generated for a new self-hosted runner
export HOST_NAME=`hostname`
export LABELS= rhel
export VARS_GHA=http_proxy=http://proxy-dmz.XXX.com:911,https_proxy=http://proxy-dmz.XXX.com:912
ansible-playbook configure-self-hosted-runner.yml -extra-vars \
"testUser=pmdkuser runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA"
cd
rm -rf pmdk
```
Expand All @@ -144,7 +175,7 @@ cd pmdk/utils/ansible
```
Update playbooks to be used directly on the target as described [above](#provisioning-from-the-target-platform-itself)
and execute:
```
```sh
# as root:
ansible-playbook ./opensuse-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass"
# reboot shall be performed only if the playbook requests to do it.
Expand All @@ -158,19 +189,14 @@ reboot
cd pmdk/utils/ansible
# note - no newRegions=true when running the playbook after the reboot
ansible-playbook ./configure-pmem.yml --extra-vars "testUser=pmdkuser"

export GHA_TOKEN= # GitHub token generated for a new self-hosted runner
export HOST_NAME=`hostname`
export LABELS= opensuse
export VARS_GHA=http_proxy=http://proxy-dmz.XXX.com:911,https_proxy=http://proxy-dmz.XXX.com:912
ansible-playbook configure-self-hosted-runner.yml -extra-vars \
"testUser=pmdkuser runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA"
cd
rm -rf pmdk
```

## Installing and setting up a GitHub Actions runner
Installation and configuration of a self-hosted runner (as pmdkuser):
```sh
mkdir actions-runner && cd actions-runner
curl -o actions-runner-linux-x64-2.304.0.tar.gz -L \
https://github.com/actions/runner/releases/download/v2.304.0/actions-runner-linux-x64-2.304.0.tar.gz
tar xzf ./actions-runner-linux-x64-2.304.0.tar.gz
./config.cmd --url https://github.com/pmem/pmdk --token T_O_K_E_N__F_R_O_M__G_I_T_H_U_B
tmux
./run.cmd
```
Close session leaving the tmux session in the background (`CTRL+b d`).
87 changes: 87 additions & 0 deletions utils/ansible/configure-self-hosted-runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2023, Intel Corporation

# This playbook is designed to add a new self-hosted runner to pmem/pmdk.
# Examples below show how to use this file:
# 1) remote
# export TARGET_IP= # ip of the target
# export ROOT_PASSWORD= # a password of root on the target
# export GHA_TOKEN= # GitHub token generated for a new self-hosted runner
# export HOST_NAME= # host's name that will be visible on GitHub
# export LABELS= #rhel or opensuse
# export VARS_GHA= # e.g. proxy settings: http_proxy=http://proxy-dmz.XXX.com:911,https_proxy=http://proxy-dmz.XXX.com:912
# ansible-playbook -i $TARGET_IP, configure-self-hosted-runner.yml --extra-vars \
# "host=all ansible_user=root ansible_password=$ROOT_PASSWORD testUser=pmdkuser \
# runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA"
#
# 2) locally
# For a playbook to be used on a local server please:
# a) comment the first command: # -hosts: "{{ host }}"
# b) uncomment the next two lines:
# - hosts: localhost
# connection: local
#
# export GHA_TOKEN= # GitHub token generated for a new self-hosted runner
# export HOST_NAME= # Host name that will be visible on GitHub (e.g. `hostname`)
# export LABELS= #rhel or opensuse
# export VARS_GHA=http_proxy=http://proxy-dmz.XXX.com:911,https_proxy=http://proxy-dmz.XXX.com:912
# ansible-playbook configure-self-hosted-runner.yml --extra-vars
# "runner_name=$HOST_NAME labels=$LABELS vars_gha=env1,env2 token=$GHA_TOKEN"
#

#
# Runner package version may be changed by: --extra-vars package_url=<url_to_package.tar.gz>

- hosts: "{{ host }}"
#- hosts: localhost
# connection: local
vars:
testUser: pmdkuser
package_url: https://github.com/actions/runner/releases/download/v2.304.0/actions-runner-linux-x64-2.304.0.tar.gz
runner_folder: /home/{{ testUser }}/actions-runner
repo_url: https://github.com/pmem/pmdk
vars_list: "{{ vars_gha.split(',') }}"

tasks:
- name: "Create a runner folder"
file:
path: '{{ runner_folder }}'
state: directory
force: yes

- name: "Download and extract the installer"
unarchive:
src: '{{ package_url }}'
dest: '{{ runner_folder }}'
remote_src: yes

- name: "Change owner to {{ testUser }}"
shell: chown -R {{ testUser }} {{ runner_folder }}

- name: "Add runner to GHA"
shell: |
cd {{ runner_folder }}
./config.sh --url {{ repo_url }} --token {{ token }} --name {{ runner_name }} --labels {{ labels }} --runnergroup Default --work _work
become: yes
become_user: '{{ testUser }}'

- name: "Install runner service"
shell: |
cd {{ runner_folder }}
./svc.sh install {{ testUser }}
become: true
become_user: root

- name: "Insert variables into runsvc.sh file"
lineinfile:
path: "{{ runner_folder }}/runsvc.sh"
line: "export {{ item }}"
insertbefore: "insert anything to setup env when running as a service"
loop: "{{ vars_list }}"

- name: "Enable and restart runner service"
shell: |
systemctl enable actions.runner.pmem-pmdk.{{ runner_name }}.service
systemctl restart actions.runner.pmem-pmdk.{{ runner_name }}.service
become: true
become_user: root

0 comments on commit 0ff9c34

Please sign in to comment.