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/.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/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/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..efe85f3 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,28 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: instance + image: solita/ubuntu-systemd:latest + privileged: true + command: /sbin/init + capabilities: + - SYS_ADMIN + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro +provisioner: + name: ansible + options: + vvv: true + 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..c7269b7 --- /dev/null +++ b/molecule/default/playbook.yml @@ -0,0 +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 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 0000000..93383a4 Binary files /dev/null and b/molecule/default/tests/test_default.pyc differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..dd59384 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +ansible==2.7.5 +molecule==2.19.0 +docker==3.6.0 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..5f2a986 100644 --- a/tasks/install-on-Debian.yml +++ b/tasks/install-on-Debian.yml @@ -34,11 +34,16 @@ # because: we run the template unit - name: Turn off the installed service - service: - name: buildkite-agent - enabled: no + systemd: + name: buildkite-agent.service + daemon_reload: true + enabled: false state: stopped -- name: "Create buildkite-agent service instances" - systemd: name=buildkite-agent@{{item}} state=started enabled=yes - with_sequence: start=1 end={{buildkite_agent_count}} stride=1 +- 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 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: