From 559d5575b97730ee558e230dd969ac2985c97cdf Mon Sep 17 00:00:00 2001 From: Peter Mounce Date: Tue, 11 Dec 2018 15:11:12 +0000 Subject: [PATCH 1/9] molecule + contribution guide --- .yamllint | 13 ++++++ CONTRIBUTING.md | 58 ++++++++++++++++++++++++ molecule/default/Dockerfile.j2 | 14 ++++++ molecule/default/INSTALL.rst | 16 +++++++ molecule/default/molecule.yml | 20 ++++++++ molecule/default/playbook.yml | 5 ++ molecule/default/tests/test_default.py | 14 ++++++ molecule/default/tests/test_default.pyc | Bin 0 -> 1129 bytes requirements.txt | 3 ++ 9 files changed, 143 insertions(+) create mode 100644 .yamllint create mode 100644 CONTRIBUTING.md create mode 100644 molecule/default/Dockerfile.j2 create mode 100644 molecule/default/INSTALL.rst create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/playbook.yml create mode 100644 molecule/default/tests/test_default.py create mode 100644 molecule/default/tests/test_default.pyc create mode 100644 requirements.txt diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..3a2255e --- /dev/null +++ b/.yamllint @@ -0,0 +1,13 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + # NOTE(retr0h): Templates no longer fail this lint rule. + # Uncomment if running old Molecule templates. + # truthy: disable diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..caa7cdb --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,58 @@ +# CONTRIBUTING + +## Overview + +Contributions are welcome! + +* Please make sure that existing tests pass, and new coverage is added where changes happen. + +## Local workflow + +### Setup + +1. Install [pyenv] +1. Set up pyenv: + + ```bash + pyenv install 2.7.15 + pyenv install 3.7.1 + pyenv global 2.7.15 3.7.1 + python -m pip install virtualenv + unset PYTHONPATH + ``` + +1. Set up virtualenv: + + ```bash + python -m virtualenv .venv + source .venv/bin/activate + python -m pip install -r requirements.txt + ``` + +### Iterate + +1. Fork the repository via github. +1. Clone it, add `upstream` remote. + + ```bash + git clone git@github.com:{you}/ansible-buildkite-agent.git + cd ansible-buildkite-agent + git checkout devel + git remote add upstream git@github.com:azavea/ansible-buildkite-agent.git + ``` + +1. Make a new branch. `git checkout -b {branch name}`. +1. Make some changes, covered by tests. `git commit -m "some message"`. +1. Run the tests via `molecule test`. +1. Push the changes to your github fork. `git push -u origin {branch name}` +1. Open a pull-request via github (should be a hyperlink inside the git push output to click on). + +#### Once you're done + +Leave the virtualenv: + +```bash +deactivate +``` + +[pyenv]: https://github.com/pyenv/pyenv#installation diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..0a60553 --- /dev/null +++ b/molecule/default/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/molecule/default/INSTALL.rst b/molecule/default/INSTALL.rst new file mode 100644 index 0000000..b42edf5 --- /dev/null +++ b/molecule/default/INSTALL.rst @@ -0,0 +1,16 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + + $ sudo pip install docker-py diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..f5e3b11 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,20 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: instance + image: centos:7 +provisioner: + name: ansible + lint: + name: ansible-lint +scenario: + name: default +verifier: + name: testinfra + lint: + name: flake8 diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml new file mode 100644 index 0000000..1d76e7f --- /dev/null +++ b/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: ansible-buildkite-agent diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py new file mode 100644 index 0000000..eedd64a --- /dev/null +++ b/molecule/default/tests/test_default.py @@ -0,0 +1,14 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_hosts_file(host): + f = host.file('/etc/hosts') + + assert f.exists + assert f.user == 'root' + assert f.group == 'root' diff --git a/molecule/default/tests/test_default.pyc b/molecule/default/tests/test_default.pyc new file mode 100644 index 0000000000000000000000000000000000000000..93383a4e0a89b4d37805a7426dd6e2c8422289ea GIT binary patch literal 1129 zcmeHFUvJYe5WghdUorZG&|dbOm(?J|rb!4fjZWKCI?)XzDx@eRPUkkYgMF#iZhZm1 z6<>t!!83xh(`;jW1)Su3{^k6;^ZgwB+*tqdz4aKU!Mjd7 zI_|!2ch66IAELwKP8)6dIL{N0W`FS=&}=$nt|^tPh!V^_xTbs_m@PmbzEsP=7Bcd| zJi7xnYVc?Q(y`7$o2hHo$uf=!yHExVHfX7pLRYR^Wg_ReOfbI`HsT?<`^IpMLdmw) zO1rSqBKC{}t;!;_r90fxqCHF&k^yJTFY;KS#Uw_~Cb4Fj%2Tclo9(iRo{e{Aqo>cu zX6It2FU?+}r@Nn@*fEgooE4(j7SbSfXY1;WE}j zu?g2A6NDf)C}gH%c6D_(v{f@jsn9$@rKj`x{g|3AlJS`T`@2r^7lln2r96wv99zW{ zo74e^xwc2P$!i3eRWjf;{igTG3#~RJEdcd!%ldWItrA6UTCp_ZQ_dq@N=e Date: Tue, 11 Dec 2018 15:15:13 +0000 Subject: [PATCH 2/9] Fix linting errors --- defaults/main.yml | 10 +++++----- examples/site.yml | 2 +- tasks/install-on-Darwin.yml | 2 +- tasks/install-on-Debian.yml | 2 +- tasks/install-on-Windows.yml | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index c8f596e..90adf9d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -59,14 +59,14 @@ buildkite_agent_tags_from_gcp: "false" buildkite_agent_tags_from_host: "false" # Debian options -buildkite_agent_allow_latest: yes -buildkite_agent_version: "3.7.0" -buildkite_agent_build_number: "2659" +buildkite_agent_allow_latest: true +buildkite_agent_version: "3.8.2" +buildkite_agent_build_number: "2742" # Windows options buildkite_agent_nssm_version: "2.24.101.20180116" buildkite_agent_platform: "amd64" -buildkite_agent_windows_grant_admin: False +buildkite_agent_windows_grant_admin: false # Darwin options -buildkite_agent_load_bash_profile: yes +buildkite_agent_load_bash_profile: true diff --git a/examples/site.yml b/examples/site.yml index 26ba46b..15f4510 100644 --- a/examples/site.yml +++ b/examples/site.yml @@ -1,6 +1,6 @@ --- - hosts: all - become: True + become: true pre_tasks: - name: Update APT cache diff --git a/tasks/install-on-Darwin.yml b/tasks/install-on-Darwin.yml index 99adea7..847506b 100644 --- a/tasks/install-on-Darwin.yml +++ b/tasks/install-on-Darwin.yml @@ -9,7 +9,7 @@ - homebrew: name: buildkite-agent state: latest - update_homebrew: yes + update_homebrew: true - name: Configure Buildkite template: diff --git a/tasks/install-on-Debian.yml b/tasks/install-on-Debian.yml index 84a3254..053bbbf 100644 --- a/tasks/install-on-Debian.yml +++ b/tasks/install-on-Debian.yml @@ -36,7 +36,7 @@ - name: Turn off the installed service service: name: buildkite-agent - enabled: no + enabled: false state: stopped - name: "Create buildkite-agent service instances" diff --git a/tasks/install-on-Windows.yml b/tasks/install-on-Windows.yml index 44e51d7..9cb967e 100644 --- a/tasks/install-on-Windows.yml +++ b/tasks/install-on-Windows.yml @@ -10,8 +10,8 @@ name: "buildkite-agent" # TODO: Single static file with no isolation between runs is unsafe (but that's unlikely to occur) password: "{{ user_password }}" - password_never_expires: yes - user_cannot_change_password: yes + password_never_expires: true + user_cannot_change_password: true - name: grant administrator privileges to user win_group_membership: @@ -41,7 +41,7 @@ src: 'c:/windows/temp/buildkite-agent-windows-{{ buildkite_agent_platform }}-{{ buildkite_agent_version }}.zip' dest: 'c:/program files/buildkite-agent' creates: 'c:/program files/buildkite-agent/buildkite-agent.exe' - delete_archive: yes + delete_archive: true - name: delete the shipped configuration stub to avoid binary picking it up (buildkite/agent#881) win_file: From 97a55cacbd334350408c07f8615eb0ccb26d6d7c Mon Sep 17 00:00:00 2001 From: Peter Mounce Date: Tue, 11 Dec 2018 15:23:05 +0000 Subject: [PATCH 3/9] Need a systemd-capable image, ubuntu flavour, with apt-transport-https --- molecule/default/molecule.yml | 7 ++++++- molecule/default/playbook.yml | 2 ++ molecule/default/prepare.yml | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 molecule/default/prepare.yml diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index f5e3b11..54a2a8c 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -7,7 +7,12 @@ lint: name: yamllint platforms: - name: instance - image: centos:7 + image: solita/ubuntu-systemd:latest + command: /sbin/init + capabilities: + - SYS_ADMIN + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro provisioner: name: ansible lint: diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml index 1d76e7f..c7269b7 100644 --- a/molecule/default/playbook.yml +++ b/molecule/default/playbook.yml @@ -1,5 +1,7 @@ --- - name: Converge hosts: all + become: true + roles: - role: ansible-buildkite-agent diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml new file mode 100644 index 0000000..255fe4b --- /dev/null +++ b/molecule/default/prepare.yml @@ -0,0 +1,10 @@ +--- +- name: Prepare + hosts: all + become: true + + tasks: + - name: install apt-transport-https + apt: + pkg: apt-transport-https + state: present From ddd9822acaf1fd9145d7cd514733017374c8a185 Mon Sep 17 00:00:00 2001 From: Peter Mounce Date: Mon, 17 Dec 2018 12:03:20 +0000 Subject: [PATCH 4/9] Unpack the line to attributes for easier diff and linting. --- tasks/install-on-Debian.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tasks/install-on-Debian.yml b/tasks/install-on-Debian.yml index 053bbbf..1494674 100644 --- a/tasks/install-on-Debian.yml +++ b/tasks/install-on-Debian.yml @@ -40,5 +40,8 @@ state: stopped - name: "Create buildkite-agent service instances" - systemd: name=buildkite-agent@{{item}} state=started enabled=yes + systemd: + name: buildkite-agent@{{ item }}.service + state: started + enabled: true with_sequence: start=1 end={{buildkite_agent_count}} stride=1 From 7e0a6e29cb669834f78bf3c382fde798cd79132e Mon Sep 17 00:00:00 2001 From: Peter Mounce Date: Mon, 17 Dec 2018 12:03:34 +0000 Subject: [PATCH 5/9] Quotes unnecessary --- tasks/install-on-Debian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/install-on-Debian.yml b/tasks/install-on-Debian.yml index 1494674..87512f5 100644 --- a/tasks/install-on-Debian.yml +++ b/tasks/install-on-Debian.yml @@ -39,7 +39,7 @@ enabled: false state: stopped -- name: "Create buildkite-agent service instances" +- name: create buildkite-agent service instances systemd: name: buildkite-agent@{{ item }}.service state: started From c252cd78c901a9a8d938fe48547e98bca70b41a0 Mon Sep 17 00:00:00 2001 From: Peter Mounce Date: Mon, 17 Dec 2018 12:03:52 +0000 Subject: [PATCH 6/9] daemon_reload is needed? --- tasks/install-on-Debian.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tasks/install-on-Debian.yml b/tasks/install-on-Debian.yml index 87512f5..a21dfe3 100644 --- a/tasks/install-on-Debian.yml +++ b/tasks/install-on-Debian.yml @@ -34,14 +34,16 @@ # because: we run the template unit - name: Turn off the installed service - service: - name: buildkite-agent + systemd: + name: buildkite-agent.service + daemon_reload: true enabled: false state: stopped - name: create buildkite-agent service instances systemd: name: buildkite-agent@{{ item }}.service + daemon_reload: true state: started enabled: true with_sequence: start=1 end={{buildkite_agent_count}} stride=1 From dbaaa3d6986797f9aa79a139779d9452e18db1a8 Mon Sep 17 00:00:00 2001 From: Peter Mounce Date: Mon, 17 Dec 2018 12:03:58 +0000 Subject: [PATCH 7/9] syntax --- tasks/install-on-Debian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/install-on-Debian.yml b/tasks/install-on-Debian.yml index a21dfe3..5f2a986 100644 --- a/tasks/install-on-Debian.yml +++ b/tasks/install-on-Debian.yml @@ -46,4 +46,4 @@ daemon_reload: true state: started enabled: true - with_sequence: start=1 end={{buildkite_agent_count}} stride=1 + with_sequence: start=1 end={{ buildkite_agent_count }} stride=1 From fc8f1301dea191bdfd83bf1af9ea2c8796b829a8 Mon Sep 17 00:00:00 2001 From: Peter Mounce Date: Fri, 21 Dec 2018 18:36:33 +0000 Subject: [PATCH 8/9] wire up travis --- .travis.yml | 10 ++++++++++ requirements.txt | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6e2dbfc --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +--- +sudo: required +language: python +services: + - docker +before_install: + - sudo apt-get -qq update + - pip install -r requirements.txt +script: + - molecule test diff --git a/requirements.txt b/requirements.txt index e5c2833..dd59384 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -ansible==2.7.4 +ansible==2.7.5 molecule==2.19.0 docker==3.6.0 From df8b13d3e59980f90d30e1dd24a182302c3e55f9 Mon Sep 17 00:00:00 2001 From: Peter Mounce Date: Mon, 24 Dec 2018 12:04:52 +0000 Subject: [PATCH 9/9] according to docs, these are needed? --- molecule/default/molecule.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 54a2a8c..efe85f3 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -8,6 +8,7 @@ lint: platforms: - name: instance image: solita/ubuntu-systemd:latest + privileged: true command: /sbin/init capabilities: - SYS_ADMIN @@ -15,6 +16,8 @@ platforms: - /sys/fs/cgroup:/sys/fs/cgroup:ro provisioner: name: ansible + options: + vvv: true lint: name: ansible-lint scenario: