From 6ff5a13497a1276fc03518bbdaa46a0bcf43a508 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 10 Jul 2017 11:08:36 -0500 Subject: [PATCH] Add Buildbot worker setup to Ansible playbook Currently assumes the host uses systemd --- .../templates/buildbot-worker.service.j2 | 17 +++++ contrib/ci-workers/templates/host.j2 | 4 ++ contrib/ci-workers/unix.yml | 68 +++++++++++++++++++ contrib/ci-workers/vars/buildbot.yml | 4 ++ 4 files changed, 93 insertions(+) create mode 100644 contrib/ci-workers/templates/buildbot-worker.service.j2 create mode 100644 contrib/ci-workers/templates/host.j2 create mode 100644 contrib/ci-workers/vars/buildbot.yml diff --git a/contrib/ci-workers/templates/buildbot-worker.service.j2 b/contrib/ci-workers/templates/buildbot-worker.service.j2 new file mode 100644 index 000000000..1fee26aa3 --- /dev/null +++ b/contrib/ci-workers/templates/buildbot-worker.service.j2 @@ -0,0 +1,17 @@ +[Unit] +Description=Buildbot worker +Wants=network.target +After=network.target + +[Service] +Type=forking +PIDFile=/home/{{ buildbot_worker_user }}/{{ buildbot_worker_name }}/twistd.pid +WorkingDirectory=/home/{{ buildbot_worker_user }} +ExecStart=/usr/local/bin/buildbot-worker start {{ buildbot_worker_name }} +ExecReload=/usr/local/bin/buildbot-worker restart {{ buildbot_worker_name }} +ExecStop=/usr/local/bin/buildbot-worker stop {{ buildbot_worker_name }} +Restart=always +User={{ buildbot_worker_user }} + +[Install] +WantedBy=multi-user.target diff --git a/contrib/ci-workers/templates/host.j2 b/contrib/ci-workers/templates/host.j2 new file mode 100644 index 000000000..708baf67b --- /dev/null +++ b/contrib/ci-workers/templates/host.j2 @@ -0,0 +1,4 @@ +OS: {{ ansible_distribution }} {{ ansible_distribution_version }} +Memory: {{ ansible_memtotal_mb }} MB +CPU: {{ ansible_processor[1] }} +{{ buildbot_worker_version.stdout }} diff --git a/contrib/ci-workers/unix.yml b/contrib/ci-workers/unix.yml index 6fd56a0a8..ecc826480 100644 --- a/contrib/ci-workers/unix.yml +++ b/contrib/ci-workers/unix.yml @@ -6,6 +6,17 @@ vars_files: - vars/default.yml + - vars/buildbot.yml + + vars_prompt: + - name: "buildbot_worker_admin" + prompt: "Admin details" + default: "Zcash " + - name: "buildbot_worker_name" + prompt: "Buildbot worker name (provided by ZECC)" + private: no + - name: "buildbot_worker_password" + prompt: "Buildbot worker password (provided by ZECC)" pre_tasks: - name: Install Python 2 for Ansible and Buildbot @@ -67,3 +78,60 @@ name: "{{ item }}" state: latest with_items: "{{ python_modules }}" + notify: restart buildbot-worker + + - name: Get installed Buildbot version + command: buildbot-worker --version + register: buildbot_worker_version + + - name: Set up the Buildbot worker user + user: + name: "{{ buildbot_worker_user }}" + comment: Buildbot worker + shell: /bin/bash + state: present + + - name: Create Buildbot worker + command: > + buildbot-worker create-worker ~/{{ buildbot_worker_name }} + {{ buildbot_master_host }}:{{ buildbot_master_port }} + {{ buildbot_worker_name|quote }} {{ buildbot_worker_password|quote }} + args: + creates: "~/{{ buildbot_worker_name }}/buildbot.tac" + become_user: "{{ buildbot_worker_user }}" + + - name: Set admin details for Buildbot worker + copy: + content: "{{ buildbot_worker_admin }}" + dest: "~/{{ buildbot_worker_name }}/info/admin" + become_user: "{{ buildbot_worker_user }}" + + - name: Set host details for Buildbot worker + template: + src: templates/host.j2 + dest: "~/{{ buildbot_worker_name }}/info/host" + become_user: "{{ buildbot_worker_user }}" + + - name: Copy Buildbot worker systemd service unit + template: + src: templates/buildbot-worker.service.j2 + dest: "/etc/systemd/system/buildbot-worker.service" + owner: root + group: root + mode: "0644" + notify: reload systemd + + - name: Start Buildbot worker. + service: + name: buildbot-worker + state: started + enabled: yes + + handlers: + - name: restart buildbot-worker + service: + name: buildbot-worker + state: restarted + + - name: reload systemd + command: /bin/systemctl daemon-reload diff --git a/contrib/ci-workers/vars/buildbot.yml b/contrib/ci-workers/vars/buildbot.yml new file mode 100644 index 000000000..3d21f400f --- /dev/null +++ b/contrib/ci-workers/vars/buildbot.yml @@ -0,0 +1,4 @@ +--- +buildbot_worker_user: zcbbworker +buildbot_master_host: dev-ci.z.cash +buildbot_master_port: 9899