-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #285 from caktus/CU-8689pdzrr-k8s-self-hosted-runner
K8s Self-hosted GitHub Runner
- Loading branch information
Showing
6 changed files
with
112 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,47 @@ | ||
--- | ||
- hosts: runner | ||
become: yes | ||
tags: base | ||
roles: | ||
- caktus.hosting_services.users | ||
- name: Install Actions Runner Controller and configure runner scale set | ||
hosts: cluster | ||
vars: | ||
ansible_connection: local | ||
ansible_python_interpreter: "{{ ansible_playbook_python }}" | ||
runner_namespace: github-runner | ||
chart_version: "0.9.3" | ||
gather_facts: false | ||
tasks: | ||
- name: Set hostname | ||
hostname: | ||
name: "{{ inventory_hostname_short }}" | ||
when: inventory_hostname_short is defined and inventory_hostname_short | ||
- name: Add new hostname to /etc/hosts | ||
lineinfile: | ||
path: /etc/hosts | ||
regexp: '^127\.0\.1\.1' | ||
line: '127.0.1.1 {{ inventory_hostname_short }}' | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
when: inventory_hostname_short is defined and inventory_hostname_short | ||
# https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners-with-actions-runner-controller/quickstart-for-actions-runner-controller | ||
# | ||
# Ansible task to automate: | ||
# helm install arc \ | ||
# --namespace "${NAMESPACE}" \ | ||
# --create-namespace \ | ||
# oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller | ||
- name: Installing Actions Runner Controller | ||
kubernetes.core.helm: | ||
context: "{{ k8s_context|mandatory }}" | ||
chart_ref: oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller | ||
chart_version: "{{ chart_version }}" | ||
release_name: arc | ||
release_namespace: "{{ runner_namespace }}" | ||
create_namespace: true | ||
wait: yes | ||
|
||
- name: Install GitHub Actions Runner | ||
hosts: runner | ||
tags: runner | ||
become: yes | ||
tasks: | ||
- name: Create runner user | ||
ansible.builtin.user: | ||
name: "{{ github_runner_user }}" | ||
comment: Github Actions Runner | ||
# Install Docker | ||
# https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository | ||
- name: Install dependencies | ||
ansible.builtin.package: | ||
name: | ||
- jq | ||
- ca-certificates | ||
- curl | ||
- gnupg | ||
- lsb-release | ||
- libpq-dev | ||
- python3.10 | ||
- python3.10-dev | ||
- name: Add Docker's official GPG key | ||
ansible.builtin.apt_key: | ||
url: https://download.docker.com/linux/ubuntu/gpg | ||
state: present | ||
- name: Add Docker repository | ||
ansible.builtin.apt_repository: | ||
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable | ||
state: present | ||
- name: Install Docker Engine | ||
ansible.builtin.package: | ||
name: | ||
- docker-ce | ||
- docker-ce-cli | ||
- containerd.io | ||
- docker-buildx-plugin | ||
- docker-compose-plugin | ||
update_cache: yes | ||
- name: Task name | ||
stat: | ||
path: /home/{{ github_runner_user }}/runner | ||
register: runner_dir | ||
- name: Set vars | ||
set_fact: | ||
run_removal_tasks: >- | ||
{{ | ||
runner_dir.stat.exists | ||
and ( | ||
(force_reinstall is defined and force_reinstall == "yes") | ||
or (force_removal is defined and force_removal == "yes") | ||
) | ||
}} | ||
# Various complicated Ansible roles exist, but this just works: | ||
# https://github.com/actions/runner/blob/main/docs/automate.md | ||
- name: Remove the runner | ||
ansible.builtin.shell: | ||
cmd: > | ||
curl -s https://raw.githubusercontent.com/actions/runner/main/scripts/remove-svc.sh | ||
| bash -s {{ github_scope }} | ||
chdir: /home/{{ github_runner_user }} | ||
environment: | ||
RUNNER_CFG_PAT: "{{ github_pat }}" | ||
when: run_removal_tasks | ||
ignore_errors: True | ||
- name: Delete the runner | ||
ansible.builtin.shell: | ||
cmd: > | ||
curl -s https://raw.githubusercontent.com/actions/runner/main/scripts/delete.sh | ||
| bash -s {{ github_scope }} {{ github_runner_name }} | ||
chdir: /home/{{ github_runner_user }} | ||
environment: | ||
RUNNER_CFG_PAT: "{{ github_pat }}" | ||
when: run_removal_tasks | ||
ignore_errors: True | ||
- name: Remove old runner directory and files | ||
ansible.builtin.file: | ||
path: "{{ item }}" | ||
state: absent | ||
loop: | ||
- /home/{{ github_runner_user }}/runner | ||
when: run_removal_tasks | ||
- name: Add user '{{ github_runner_user }}' to group docker | ||
user: | ||
name: "{{ github_runner_user }}" | ||
groups: docker | ||
append: yes | ||
- name: Restart docker service | ||
ansible.builtin.service: | ||
name: docker | ||
state: restarted | ||
- name: Install the runner [If error, RUNNER_CFG_PAT might be missing or expired! See README.md] | ||
ansible.builtin.shell: | ||
cmd: > | ||
curl -s https://raw.githubusercontent.com/actions/runner/main/scripts/create-latest-svc.sh | ||
| bash -s -- | ||
-s {{ github_scope }} | ||
-n {{ github_runner_name }} | ||
-l {{ github_runner_location }},self-hosted | ||
-u {{ github_runner_user }} | ||
chdir: /home/{{ github_runner_user }} | ||
environment: | ||
RUNNER_CFG_PAT: "{{ github_pat }}" | ||
when: (not runner_dir.stat.exists) or (force_reinstall is defined and force_reinstall=="yes") | ||
# Ansible task to automate: | ||
# helm install "${INSTALLATION_NAME}" \ | ||
# --namespace "${NAMESPACE}" \ | ||
# --create-namespace \ | ||
# --set githubConfigUrl="https://github.com/caktus/philly-hip" \ | ||
# --set githubConfigSecret.github_token="${RUNNER_CFG_PAT}" \ | ||
# oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set | ||
- name: Configuring a runner scale set | ||
kubernetes.core.helm: | ||
context: "{{ k8s_context|mandatory }}" | ||
chart_ref: oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set | ||
chart_version: "{{ chart_version }}" | ||
release_name: arc-runner-set | ||
release_namespace: "{{ runner_namespace }}" | ||
create_namespace: true | ||
release_values: | ||
githubConfigUrl: "https://github.com/caktus/philly-hip" | ||
githubConfigSecret: | ||
github_token: "{{ lookup('env', 'RUNNER_CFG_PAT') }}" | ||
wait: yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.