Skip to content

Commit

Permalink
Add multiple GH runners
Browse files Browse the repository at this point in the history
Add multiple GH runners
  • Loading branch information
ruzickap committed Jan 13, 2020
1 parent 734eee1 commit a9d05fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
31 changes: 19 additions & 12 deletions ansible/build_remote_ssh_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
- virtualbox-6.1
- wget

packer_templates_git_repo: https://github.com/ruzickap/packer-templates
github_actions_runner_url: https://githubassets.azureedge.net/runners/2.161.0/actions-runner-linux-x64-2.161.0.tar.gz
builder_username: builder

vagrant_plugins:
- vagrant-libvirt

action_runner_count: 2

tasks:
- name: Install Python
raw: sudo bash -x -c "test -x /usr/bin/python3 || ( apt -qq update && apt install -y python3-minimal )"
raw: sudo bash -x -c "test -x /usr/bin/python3 || ( apt -qq update && apt install -y gnupg2 python3-minimal )"
register: output
changed_when: output.stdout is search("Unpacking")

Expand Down Expand Up @@ -138,32 +139,38 @@
loop: "{{ vagrant_plugins }}"
when: vagrant_plugin_list.stdout is not search(item)

- name: Create a directory if it does not exist
- name: Create a directories for action-runners if they do not exist
file:
path: /home/{{ builder_username }}/actions-runner
path: /home/{{ builder_username }}/actions-runner-{{ item }}
state: directory
loop: "{{ range(1, action_runner_count + 1) | list }}"

- name: Download and unpack the "actions-runner"
unarchive:
src: "{{ github_actions_runner_url }}"
dest: /home/{{ builder_username }}/actions-runner
dest: /home/{{ builder_username }}/actions-runner-{{ item }}
remote_src: yes
loop: "{{ range(1, action_runner_count + 1) | list }}"

- name: Register actions-runner
command: ./config.sh --url {{ packer_templates_git_repo }} --token {{ TOKEN }} --agent "{{ ansible_hostname }}" --work "_work"
- name: Register actions-runner-x
command: ./config.sh --url {{ MY_PACKER_TEMPLATES_GITHUB_REPOSITORY }} --token {{ GITHUB_SELF_HOSTED_RUNNER_TOKEN }} --agent "{{ ansible_hostname }}-{{ item }}" --work "_work"
args:
chdir: /home/{{ builder_username }}/actions-runner
creates: /home/{{ builder_username }}/actions-runner/.runner
chdir: /home/{{ builder_username }}/actions-runner-{{ item }}
creates: /home/{{ builder_username }}/actions-runner-{{ item }}/.runner
loop: "{{ range(1, action_runner_count + 1) | list }}"

become: yes
become_user: "{{ builder_username }}"

- name: Install actions-runner service
- name: Install actions-runner-x service
shell: ./svc.sh install && ./svc.sh start
become: true
args:
chdir: /home/{{ builder_username }}/actions-runner
creates: /home/{{ builder_username }}/actions-runner/.service
chdir: /home/{{ builder_username }}/actions-runner-{{ item }}
creates: /home/{{ builder_username }}/actions-runner-{{ item }}/.service
environment:
SUDO_USER: "{{ builder_username }}"
loop: "{{ range(1, action_runner_count + 1) | list }}"

handlers:
- name: reboot
Expand Down
9 changes: 5 additions & 4 deletions tools/build_remote_ssh_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

REMOTE_IP="company-nb"
REMOTE_USER="pruzicka"
TOKEN=${TOKEN:-AxxxxxxxxxxxxxxxxxxxxxxxxxxxO}
MY_PACKER_TEMPLATES_GITHUB_REPOSITORY="https://github.com/ruzickap/packer-templates"
GITHUB_SELF_HOSTED_RUNNER_TOKEN=${TOKEN:-Axxxxxxxxxxxxxxxxxxxxxxxxxxx4}

# Prepare remote machine for build
if [ -n "$TOKEN" ]; then
ansible-playbook -i "$REMOTE_IP," -e TOKEN="$TOKEN" --user $REMOTE_USER ../ansible/build_remote_ssh_ubuntu.yml
if [ -n "$GITHUB_SELF_HOSTED_RUNNER_TOKEN" ]; then
ansible-playbook -i "$REMOTE_IP," -e GITHUB_SELF_HOSTED_RUNNER_TOKEN="$GITHUB_SELF_HOSTED_RUNNER_TOKEN" -e MY_PACKER_TEMPLATES_GITHUB_REPOSITORY="$MY_PACKER_TEMPLATES_GITHUB_REPOSITORY" --user "$REMOTE_USER" ../ansible/build_remote_ssh_ubuntu.yml
else
echo "Missing TOKEN"
echo "Missing GITHUB_SELF_HOSTED_RUNNER_TOKEN"
exit 1
fi

0 comments on commit a9d05fb

Please sign in to comment.