From 4ffb8aef4ec486e4729ea05e415d594ec34d458a Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 09:51:53 +0000 Subject: [PATCH 01/13] docs: remove Travis CI badges --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a329f2e..9caca09 100644 --- a/README.md +++ b/README.md @@ -5,20 +5,20 @@ [![GitHub release](https://img.shields.io/github/release/markosamuli/ansible-linuxbrew.svg)](https://github.com/markosamuli/ansible-linuxbrew/releases) [![License](https://img.shields.io/github/license/markosamuli/ansible-linuxbrew.svg)](https://github.com/markosamuli/ansible-linuxbrew/blob/master/LICENSE) -| Branch | Status | -|---------|--------| -| master | [![Build Status](https://travis-ci.org/markosamuli/ansible-linuxbrew.svg?branch=master)](https://travis-ci.org/markosamuli/ansible-linuxbrew) -| develop | [![Build Status](https://travis-ci.org/markosamuli/ansible-linuxbrew.svg?branch=develop)](https://travis-ci.org/markosamuli/ansible-linuxbrew) - Ansible role to install [Linuxbrew](http://linuxbrew.sh/) on Ubuntu. +I'm not actively using or maintaining this role. The role used Travis CI for +testing and publishing the releases, but since June 15th, 2021, the building +on [travis-ci.org](https://www.travis-ci.org/) is ceased and I have stopped +using Travis CI on my OSS projects. + ## Configuration By default, the role uses Ansible to clone the Homebrew Git repository and create all relevant directories. -To use the official [Homebrew installer] script instead, you need to enable this -in the Ansible configuration: +To use the official [Homebrew installer][homebrew-installer] script instead, +you need to enable this in the Ansible configuration: ```yaml linuxbrew_use_installer: true @@ -52,14 +52,15 @@ make test ## License -* [BSD License](LICENSE) +- [BSD License](LICENSE) ## Contributions -The installation is based on the official [Homebrew installer] script. +The installation is based on the official [Homebrew installer][homebrew-installer] +script. -[Homebrew installer]: https://github.com/Linuxbrew/install +[homebrew-installer]: https://github.com/Linuxbrew/install ## Author Information -* [@markosamuli](https://github.com/markosamuli) +- [@markosamuli](https://github.com/markosamuli) From 0f094be826e82ef97a5e946823ea63b3846c4418 Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 09:52:37 +0000 Subject: [PATCH 02/13] chore: remove EOL Ubuntu Xenial image --- tests/xenial/Dockerfile | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 tests/xenial/Dockerfile diff --git a/tests/xenial/Dockerfile b/tests/xenial/Dockerfile deleted file mode 100644 index 8b52cea..0000000 --- a/tests/xenial/Dockerfile +++ /dev/null @@ -1,40 +0,0 @@ -FROM ubuntu:xenial - -RUN apt-get update && apt-get install -y \ - python-minimal \ - python-pip \ - && rm -rf /var/lib/apt/lists/* - -ARG ansible_version="<2.9.0" -ENV ANSIBLE_VERSION="${ansible_version}" -RUN pip install ansible${ANSIBLE_VERSION} - -RUN apt-get update && apt-get install -y \ - zsh \ - sudo \ - && rm -rf /var/lib/apt/lists/* - -RUN apt-get update && apt-get install -y \ - aptitude \ - && rm -rf /var/lib/apt/lists/* - -ARG user=test -ARG repository=ansible-linuxbrew - -# Create test user -RUN useradd -m ${user} -s /bin/bash \ - && echo "${user}:${user}" | chpasswd \ - && adduser ${user} sudo \ - && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers -RUN touch /home/${user}/.zshrc \ - && chown -R ${user}:${user} /home/${user} - -# Create directory for code -RUN mkdir -p /home/${user}/${repository} ; \ - chown -R ${user}:${user} /home/${user}/${repository} -VOLUME ["/home/${user}/${repository}"] - -# Make sure we have the latest packages -RUN apt-get update - -CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" From aaa5f3cc27301cd1cf7a61392a44e623ce3c2f8b Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 09:53:54 +0000 Subject: [PATCH 03/13] chore: remove EOL Debian Stretch image --- tests/stretch/Dockerfile | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 tests/stretch/Dockerfile diff --git a/tests/stretch/Dockerfile b/tests/stretch/Dockerfile deleted file mode 100644 index a3df167..0000000 --- a/tests/stretch/Dockerfile +++ /dev/null @@ -1,40 +0,0 @@ -FROM debian:stretch - -RUN apt-get update && apt-get install -y \ - python-minimal \ - python-pip \ - && rm -rf /var/lib/apt/lists/* - -ARG ansible_version="<2.9.0" -ENV ANSIBLE_VERSION="${ansible_version}" -RUN pip install ansible${ANSIBLE_VERSION} - -RUN apt-get update && apt-get install -y \ - zsh \ - sudo \ - && rm -rf /var/lib/apt/lists/* - -RUN apt-get update && apt-get install -y \ - aptitude \ - && rm -rf /var/lib/apt/lists/* - -ARG user=test -ARG repository=ansible-linuxbrew - -# Create test user -RUN useradd -m ${user} -s /bin/bash \ - && echo "${user}:${user}" | chpasswd \ - && adduser ${user} sudo \ - && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers -RUN touch /home/${user}/.zshrc \ - && chown -R ${user}:${user} /home/${user} - -# Create directory for code -RUN mkdir -p /home/${user}/${repository} ; \ - chown -R ${user}:${user} /home/${user}/${repository} -VOLUME ["/home/${user}/${repository}"] - -# Make sure we have the latest packages -RUN apt-get update - -CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" From ee4fc3e3715bac279b38a34205aaf95905792b0f Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 09:58:11 +0000 Subject: [PATCH 04/13] docs: mention Ansible 2.8 as the latest tested version --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9caca09..a80f3fc 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ testing and publishing the releases, but since June 15th, 2021, the building on [travis-ci.org](https://www.travis-ci.org/) is ceased and I have stopped using Travis CI on my OSS projects. +I've tested the role up to Ansible 2.8 using local installation. + ## Configuration By default, the role uses Ansible to clone the Homebrew Git repository and From 666a6341302da5030265a8d0c9888c7bc36ba025 Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 16:41:58 +0000 Subject: [PATCH 05/13] feat: support RedHad-based systems and latest Ansible versions Fixes #8, #10 --- .ansible-lint | 4 +- .pre-commit-config.yaml | 32 ++-- CHANGELOG.md | 51 ++++-- Makefile | 31 +++- README.md | 28 +++- defaults/main.yml | 1 - meta/main.yml | 16 +- tasks/install.yml | 13 -- .../debian.yml} | 3 +- tasks/install/install.yml | 16 ++ tasks/install/redhat.yml | 7 + .../with_git.yml} | 37 +++-- .../with_installer.yml} | 18 +-- tasks/main.yml | 12 +- tasks/shell/bash.yml | 139 ++++++++++++++++ tasks/{ => shell}/shell.yml | 7 +- tasks/shell/zsh.yml | 78 +++++++++ tasks/shell_bash.yml | 24 --- tasks/shell_zsh.yml | 24 --- tests/Dockerfile.template | 37 ----- tests/bionic/Dockerfile | 46 ++++-- tests/bullseye/Dockerfile | 43 +++++ tests/buster/Dockerfile | 40 +++-- tests/fedora37/Dockerfile | 33 ++++ tests/focal/Dockerfile | 44 +++++ tests/inventory | 2 +- tests/jammy/Dockerfile | 44 +++++ tests/run-tests | 153 +++++++++++------- tests/run-tests-with-git | 41 +++-- tests/run-tests-with-installer | 41 +++-- tests/test.yml | 4 +- tests/update | 37 ----- vars/main.yml | 1 - vars/os/Debian.yml | 5 +- vars/os/RedHat.yml | 10 ++ 35 files changed, 785 insertions(+), 337 deletions(-) delete mode 100644 tasks/install.yml rename tasks/{install_debian.yml => install/debian.yml} (87%) create mode 100644 tasks/install/install.yml create mode 100644 tasks/install/redhat.yml rename tasks/{install_with_git.yml => install/with_git.yml} (75%) rename tasks/{install_with_installer.yml => install/with_installer.yml} (55%) create mode 100644 tasks/shell/bash.yml rename tasks/{ => shell}/shell.yml (74%) create mode 100644 tasks/shell/zsh.yml delete mode 100644 tasks/shell_bash.yml delete mode 100644 tasks/shell_zsh.yml delete mode 100644 tests/Dockerfile.template create mode 100644 tests/bullseye/Dockerfile create mode 100644 tests/fedora37/Dockerfile create mode 100644 tests/focal/Dockerfile create mode 100644 tests/jammy/Dockerfile delete mode 100755 tests/update create mode 100644 vars/os/RedHat.yml diff --git a/.ansible-lint b/.ansible-lint index 9be5545..a6d1e2d 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -1,2 +1,4 @@ +--- exclude_paths: -- .travis.yml + - .travis.yml + - .ansible-lint diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4f128e5..f7502d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,51 +1,45 @@ -# -*- mode: yaml -*- -# vim:ts=2:sw=2:ai:si:syntax=yaml -################################ -# pre-commit hooks configuration -################################ --- - repos: - repo: https://github.com/pre-commit/pre-commit-hooks.git - rev: v2.2.3 + rev: v4.4.0 hooks: - id: check-executables-have-shebangs - id: check-byte-order-marker - id: check-case-conflict - id: check-merge-conflict - id: trailing-whitespace - args: ['--markdown-linebreak-ext=md'] + args: ["--markdown-linebreak-ext=md"] - id: end-of-file-fixer - id: mixed-line-ending - args: ['--fix=lf'] + args: ["--fix=lf"] - id: check-yaml - id: pretty-format-json - args: ['--autofix', '--indent=2', '--no-sort-keys'] + args: ["--autofix", "--indent=2", "--no-sort-keys"] - repo: https://github.com/adrienverge/yamllint.git - rev: v1.16.0 + rev: v1.29.0 hooks: - id: yamllint - repo: https://github.com/ansible/ansible-lint.git - rev: v4.1.0 + rev: v6.13.1 hooks: - id: ansible-lint files: \.(yaml|yml)$ - - repo: https://github.com/bemeurer/beautysh.git - rev: '4.1' + - repo: https://github.com/syntaqx/git-hooks + rev: v0.0.17 hooks: - - id: beautysh + - id: shellcheck files: (tests/run-.*|tests/update)$ - - repo: https://github.com/openstack-dev/bashate.git - rev: '0.6.0' + - repo: https://github.com/scop/pre-commit-shfmt + rev: v3.6.0-1 hooks: - - id: bashate + - id: shfmt files: (tests/run-.*|tests/update)$ - repo: https://github.com/igorshubovych/markdownlint-cli.git - rev: v0.17.0 + rev: v0.33.0 hooks: - id: markdownlint diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cc9d09..360137b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,44 +1,77 @@ # Changelog +## [2.0.0] - 2023-02-17 + +### Ansible compatibility + +- Require Ansible 2.9.22 +- Support Ansible 7.2.0 +- Use fully qualified collection names (FQCN) with builtin modules + +### Fixes + +- Use `become_user` instead of `become` when installing with Git by [@Hunsu] in [#6] +- Remove installer script checksum that causes issues [#10] + +[@hunsu]: https://github.com/Hunsu +[#6]: https://github.com/markosamuli/ansible-linuxbrew/pull/6 +[#10]: https://github.com/markosamuli/ansible-linuxbrew/issues/10 + +### Python compatibility + +- Use Python 3 on all test Docker images +- Drop support for EOL Python 2.7 + +### OS compatibility + +- Add support for Ubuntu 20.04 LTS and 22.04 LTS +- Add support for Debian 11 +- Add support for Fedora 37 and RedHat based-systems by [@aarey] in [#9] +- Drop support for Debian 11 +- Drop support for Ubuntu 16.04 LTS + +[@aarey]: https://github.com/aairey +[#9]: https://github.com/markosamuli/ansible-linuxbrew/pull/9 + ## [1.2.2] - 2020-09-06 ### Fixed -* Update `install.sh` checksum -* Create missing `var/homebrew/linked` directory -* Update `linuxbrew-core` repository URL +- Update `install.sh` checksum +- Create missing `var/homebrew/linked` directory +- Update `linuxbrew-core` repository URL ## [1.2.1] - 2020-09-05 ### Fixed -* Migrate to the new `install.sh` script +- Migrate to the new `install.sh` script ## [1.2.0] - 2019-10-25 ### Changes -* Add `linuxbrew_init_shell` variable to allow shell file modification to be +- Add `linuxbrew_init_shell` variable to allow shell file modification to be disabled. Fixes [#1] ## [1.1.1] - 2019-07-20 ### Fixes -* Updated `install.sh` checksum for the 2019-07-18 updated version. +- Updated `install.sh` checksum for the 2019-07-18 updated version. ## [1.1.0] - 2019-07-14 ### Changes -* Use Ansible tasks to clone the Homebrew Git repositories, create directories +- Use Ansible tasks to clone the Homebrew Git repositories, create directories and set permissions where possible instead of using the official installer bash script. ### Fixes -* Install installation dependencies. -* Update both `.bashrc` and `.zshrc` shell scripts. +- Install installation dependencies. +- Update both `.bashrc` and `.zshrc` shell scripts. ## [1.0.0] - 2019-01-13 diff --git a/Makefile b/Makefile index 75d757d..65fbe03 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,33 @@ -PRE_COMMIT_HOOKS=.git/hooks/pre-commit + +.DEFAULT_GOAL := help + +# Use VERBOSE=1 make to get verbose output +ifndef VERBOSE +.SILENT: +endif + +.PHONY: help +help: ## print this help + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort -d | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +PRE_COMMIT_HOOKS = .git/hooks/pre-commit + +TEST_IMAGES = $(shell ls tests/*/Dockerfile | xargs dirname | xargs basename) + +.PHONY: setup +setup: $(PRE_COMMIT_HOOKS) .PHONY: test -test: - @./tests/run-tests +test: ## run tests with all available Docker images + ./tests/run-tests + +.PHONY: $(TEST_IMAGES) +$(TEST_IMAGES): + ./tests/run-tests $@ .PHONY: lint lint: $(PRE_COMMIT_HOOKS) - @pre-commit run -a + pre-commit run -a $(PRE_COMMIT_HOOKS): - @pre-commit install + pre-commit install diff --git a/README.md b/README.md index a80f3fc..836b6d9 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,30 @@ using Travis CI on my OSS projects. I've tested the role up to Ansible 2.8 using local installation. +## Compatibility + +Run tests with a supported Docker image, for example with `bionic`: + +```bash +make bionic +``` + +| Release | Docker image | Ansible | +| ---------------- | ---------------------- | ---------------- | +| Ubuntu 18.04 LTS | [`bionic`][bionic] | `<2.12,>=2.9.22` | +| Ubuntu 20.04 LTS | [`focal`][focal] | `>=2.9.22` | +| Ubuntu 22.04 LTS | [`jammy`][jammy] | `>=2.9.22` | +| Debian 10 | [`buster`][buster] | `<2.12,>=2.9.22` | +| Debian 11 | [`bullseye`][bullseye] | `>=2.9.22` | +| Fedora 37 | [`fedora37`][fedora37] | `>=2.9.22` | + +[bionic]: tests/bionic/Dockerfile +[focal]: tests/focal/Dockerfile +[jammy]: tests/jammy/Dockerfile +[buster]: tests/buster/Dockerfile +[bullseye]: tests/buster/Dockerfile +[fedora37]: tests/fedora37/Dockerfile + ## Configuration By default, the role uses Ansible to clone the Homebrew Git repository and @@ -26,10 +50,12 @@ you need to enable this in the Ansible configuration: linuxbrew_use_installer: true ``` +The installer seems to be faster than the default Ansible installation method. + ## Role Variables Set `linuxbrew_init_shell` to `false` if you're for example managing your shell -rc files using your own .dotfiles repository. +init files using your own `.dotfiles` repository. ```yaml # Configure shell rc files diff --git a/defaults/main.yml b/defaults/main.yml index 0f7730c..52f6585 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,4 @@ --- - # Path to user home directory linuxbrew_home: "{{ ansible_env.HOME }}" diff --git a/meta/main.yml b/meta/main.yml index d3b6179..e67c981 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,23 +1,27 @@ # -*- mode: yaml -*- # vim:ts=2:sw=2:ai:si:syntax=yaml --- - galaxy_info: role_name: linuxbrew + namespace: markosamuli author: Marko Samuli Kirves - description: Install Linuxbrew - license: MIT - min_ansible_version: 2.6 + description: Install Homebrew on Linux + license: BSD + min_ansible_version: 2.9.22 github_branch: master platforms: - name: Ubuntu versions: - - xenial - bionic + - focal + - jammy - name: Debian versions: - buster - - stretch + - bullseye + - name: Fedora + versions: + - "37" galaxy_tags: - linuxbrew - homebrew diff --git a/tasks/install.yml b/tasks/install.yml deleted file mode 100644 index 73f275c..0000000 --- a/tasks/install.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- - -- name: Install dependencies on Debian based systems - include_tasks: install_debian.yml - when: "ansible_os_family == 'Debian' or ansible_distribution == 'Pengwin'" - -- name: Install with Git - include_tasks: install_with_git.yml - when: not linuxbrew_use_installer - -- name: Install using the installer script - include_tasks: install_with_installer.yml - when: linuxbrew_use_installer diff --git a/tasks/install_debian.yml b/tasks/install/debian.yml similarity index 87% rename from tasks/install_debian.yml rename to tasks/install/debian.yml index ce7162b..da68bc4 100644 --- a/tasks/install_debian.yml +++ b/tasks/install/debian.yml @@ -1,7 +1,6 @@ --- - - name: Install dependencies with APT - apt: + ansible.builtin.apt: name: "{{ linuxbrew_install_dependencies }}" when: linuxbrew_install_dependencies is defined become: true diff --git a/tasks/install/install.yml b/tasks/install/install.yml new file mode 100644 index 0000000..8dc8fff --- /dev/null +++ b/tasks/install/install.yml @@ -0,0 +1,16 @@ +--- +- name: Install dependencies on Debian based systems + ansible.builtin.include_tasks: debian.yml + when: "ansible_os_family == 'Debian' or ansible_distribution == 'Pengwin'" + +- name: Install dependencies on RedHat based systems + ansible.builtin.include_tasks: redhat.yml + when: "ansible_os_family == 'RedHat'" + +- name: Install with Git + ansible.builtin.include_tasks: with_git.yml + when: not linuxbrew_use_installer + +- name: Install using the installer script + ansible.builtin.include_tasks: with_installer.yml + when: linuxbrew_use_installer diff --git a/tasks/install/redhat.yml b/tasks/install/redhat.yml new file mode 100644 index 0000000..f3a7890 --- /dev/null +++ b/tasks/install/redhat.yml @@ -0,0 +1,7 @@ +--- +- name: Install dependencies with yum + ansible.builtin.yum: + name: "{{ linuxbrew_install_dependencies }}" + state: present + when: linuxbrew_install_dependencies is defined + become: true diff --git a/tasks/install_with_git.yml b/tasks/install/with_git.yml similarity index 75% rename from tasks/install_with_git.yml rename to tasks/install/with_git.yml index cfef894..43d79fb 100644 --- a/tasks/install_with_git.yml +++ b/tasks/install/with_git.yml @@ -1,23 +1,28 @@ --- +- name: Get current user + ansible.builtin.command: whoami + register: linuxbrew_whoami + changed_when: false + become: false - name: Set Linuxbrew user - set_fact: - linuxbrew_user: "{{ ansible_user }}" + ansible.builtin.set_fact: + linuxbrew_user: "{{ linuxbrew_whoami.stdout }}" when: linuxbrew_user is undefined - name: Get group for user {{ linuxbrew_user }} - command: id -g + ansible.builtin.command: id -g register: linuxbrew_user_group become_user: "{{ linuxbrew_user }}" changed_when: false - name: Set Linuxbrew group - set_fact: + ansible.builtin.set_fact: linuxbrew_group: "{{ linuxbrew_user_group.stdout }}" when: linuxbrew_group is undefined - name: Create Linuxbrew directory - file: + ansible.builtin.file: path: "{{ linuxbrew_prefix_shared }}" state: directory owner: "{{ linuxbrew_user }}" @@ -26,7 +31,7 @@ become: true - name: Create Linuxbrew directories - file: + ansible.builtin.file: path: "{{ linuxbrew_prefix_shared }}/{{ item }}" state: directory owner: "{{ linuxbrew_user }}" @@ -50,23 +55,23 @@ - Frameworks - name: Set path to Homebrew repository - set_fact: + ansible.builtin.set_fact: linuxbrew_repository: "{{ linuxbrew_prefix_shared }}/Homebrew" - name: Clone Homebrew repository - git: + ansible.builtin.git: repo: "{{ linuxbrew_brew_repo }}" dest: "{{ linuxbrew_repository }}" version: "{{ linuxbrew_brew_version }}" -- name: Clone Linuxbrew Core Tap repository - git: +- name: Clone Homebrew Core Tap repository + ansible.builtin.git: repo: "{{ linuxbrew_core_tap_repo }}" dest: "{{ linuxbrew_repository }}/Library/Taps/homebrew/homebrew-core" version: "{{ linuxbrew_core_tap_version }}" - name: Update permissions - file: + ansible.builtin.file: path: "{{ item }}" owner: "{{ linuxbrew_user }}" group: "{{ linuxbrew_group }}" @@ -76,21 +81,23 @@ - "{{ linuxbrew_repository }}/Library/Taps/homebrew/homebrew-core" - name: Create symlink to brew binary - file: + ansible.builtin.file: dest: "{{ linuxbrew_prefix_shared }}/bin/brew" src: "{{ linuxbrew_repository }}/bin/brew" state: "link" when: linuxbrew_prefix_shared != linuxbrew_repository - name: Path to portable-ruby vendor directory - set_fact: + ansible.builtin.set_fact: + # yamllint disable-line rule:line-length linuxbrew_ruby_current: "{{ linuxbrew_repository }}/vendor/portable-ruby/current" - name: Path to portable-ruby binary - set_fact: + ansible.builtin.set_fact: linuxbrew_ruby_path: "{{ linuxbrew_ruby_current }}/bin/ruby" - name: Update Homebrew to install portable Ruby - command: "{{ linuxbrew_prefix_shared }}/bin/brew update --force" + # yamllint disable-line rule:line-length + ansible.builtin.command: "{{ linuxbrew_prefix_shared }}/bin/brew update --force" args: creates: "{{ linuxbrew_ruby_path }}" diff --git a/tasks/install_with_installer.yml b/tasks/install/with_installer.yml similarity index 55% rename from tasks/install_with_installer.yml rename to tasks/install/with_installer.yml index 80cb924..3194556 100644 --- a/tasks/install_with_installer.yml +++ b/tasks/install/with_installer.yml @@ -1,27 +1,27 @@ --- - - name: Temporary directory - file: + ansible.builtin.file: path: "{{ linuxbrew_install_tmp }}" state: directory + mode: 0700 become: false -- name: Download Linuxbrew install script - get_url: +- name: Download Homebrew install script + ansible.builtin.get_url: url: "{{ linuxbrew_install_url }}" dest: "{{ linuxbrew_install_tmp }}/install.sh" - checksum: "{{ linuxbrew_install_checksum }}" - mode: 0777 + checksum: "{{ linuxbrew_install_checksum | default(omit) }}" + mode: 0700 become: false -- name: Install Linuxbrew - command: sh -c "{{ linuxbrew_install_tmp }}/install.sh" +- name: Install Homebrew with the installer + ansible.builtin.command: sh -c "{{ linuxbrew_install_tmp }}/install.sh" register: install_result changed_when: "install_result.rc == 0" become: false - name: Remove temporary directory - file: + ansible.builtin.file: path: "{{ linuxbrew_install_tmp }}" state: absent become: false diff --git a/tasks/main.yml b/tasks/main.yml index 0c8b297..e784e06 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,28 +2,28 @@ # tasks file for markosamuli.linuxbrew - name: Load variables for the target system - include_vars: "{{ item }}" + ansible.builtin.include_vars: "{{ item }}" with_first_found: - "os/{{ ansible_distribution }}.yml" - "os/{{ ansible_os_family }}.yml" - name: Check if Linuxbrew is already installed in {{ linuxbrew_prefix_shared }} - stat: + ansible.builtin.stat: path: "{{ linuxbrew_prefix_shared }}/bin/brew" register: linuxbrew_shared_st become: true - name: Check if Linuxbrew is already installed in {{ linuxbrew_prefix_user }} - stat: + ansible.builtin.stat: path: "{{ linuxbrew_prefix_user }}/bin/brew" register: linuxbrew_user_st become: false - name: Install Linuxbrew - include_tasks: install.yml + ansible.builtin.include_tasks: install/install.yml when: not linuxbrew_shared_st.stat.exists - and not linuxbrew_user_st.stat.exists + and not linuxbrew_user_st.stat.exists - name: Configure Linuxbrew in shell - include_tasks: shell.yml + ansible.builtin.include_tasks: shell/shell.yml when: linuxbrew_init_shell|bool diff --git a/tasks/shell/bash.yml b/tasks/shell/bash.yml new file mode 100644 index 0000000..c430a7c --- /dev/null +++ b/tasks/shell/bash.yml @@ -0,0 +1,139 @@ +--- +- name: Find .bash_profile and .profile files + block: + - name: Set path to .bash_profile + ansible.builtin.set_fact: + linuxbrew_bash_profile_path: "{{ linuxbrew_home }}/.bash_profile" + when: linuxbrew_bash_profile_path is undefined + + - name: Check whether .bash_profile exists + ansible.builtin.stat: + path: "{{ linuxbrew_bash_profile_path }}" + register: linuxbrew_bash_profile_st + + - name: Set path to .profile + ansible.builtin.set_fact: + linuxbrew_profile_path: "{{ linuxbrew_home }}/.profile" + when: linuxbrew_profile_path is undefined + + - name: Check whether .profile exists + ansible.builtin.stat: + path: "{{ linuxbrew_profile_path }}" + register: linuxbrew_profile_st + +- name: Configure .bash_profile (if it exists) + when: linuxbrew_bash_profile_st.stat.exists + block: + - name: Resolve .bash_profile symlink + ansible.builtin.set_fact: + # yamllint disable-line rule:line-length + linuxbrew_bash_profile_path: "{{ linuxbrew_bash_profile_st.stat.lnk_source }}" + when: + - linuxbrew_bash_profile_st.stat.exists + - linuxbrew_bash_profile_st.stat.islnk + + - name: Check whether Homebrew is loaded in .bash_profile + ansible.builtin.command: >- + grep -Fq 'brew shellenv' {{ linuxbrew_bash_profile_path }} + register: check_bash_profile + ignore_errors: true + changed_when: false + failed_when: false + when: linuxbrew_bash_profile_st.stat.exists + + - name: Load Homebrew in .bash_profile + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_bash_profile_path }}" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + when: + - linuxbrew_bash_profile_st.stat.exists + - check_bash_profile.rc != 0 + + - name: Create new .bash_profile + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_bash_profile_path }}" + create: true + mode: "0644" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + when: not linuxbrew_bash_profile_st.stat.exists + +- name: Configure .profile (if it exists) + when: not linuxbrew_bash_profile_st.stat.exists + block: + - name: Resolve .profile symlink + ansible.builtin.set_fact: + linuxbrew_profile_path: "{{ linuxbrew_profile_st.stat.lnk_source }}" + when: + - linuxbrew_profile_st.stat.exists + - linuxbrew_profile_st.stat.islnk + + - name: Check whether Homebrew is loaded in .profile + ansible.builtin.command: >- + grep -Fq 'brew shellenv' {{ linuxbrew_profile_path }} + register: check_profile + ignore_errors: true + changed_when: false + failed_when: false + when: linuxbrew_profile_st.stat.exists + + - name: Load Homebrew in .profile + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_profile_path }}" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + when: + - linuxbrew_profile_st.stat.exists + - check_profile.rc != 0 + + - name: Create new .profile + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_profile_path }}" + create: true + mode: "0644" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + when: not linuxbrew_profile_st.stat.exists + +- name: Configure .bashrc (if it exists) + block: + - name: Set path to .bashrc + ansible.builtin.set_fact: + linuxbrew_bashrc_path: "{{ linuxbrew_home }}/.bashrc" + when: linuxbrew_bashrc_path is undefined + + - name: Check whether .bashrc file exists + ansible.builtin.stat: + path: "{{ linuxbrew_bashrc_path }}" + register: linuxbrew_bashrc_st + + - name: Resolve .bashrc symlink + ansible.builtin.set_fact: + linuxbrew_bashrc_path: "{{ linuxbrew_bashrc_st.stat.lnk_source }}" + when: + - linuxbrew_bashrc_st.stat.exists + - linuxbrew_bashrc_st.stat.islnk + + - name: Check whether Homebrew is loaded in .bashrc + ansible.builtin.command: >- + grep -EFq 'brew shellenv' {{ linuxbrew_bashrc_path }} + register: check_bashrc_linuxbrew + ignore_errors: true + changed_when: false + failed_when: false + when: linuxbrew_bashrc_st.stat.exists + + - name: Load Homebrew in .bashrc + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_bashrc_path }}" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + when: + - linuxbrew_bashrc_st.stat.exists + - check_bashrc_linuxbrew.rc != 0 diff --git a/tasks/shell.yml b/tasks/shell/shell.yml similarity index 74% rename from tasks/shell.yml rename to tasks/shell/shell.yml index 84827c8..0cca6a3 100644 --- a/tasks/shell.yml +++ b/tasks/shell/shell.yml @@ -1,7 +1,6 @@ --- - - name: Set path to Linuxbrew prefix - set_fact: + ansible.builtin.set_fact: linuxbrew_prefix: "{{ item }}" with_first_found: - "{{ linuxbrew_prefix_shared }}" @@ -9,9 +8,9 @@ become: true - name: Load Linuxbrew in bash - include_tasks: shell_bash.yml + ansible.builtin.include_tasks: bash.yml when: linuxbrew_prefix is defined - name: Load Linuxbrew in zsh - include_tasks: shell_zsh.yml + ansible.builtin.include_tasks: zsh.yml when: linuxbrew_prefix is defined diff --git a/tasks/shell/zsh.yml b/tasks/shell/zsh.yml new file mode 100644 index 0000000..2cf63a8 --- /dev/null +++ b/tasks/shell/zsh.yml @@ -0,0 +1,78 @@ +--- +- name: Configure .zprofile + block: + - name: Set path to .zprofile + ansible.builtin.set_fact: + linuxbrew_zprofile_path: "{{ linuxbrew_home }}/.zprofile" + when: linuxbrew_zprofile_path is undefined + + - name: Check whether .zprofile exists + ansible.builtin.stat: + path: "{{ linuxbrew_zprofile_path }}" + register: linuxbrew_zprofile_st + + - name: Resolve .zprofile symlink + ansible.builtin.set_fact: + linuxbrew_zprofile_path: "{{ linuxbrew_zprofile_st.stat.lnk_source }}" + when: + - linuxbrew_zprofile_st.stat.exists + - linuxbrew_zprofile_st.stat.islnk + + - name: Check whether pyenv is loaded in .zprofile + ansible.builtin.command: >- + grep -Fq 'brew shellenv' {{ linuxbrew_zprofile_path }} + register: check_zprofile + ignore_errors: true + changed_when: false + failed_when: false + when: linuxbrew_zprofile_st.stat.exists + + - name: Configure .zprofile and create if missing + when: not linuxbrew_zprofile_st.stat.exists or check_zprofile.rc != 0 + block: + - name: Load Homebrew in .zprofile + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_zprofile_path }}" + create: true + mode: "0644" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + +- name: Configure .zshrc (if it exists) + block: + - name: Set path to .zshrc + ansible.builtin.set_fact: + linuxbrew_zshrc_path: "{{ linuxbrew_home }}/.zshrc" + when: linuxbrew_zshrc_path is undefined + + - name: Check whether .zshrc exists + ansible.builtin.stat: + path: "{{ linuxbrew_zshrc_path }}" + register: linuxbrew_zshrc_st + + - name: Resolve .zshrc symlink + ansible.builtin.set_fact: + linuxbrew_zshrc_path: "{{ linuxbrew_zshrc_st.stat.lnk_source }}" + when: + - linuxbrew_zshrc_st.stat.exists + - linuxbrew_zshrc_st.stat.islnk + + - name: Check whether pyenv is loaded in .zshrc + ansible.builtin.command: >- + grep -Fq 'brew shellenv' {{ linuxbrew_zshrc_path }} + register: check_zshrc_linuxbrew + ignore_errors: true + changed_when: false + failed_when: false + when: linuxbrew_zshrc_st.stat.exists + + - name: Load Homebrew in .zshrc + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_zshrc_path }}" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + when: + - linuxbrew_zshrc_st.stat.exists + - check_zshrc_linuxbrew.rc != 0 diff --git a/tasks/shell_bash.yml b/tasks/shell_bash.yml deleted file mode 100644 index 2d68da2..0000000 --- a/tasks/shell_bash.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- - -- name: Set path to .bashrc - set_fact: - linuxbrew_bashrc_path: "{{ linuxbrew_home }}/.bashrc" - when: linuxbrew_bashrc_path is undefined - -- name: Check whether .bashrc file exists - stat: - path: "{{ linuxbrew_bashrc_path }}" - register: linuxbrew_bashrc_st - -- name: Resolve .bashrc symlink - set_fact: - linuxbrew_bashrc_path: "{{ linuxbrew_bashrc_st.stat.lnk_source }}" - when: linuxbrew_bashrc_st.stat.exists and linuxbrew_bashrc_st.stat.islnk - -- name: Load Linuxbrew in .bashrc - blockinfile: - dest: "{{ linuxbrew_bashrc_path }}" - marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" - block: | - eval $({{ linuxbrew_prefix }}/bin/brew shellenv) - when: linuxbrew_bashrc_st.stat.exists diff --git a/tasks/shell_zsh.yml b/tasks/shell_zsh.yml deleted file mode 100644 index 6a34b6f..0000000 --- a/tasks/shell_zsh.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- - -- name: Set path to .zshrc - set_fact: - linuxbrew_zshrc_path: "{{ linuxbrew_home }}/.zshrc" - when: linuxbrew_zshrc_path is undefined - -- name: Check whether .zshrc exists - stat: - path: "{{ linuxbrew_zshrc_path }}" - register: linuxbrew_zshrc_st - -- name: Resolve .zshrc symlink - set_fact: - linuxbrew_zshrc_path: "{{ linuxbrew_zshrc_st.stat.lnk_source }}" - when: linuxbrew_zshrc_st.stat.exists and linuxbrew_zshrc_st.stat.islnk - -- name: Load Linuxbrew in .zshrc - blockinfile: - dest: "{{ linuxbrew_zshrc_path }}" - marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" - block: | - eval $({{ linuxbrew_prefix }}/bin/brew shellenv) - when: linuxbrew_zshrc_st.stat.exists diff --git a/tests/Dockerfile.template b/tests/Dockerfile.template deleted file mode 100644 index 49dcca1..0000000 --- a/tests/Dockerfile.template +++ /dev/null @@ -1,37 +0,0 @@ -FROM %%FROM%% - -RUN apt-get update && apt-get install -y \ - python-minimal \ - python-pip \ - && rm -rf /var/lib/apt/lists/* - -ARG ansible_version="%%ANSIBLE_VERSION%%" -ENV ANSIBLE_VERSION="${ansible_version}" -RUN pip install ansible${ANSIBLE_VERSION} - -RUN apt-get update && apt-get install -y \ - zsh \ - sudo \ - && rm -rf /var/lib/apt/lists/* - -RUN apt-get update && apt-get install -y \ - aptitude \ - && rm -rf /var/lib/apt/lists/* - -ARG user=%%USER%% -ARG repository=%%REPOSITORY%% - -# Create test user -RUN useradd -m ${user} -s /bin/bash \ - && echo "${user}:${user}" | chpasswd \ - && adduser ${user} sudo \ - && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers -RUN touch /home/${user}/.zshrc \ - && chown -R ${user}:${user} /home/${user} - -# Create directory for code -RUN mkdir -p /home/${user}/${repository} ; \ - chown -R ${user}:${user} /home/${user}/${repository} -VOLUME ["/home/${user}/${repository}"] - -CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/bionic/Dockerfile b/tests/bionic/Dockerfile index ef7e289..18ed548 100644 --- a/tests/bionic/Dockerfile +++ b/tests/bionic/Dockerfile @@ -1,37 +1,49 @@ FROM ubuntu:bionic RUN apt-get update && apt-get install -y \ - python-minimal \ - python-pip \ - && rm -rf /var/lib/apt/lists/* + ca-certificates \ + && rm -rf /var/lib/apt/lists/* -ARG ansible_version="<2.9.0" -ENV ANSIBLE_VERSION="${ansible_version}" -RUN pip install ansible${ANSIBLE_VERSION} +# Use a maintained UK-based mirror with HTTPS support +ARG ubuntu_archive=https://mirror.pulsant.com/sites/ubuntu-archive/ +RUN sed -i "s~http://archive.ubuntu.com/ubuntu/~${ubuntu_archive}~g" /etc/apt/sources.list -RUN apt-get update && apt-get install -y \ - zsh \ - sudo \ - && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* +# Python 3.6.9 RUN apt-get update && apt-get install -y \ - aptitude \ - && rm -rf /var/lib/apt/lists/* + zsh \ + sudo \ + python3-minimal \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +# Fixed in Python 3.7 +# https://github.com/pypa/pip/issues/10219 +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 + +# Ansible will require Python 3.8 or newer on the controller starting +# with Ansible 2.12. +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="<2.12,${ansible_version}" +RUN pip3 install ansible${ANSIBLE_VERSION} ARG user=test ARG repository=ansible-linuxbrew # Create test user RUN useradd -m ${user} -s /bin/bash \ - && echo "${user}:${user}" | chpasswd \ - && adduser ${user} sudo \ - && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + && echo "${user}:${user}" | chpasswd \ + && adduser ${user} sudo \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers RUN touch /home/${user}/.zshrc \ - && chown -R ${user}:${user} /home/${user} + && chown -R ${user}:${user} /home/${user} # Create directory for code RUN mkdir -p /home/${user}/${repository} ; \ - chown -R ${user}:${user} /home/${user}/${repository} + chown -R ${user}:${user} /home/${user}/${repository} VOLUME ["/home/${user}/${repository}"] # Make sure we have the latest packages diff --git a/tests/bullseye/Dockerfile b/tests/bullseye/Dockerfile new file mode 100644 index 0000000..b5ac400 --- /dev/null +++ b/tests/bullseye/Dockerfile @@ -0,0 +1,43 @@ +FROM debian:bullseye + +RUN apt-get update && apt-get install -y \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +# Use HTTPS +RUN sed -i "s~http://~https://~g" /etc/apt/sources.list + +RUN apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* + +RUN apt-get update && apt-get install -y \ + zsh \ + sudo \ + python3-minimal \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="${ansible_version}" +RUN pip3 install ansible${ANSIBLE_VERSION} + +ARG user=test +ARG repository=ansible-linuxbrew + +# Create test user +RUN useradd -m ${user} -s /bin/bash \ + && echo "${user}:${user}" | chpasswd \ + && adduser ${user} sudo \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +RUN touch /home/${user}/.zshrc \ + && chown -R ${user}:${user} /home/${user} + +# Create directory for code +RUN mkdir -p /home/${user}/${repository} ; \ + chown -R ${user}:${user} /home/${user}/${repository} +VOLUME ["/home/${user}/${repository}"] + +# Make sure we have the latest packages +RUN apt-get update + +CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/buster/Dockerfile b/tests/buster/Dockerfile index 96a4179..00ad2bb 100644 --- a/tests/buster/Dockerfile +++ b/tests/buster/Dockerfile @@ -1,37 +1,43 @@ FROM debian:buster RUN apt-get update && apt-get install -y \ - python-minimal \ - python-pip \ - && rm -rf /var/lib/apt/lists/* + ca-certificates \ + && rm -rf /var/lib/apt/lists/* -ARG ansible_version="<2.9.0" -ENV ANSIBLE_VERSION="${ansible_version}" -RUN pip install ansible${ANSIBLE_VERSION} +# Use HTTPS +RUN sed -i "s~http://~https://~g" /etc/apt/sources.list -RUN apt-get update && apt-get install -y \ - zsh \ - sudo \ - && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* +# Python 3.7.3 RUN apt-get update && apt-get install -y \ - aptitude \ - && rm -rf /var/lib/apt/lists/* + zsh \ + sudo \ + python3-minimal \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +# Ansible will require Python 3.8 or newer on the controller starting with +# Ansible 2.12 +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="<2.12,${ansible_version}" +RUN pip3 install ansible${ANSIBLE_VERSION} ARG user=test ARG repository=ansible-linuxbrew # Create test user RUN useradd -m ${user} -s /bin/bash \ - && echo "${user}:${user}" | chpasswd \ - && adduser ${user} sudo \ - && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + && echo "${user}:${user}" | chpasswd \ + && adduser ${user} sudo \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers RUN touch /home/${user}/.zshrc \ - && chown -R ${user}:${user} /home/${user} + && chown -R ${user}:${user} /home/${user} # Create directory for code RUN mkdir -p /home/${user}/${repository} ; \ - chown -R ${user}:${user} /home/${user}/${repository} + chown -R ${user}:${user} /home/${user}/${repository} VOLUME ["/home/${user}/${repository}"] # Make sure we have the latest packages diff --git a/tests/fedora37/Dockerfile b/tests/fedora37/Dockerfile new file mode 100644 index 0000000..c1b2249 --- /dev/null +++ b/tests/fedora37/Dockerfile @@ -0,0 +1,33 @@ +FROM fedora:37 + +RUN dnf -y update && dnf clean all + +# Python 3.11 +RUN dnf -y install \ + zsh \ + sudo \ + python3 \ + python3-pip \ + && dnf clean all + +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="${ansible_version}" +RUN pip install ansible${ANSIBLE_VERSION} + +ARG user=test +ARG repository=ansible-linuxbrew + +# Create test user +RUN useradd -m -s /bin/bash ${user} \ + && echo "${user}:${user}" | chpasswd \ + && usermod -aG wheel ${user} \ + && echo '%wheel ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +RUN touch /home/${user}/.zshrc \ + && chown -R ${user}:${user} /home/${user} + +# Create directory for code +RUN mkdir -p /home/${user}/${repository} ; \ + chown -R ${user}:${user} /home/${user}/${repository} +VOLUME ["/home/${user}/${repository}"] + +CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/focal/Dockerfile b/tests/focal/Dockerfile new file mode 100644 index 0000000..1174cf5 --- /dev/null +++ b/tests/focal/Dockerfile @@ -0,0 +1,44 @@ +FROM ubuntu:focal + +RUN apt-get update && apt-get install -y \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +# Use a maintained UK-based mirror with HTTPS support +ARG ubuntu_archive=https://mirror.pulsant.com/sites/ubuntu-archive/ +RUN sed -i "s~http://archive.ubuntu.com/ubuntu/~${ubuntu_archive}~g" /etc/apt/sources.list + +RUN apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* + +RUN apt-get update && apt-get install -y \ + zsh \ + sudo \ + python3-minimal \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="${ansible_version}" +RUN pip install ansible${ANSIBLE_VERSION} + +ARG user=test +ARG repository=ansible-linuxbrew + +# Create test user +RUN useradd -m ${user} -s /bin/bash \ + && echo "${user}:${user}" | chpasswd \ + && adduser ${user} sudo \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +RUN touch /home/${user}/.zshrc \ + && chown -R ${user}:${user} /home/${user} + +# Create directory for code +RUN mkdir -p /home/${user}/${repository} ; \ + chown -R ${user}:${user} /home/${user}/${repository} +VOLUME ["/home/${user}/${repository}"] + +# Make sure we have the latest packages +RUN apt-get update + +CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/inventory b/tests/inventory index 2fbb50c..537f4b0 100644 --- a/tests/inventory +++ b/tests/inventory @@ -1 +1 @@ -localhost +localhost ansible_python_interpreter=auto diff --git a/tests/jammy/Dockerfile b/tests/jammy/Dockerfile new file mode 100644 index 0000000..1ca6b46 --- /dev/null +++ b/tests/jammy/Dockerfile @@ -0,0 +1,44 @@ +FROM ubuntu:jammy + +RUN apt-get update && apt-get install -y \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +# Use a maintained UK-based mirror with HTTPS support +ARG ubuntu_archive=https://mirror.pulsant.com/sites/ubuntu-archive/ +RUN sed -i "s~http://archive.ubuntu.com/ubuntu/~${ubuntu_archive}~g" /etc/apt/sources.list + +RUN apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* + +RUN apt-get update && apt-get install -y \ + zsh \ + sudo \ + python3-minimal \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="${ansible_version}" +RUN pip install ansible${ANSIBLE_VERSION} + +ARG user=test +ARG repository=ansible-linuxbrew + +# Create test user +RUN useradd -m ${user} -s /bin/bash \ + && echo "${user}:${user}" | chpasswd \ + && adduser ${user} sudo \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +RUN touch /home/${user}/.zshrc \ + && chown -R ${user}:${user} /home/${user} + +# Create directory for code +RUN mkdir -p /home/${user}/${repository} ; \ + chown -R ${user}:${user} /home/${user}/${repository} +VOLUME ["/home/${user}/${repository}"] + +# Make sure we have the latest packages +RUN apt-get update + +CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/run-tests b/tests/run-tests index 06c445b..09e69f8 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -1,15 +1,38 @@ #!/usr/bin/env bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_ROOT=$(dirname $DIR) +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT=$(dirname "${DIR}") -ROLE_NAME="$(basename $PROJECT_ROOT)" +REPO_NAME="$(basename "${PROJECT_ROOT}")" +ROLE_NAME="markosamuli.${REPO_NAME/ansible-/}" TEST_HOME=/home/test -### +# Ansible version to install on the Docker images +# Use PIP version specifiers: +# https://peps.python.org/pep-0440/#version-specifiers +ANSIBLE_VERSION=">=2.9.22" + +# Colour list copied from: +# https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux + +# Reset +Color_Off='\033[0m' # Text Reset + +# Bold +BPurple='\033[1;35m' # Purple + +image_msg() { + local image=$1 + shift + echo -e "${BPurple}[${image}] $*${Color_Off}" +} + # Detect Windows Subsystem for Linux -### -function detect_wsl { +detect_wsl() { + if [ ! -e /proc/version ]; then + is_wsl=0 + return + fi if grep -q Microsoft /proc/version; then echo "*** Windows Subsystem for Linux detected" is_wsl=1 @@ -18,91 +41,99 @@ function detect_wsl { fi } -### # Stop all containers -### -function finish { +finish() { local containers="" - containers=$(docker ps -q --filter=name=${ROLE_NAME}) - if [ ! -z "${containers}" ]; then - echo "*** Stop all test containers" + containers=$(docker ps -q --filter=name="${REPO_NAME}") + if [ -n "${containers}" ]; then + echo "*** Stop and remove all test containers" + # shellcheck disable=SC2086 docker stop ${containers} fi } -### # Stop container -### -function stop { +stop() { local image=$1 - local container_name=${ROLE_NAME}-${image}-tests - echo "*** Stop containers" - docker stop ${container_name} + local container_name=${REPO_NAME}-${image}-tests + echo "" + image_msg "${image}" "Stop and remove containers" + echo "" + docker stop "${container_name}" + sleep 1 } -### # Build image -### -function build { +build() { local image=$1 - local image_name=${ROLE_NAME}-${image} - echo "*** Build image" - docker build -t ${image_name} ./tests/${image} + local image_name=${REPO_NAME}-${image} + echo "" + image_msg "${image}" "Build image from tests/${image}/Dockerfile" + echo "" + docker build \ + --build-arg "ansible_version=${ANSIBLE_VERSION}" \ + -t "${image_name}" \ + "./tests/${image}" } -### # Start container in the background -### -function start { +start() { local image=$1 - local image_name=${ROLE_NAME}-${image} - local container_name=${ROLE_NAME}-${image}-tests - echo "*** Start container" + local image_name=${REPO_NAME}-${image} + local container_name=${REPO_NAME}-${image}-tests + echo "" + image_msg "${image}" "Start container ${container_name}" + echo "" docker run --rm -it -d \ - -v ${MOUNT_ROOT}:${TEST_HOME}/${ROLE_NAME} \ - --name ${container_name} \ - $image_name + -v "${MOUNT_ROOT}:${TEST_HOME}/${ROLE_NAME}" \ + -e "TEST_IMAGE=${image}" \ + --name "${container_name}" \ + "$image_name" } -### -# Run tests in the container -### -function run_tests_with_git { +run_tests_with_git() { local image=$1 - local container_name=${ROLE_NAME}-${image}-tests - echo "*** Run tests installing with Ansible from Git" + local container_name=${REPO_NAME}-${image}-tests + echo "" + image_msg "${image}" "Run tests installing with Ansible from Git" + echo "" docker exec -it \ --user test \ - ${container_name} \ - ${TEST_HOME}/${ROLE_NAME}/tests/run-tests-with-git + "${container_name}" \ + "${TEST_HOME}/${ROLE_NAME}/tests/run-tests-with-git" } -### -# Run tests in the container -### -function run_tests_with_installer { +run_tests_with_installer() { local image=$1 - local container_name=${ROLE_NAME}-${image}-tests - echo "*** Run tests installing with the Linuxbrew installer" + local container_name=${REPO_NAME}-${image}-tests + echo "" + image_msg "${image}" "Run tests installing with the Linuxbrew installer" + echo "" docker exec -it \ --user test \ - ${container_name} \ - ${TEST_HOME}/${ROLE_NAME}/tests/run-tests-with-installer + "${container_name}" \ + "${TEST_HOME}/${ROLE_NAME}/tests/run-tests-with-installer" } trap finish EXIT detect_wsl -cd $DIR +cd "${DIR}" || { + echo "${DIR} not found" + exit 1 +} -images=( "$@" ) +images=("$@") if [ ${#images[@]} -eq 0 ]; then - images=( */Dockerfile ) - images=( "${images[@]/\/Dockerfile/}" ) + images=(*/Dockerfile) + images=("${images[@]/\/Dockerfile/}") fi -cd $PROJECT_ROOT +cd "${PROJECT_ROOT}" || { + echo "${PROJECT_ROOT} not found" + exit 1 +} if [ "${is_wsl}" == "1" ]; then MOUNT_ROOT="$(pwd -P | sed 's~/mnt/c/~c:/~')" @@ -113,17 +144,17 @@ fi set -e for i in "${images[@]}"; do - build $i + build "$i" done for i in "${images[@]}"; do - start $i - run_tests_with_git $i - stop $i + start "$i" + run_tests_with_git "$i" + stop "$i" done for i in "${images[@]}"; do - start $i - run_tests_with_installer $i - stop $i + start "$i" + run_tests_with_installer "$i" + stop "$i" done diff --git a/tests/run-tests-with-git b/tests/run-tests-with-git index d1b9715..39bd6da 100755 --- a/tests/run-tests-with-git +++ b/tests/run-tests-with-git @@ -1,7 +1,7 @@ #!/usr/bin/env bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_ROOT=$(dirname $DIR) +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT=$(dirname "$DIR") set -e @@ -13,9 +13,10 @@ extra_vars=$(printf ",%s" "${ansible_vars[@]}") extra_vars="{${extra_vars:1}}" # Paths in which Ansible will search for Roles -export ANSIBLE_ROLES_PATH=$(dirname $PROJECT_ROOT) +ANSIBLE_ROLES_PATH=$(dirname "$PROJECT_ROOT") +export ANSIBLE_ROLES_PATH -cd $PROJECT_ROOT +cd "$PROJECT_ROOT" echo "*** Check syntax" @@ -24,16 +25,32 @@ ansible-playbook tests/test.yml -i tests/inventory --syntax-check echo "*** Run Ansible playbook" ansible-playbook tests/test.yml -i tests/inventory --connection=local \ + -v \ -e "${extra_vars}" +run_status=$? +if [[ ${run_status} -eq 0 ]]; then + echo 'Run: pass' +else + echo 'Run: fail' + exit 1 +fi echo "*** Idempotence test" ansible-playbook tests/test.yml -i tests/inventory --connection=local \ - -e "${extra_vars}" \ - | grep -q 'changed=0.*failed=0' \ - && (echo 'Idempotence test: pass' && exit 0) \ - || (echo 'Idempotence test: fail' && exit 1) - -echo "*** Verify installed Linuxbrew version" - -bash -c 'command -v brew && brew --version' + -e "${extra_vars}" | + grep -q 'changed=0.*failed=0' +idempotence_status=$? +if [[ $idempotence_status -eq 0 ]]; then + echo 'Idempotence test: pass' +else + echo 'Idempotence test: fail' + exit 1 +fi + +echo "*** Ansible playbooks completed on image ${TEST_IMAGE}" + +echo "*** Verify installed Linuxbrew version in bash" +bash -i -c 'command -v brew && brew --version' + +echo "*** Tests completed on image ${TEST_IMAGE}" diff --git a/tests/run-tests-with-installer b/tests/run-tests-with-installer index 24b0634..a050add 100755 --- a/tests/run-tests-with-installer +++ b/tests/run-tests-with-installer @@ -1,7 +1,7 @@ #!/usr/bin/env bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_ROOT=$(dirname $DIR) +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT=$(dirname "$DIR") set -e @@ -13,9 +13,10 @@ extra_vars=$(printf ",%s" "${ansible_vars[@]}") extra_vars="{${extra_vars:1}}" # Paths in which Ansible will search for Roles -export ANSIBLE_ROLES_PATH=$(dirname $PROJECT_ROOT) +ANSIBLE_ROLES_PATH=$(dirname "$PROJECT_ROOT") +export ANSIBLE_ROLES_PATH -cd $PROJECT_ROOT +cd "$PROJECT_ROOT" echo "*** Check syntax" @@ -24,16 +25,32 @@ ansible-playbook tests/test.yml -i tests/inventory --syntax-check echo "*** Run Ansible playbook" ansible-playbook tests/test.yml -i tests/inventory --connection=local \ + -v \ -e "${extra_vars}" +run_status=$? +if [[ ${run_status} -eq 0 ]]; then + echo 'Run: pass' +else + echo 'Run: fail' + exit 1 +fi echo "*** Idempotence test" ansible-playbook tests/test.yml -i tests/inventory --connection=local \ - -e "${extra_vars}" \ - | grep -q 'changed=0.*failed=0' \ - && (echo 'Idempotence test: pass' && exit 0) \ - || (echo 'Idempotence test: fail' && exit 1) - -echo "*** Verify installed Linuxbrew version" - -bash -c 'command -v brew && brew --version' + -e "${extra_vars}" | + grep -q 'changed=0.*failed=0' +idempotence_status=$? +if [[ $idempotence_status -eq 0 ]]; then + echo 'Idempotence test: pass' +else + echo 'Idempotence test: fail' + exit 1 +fi + +echo "*** Ansible playbooks completed on image ${TEST_IMAGE}" + +echo "*** Verify installed Linuxbrew version in bash" +bash -i -c 'command -v brew && brew --version' + +echo "*** Tests completed on image ${TEST_IMAGE}" diff --git a/tests/test.yml b/tests/test.yml index 1dc1842..37c8df6 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,6 +1,6 @@ --- - - hosts: localhost remote_user: root + name: Install Homebrew on Linux roles: - - ansible-linuxbrew + - markosamuli.linuxbrew diff --git a/tests/update b/tests/update deleted file mode 100755 index 6cb97b7..0000000 --- a/tests/update +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -user="test" -repository="$(basename $(dirname $(pwd)))" -ansible_version="<2.9.0" - -image="ubuntu" -ubuntu_releases=(xenial bionic) -for tag in "${ubuntu_releases[@]}"; do - dir="${tag}" - mkdir -p "${dir}" - echo "*** Updating $dir/Dockerfile" - sed -r \ - -e 's!%%FROM%%!'"$image:$tag"'!g' \ - -e 's!%%USER%%!'"$user"'!g' \ - -e 's!%%REPOSITORY%%!'"$repository"'!g' \ - -e 's!%%ANSIBLE_VERSION%%!'"$ansible_version"'!g' \ - "Dockerfile.template" > "$dir/Dockerfile" -done - -image="debian" -debian_releases=(stretch buster) -for tag in "${debian_releases[@]}"; do - dir="${tag}" - mkdir -p "${dir}" - echo "*** Updating $dir/Dockerfile" - sed -r \ - -e 's!%%FROM%%!'"$image:$tag"'!g' \ - -e 's!%%USER%%!'"$user"'!g' \ - -e 's!%%REPOSITORY%%!'"$repository"'!g' \ - -e 's!%%ANSIBLE_VERSION%%!'"$ansible_version"'!g' \ - "Dockerfile.template" > "$dir/Dockerfile" -done diff --git a/vars/main.yml b/vars/main.yml index ffa2ad6..30f8b7d 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -13,4 +13,3 @@ linuxbrew_core_tap_version: master # Linuxbrew installer script linuxbrew_install_tmp: "/tmp/linuxbrew" linuxbrew_install_url: "https://raw.githubusercontent.com/Homebrew/install/master/install.sh" -linuxbrew_install_checksum: "sha256:45c12bcd7765986674142230fc0860f5274903adbe37d582e5537771a1bae0b8" diff --git a/vars/os/Debian.yml b/vars/os/Debian.yml index 48b78dd..71240d4 100644 --- a/vars/os/Debian.yml +++ b/vars/os/Debian.yml @@ -1,7 +1,10 @@ --- - linuxbrew_install_dependencies: - git - curl - build-essential - locales + + # ps is not installed on the buster Docker image + # https://github.com/Homebrew/brew/blob/master/Library/Homebrew/cmd/shellenv.sh + - procps diff --git a/vars/os/RedHat.yml b/vars/os/RedHat.yml new file mode 100644 index 0000000..671f4bd --- /dev/null +++ b/vars/os/RedHat.yml @@ -0,0 +1,10 @@ +--- +# RedHat dependencies from: +# https://github.com/markosamuli/ansible-linuxbrew/pull/9 +linuxbrew_install_dependencies: + - "@Development Tools" + - git + - curl + - procps-ng + - file + - libxcrypt-compat From 5f90f1acdcffbea24aa9ca4a4a3f878c84329f4e Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 16:57:58 +0000 Subject: [PATCH 06/13] ci: run tests on GitHub Actions --- .ansible-lint | 1 + .github/workflows/pipeline.yml | 120 +++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 1 + CHANGELOG.md | 4 ++ 4 files changed, 126 insertions(+) create mode 100644 .github/workflows/pipeline.yml diff --git a/.ansible-lint b/.ansible-lint index a6d1e2d..74ffe84 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -2,3 +2,4 @@ exclude_paths: - .travis.yml - .ansible-lint + - .github/ diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000..4fb37ae --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,120 @@ +--- +name: Test and release + +# This workflow is triggered on pushes to the repository. +on: + pull_request: + branches: + - "**" + push: + branches: + - master + tags: + - v.* + +jobs: + lint: + name: Lint with pre-commit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: "18" + + - uses: actions/setup-python@v3 + with: + python-version: "3.11" + + - uses: actions/setup-go@v3 + with: + go-version: "1.19" + + - name: Install dependencies + run: | + pip3 install pre-commit + go install mvdan.cc/sh/v3/cmd/shfmt + sudo apt-get install -y shellcheck + python --version + shfmt -version + shellcheck --version + pre-commit --version + + - name: Cache pre-commit dependencies + uses: actions/cache@v3 + with: + path: ~/.cache/pre-commit/ + # yamllint disable-line rule:line-length + key: ${{ runner.os }}-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }} + restore-keys: | + ${{ runner.os }}-pre-commit- + + - name: Run pre-commit + run: pre-commit run -a + + ubuntu: + runs-on: ubuntu-latest + strategy: + matrix: + distrib: [ubuntu] + release: [focal, jammy, bionic] + + name: Test - ${{ matrix.distrib }} ${{ matrix.release }} + env: + DISTRIB: ${{ matrix.distrib }} + RELEASE: ${{ matrix.release }} + steps: + - uses: actions/checkout@v3 + + - name: Run tests + run: ./tests/run-tests ${RELEASE} + + debian: + runs-on: ubuntu-latest + strategy: + matrix: + distrib: [debian] + release: [bullseye, buster] + + name: Test - ${{ matrix.distrib }} ${{ matrix.release }} + env: + DISTRIB: ${{ matrix.distrib }} + RELEASE: ${{ matrix.release }} + steps: + - uses: actions/checkout@v3 + + - name: Run tests + run: ./tests/run-tests ${RELEASE} + + fedora: + runs-on: ubuntu-latest + strategy: + matrix: + distrib: [fedora] + release: [fedora37] + + name: Test - ${{ matrix.distrib }} ${{ matrix.release }} + env: + DISTRIB: ${{ matrix.distrib }} + RELEASE: ${{ matrix.release }} + steps: + - uses: actions/checkout@v3 + + - name: Run tests + run: ./tests/run-tests ${RELEASE} + + release: + name: Publish tagged releases to Ansible Galaxy + needs: + - lint + - ubuntu + - debian + - fedora + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: galaxy + uses: robertdebock/galaxy-action@1.2.0 + with: + galaxy_api_key: ${{ secrets.galaxy_api_key }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f7502d4..8953373 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,6 +26,7 @@ repos: hooks: - id: ansible-lint files: \.(yaml|yml)$ + exclude: .github/workflows/pipeline.yml - repo: https://github.com/syntaqx/git-hooks rev: v0.0.17 diff --git a/CHANGELOG.md b/CHANGELOG.md index 360137b..73c23be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,10 @@ [@aarey]: https://github.com/aairey [#9]: https://github.com/markosamuli/ansible-linuxbrew/pull/9 +### Testing + +- Run tests with supported Docker images on GitHub Actions + ## [1.2.2] - 2020-09-06 ### Fixed From 8cc5ee77e314ab74edf7086b3cfcd4971739d542 Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 17:08:55 +0000 Subject: [PATCH 07/13] docs: update README.md to mention the Docker test images --- README.md | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 836b6d9..b52f73a 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,6 @@ Ansible role to install [Linuxbrew](http://linuxbrew.sh/) on Ubuntu. -I'm not actively using or maintaining this role. The role used Travis CI for -testing and publishing the releases, but since June 15th, 2021, the building -on [travis-ci.org](https://www.travis-ci.org/) is ceased and I have stopped -using Travis CI on my OSS projects. - -I've tested the role up to Ansible 2.8 using local installation. - ## Compatibility Run tests with a supported Docker image, for example with `bionic`: @@ -31,6 +24,13 @@ make bionic | Debian 11 | [`bullseye`][bullseye] | `>=2.9.22` | | Fedora 37 | [`fedora37`][fedora37] | `>=2.9.22` | +If you want to add a new distribution or release version, please create a +Docker image for it under the `tests/` directory and make sure the existing +tests work. + +I'm developing this role currently in a black box using the Docker images +included in the repository and not running it on live environments. + [bionic]: tests/bionic/Dockerfile [focal]: tests/focal/Dockerfile [jammy]: tests/jammy/Dockerfile @@ -82,6 +82,11 @@ make test - [BSD License](LICENSE) +## Contributing + +I'm not actively using or maintaining this role, but welcome bug fixes and +support for missing operating systems. + ## Contributions The installation is based on the official [Homebrew installer][homebrew-installer] @@ -89,6 +94,6 @@ script. [homebrew-installer]: https://github.com/Linuxbrew/install -## Author Information +## Author information - [@markosamuli](https://github.com/markosamuli) From 0f1b0c46c09f3c3acfe9183384bea9e5c406a6ee Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 17:10:10 +0000 Subject: [PATCH 08/13] fix: go install mvdan.cc/sh/v3/cmd/shfmt@latest --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 4fb37ae..8cf66c5 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -34,7 +34,7 @@ jobs: - name: Install dependencies run: | pip3 install pre-commit - go install mvdan.cc/sh/v3/cmd/shfmt + go install mvdan.cc/sh/v3/cmd/shfmt@latest sudo apt-get install -y shellcheck python --version shfmt -version From fbd8b5c8b6f288de04ed12c3c9cf3fee86ffbb7b Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 17:19:57 +0000 Subject: [PATCH 09/13] fix: running Docker images on CI --- tests/run-tests | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/run-tests b/tests/run-tests index 09e69f8..a5604e4 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -7,6 +7,8 @@ REPO_NAME="$(basename "${PROJECT_ROOT}")" ROLE_NAME="markosamuli.${REPO_NAME/ansible-/}" TEST_HOME=/home/test +docker_run_opts=() + # Ansible version to install on the Docker images # Use PIP version specifiers: # https://peps.python.org/pep-0440/#version-specifiers @@ -72,6 +74,7 @@ build() { echo "" docker build \ --build-arg "ansible_version=${ANSIBLE_VERSION}" \ + --build-arg "repository=${ROLE_NAME}" \ -t "${image_name}" \ "./tests/${image}" } @@ -84,7 +87,8 @@ start() { echo "" image_msg "${image}" "Start container ${container_name}" echo "" - docker run --rm -it -d \ + docker run --rm -d \ + "${docker_run_opts[@]}" \ -v "${MOUNT_ROOT}:${TEST_HOME}/${ROLE_NAME}" \ -e "TEST_IMAGE=${image}" \ --name "${container_name}" \ @@ -97,7 +101,8 @@ run_tests_with_git() { echo "" image_msg "${image}" "Run tests installing with Ansible from Git" echo "" - docker exec -it \ + docker exec \ + "${docker_run_opts[@]}" \ --user test \ "${container_name}" \ "${TEST_HOME}/${ROLE_NAME}/tests/run-tests-with-git" @@ -109,7 +114,8 @@ run_tests_with_installer() { echo "" image_msg "${image}" "Run tests installing with the Linuxbrew installer" echo "" - docker exec -it \ + docker exec \ + "${docker_run_opts[@]}" \ --user test \ "${container_name}" \ "${TEST_HOME}/${ROLE_NAME}/tests/run-tests-with-installer" @@ -117,6 +123,10 @@ run_tests_with_installer() { trap finish EXIT +if [ -z "$CI" ]; then + docker_run_opts+=("-it") +fi + detect_wsl cd "${DIR}" || { From c5674826b789438ce298db8ce2a1d00ebdaf23d1 Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 17:27:40 +0000 Subject: [PATCH 10/13] fix: install Ansible in user home on test images --- tests/bionic/Dockerfile | 19 ++++++++++++------- tests/bullseye/Dockerfile | 12 +++++++----- tests/buster/Dockerfile | 16 +++++++++------- tests/fedora37/Dockerfile | 12 +++++++----- tests/focal/Dockerfile | 12 +++++++----- tests/jammy/Dockerfile | 12 +++++++----- tests/run-tests-with-git | 9 +++++++++ tests/run-tests-with-installer | 9 +++++++++ 8 files changed, 67 insertions(+), 34 deletions(-) diff --git a/tests/bionic/Dockerfile b/tests/bionic/Dockerfile index 18ed548..b469aba 100644 --- a/tests/bionic/Dockerfile +++ b/tests/bionic/Dockerfile @@ -24,14 +24,8 @@ RUN apt-get update && apt-get install -y \ ENV LANG C.UTF-8 ENV LC_ALL C.UTF-8 -# Ansible will require Python 3.8 or newer on the controller starting -# with Ansible 2.12. -ARG ansible_version=">=2.9.22" -ENV ANSIBLE_VERSION="<2.12,${ansible_version}" -RUN pip3 install ansible${ANSIBLE_VERSION} - ARG user=test -ARG repository=ansible-linuxbrew +ARG repository=markosamuli.linuxbrew # Create test user RUN useradd -m ${user} -s /bin/bash \ @@ -49,4 +43,15 @@ VOLUME ["/home/${user}/${repository}"] # Make sure we have the latest packages RUN apt-get update +USER ${user} + +# Upgrade pip to fix installation issues +RUN python3 -m pip install --upgrade pip + +# Ansible will require Python 3.8 or newer on the controller starting +# with Ansible 2.12. +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="<2.12,${ansible_version}" +RUN python3 -m pip install ansible${ANSIBLE_VERSION} + CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/bullseye/Dockerfile b/tests/bullseye/Dockerfile index b5ac400..20308a8 100644 --- a/tests/bullseye/Dockerfile +++ b/tests/bullseye/Dockerfile @@ -17,12 +17,8 @@ RUN apt-get update && apt-get install -y \ python3-pip \ && rm -rf /var/lib/apt/lists/* -ARG ansible_version=">=2.9.22" -ENV ANSIBLE_VERSION="${ansible_version}" -RUN pip3 install ansible${ANSIBLE_VERSION} - ARG user=test -ARG repository=ansible-linuxbrew +ARG repository=markosamuli.linuxbrew # Create test user RUN useradd -m ${user} -s /bin/bash \ @@ -40,4 +36,10 @@ VOLUME ["/home/${user}/${repository}"] # Make sure we have the latest packages RUN apt-get update +USER ${user} + +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="${ansible_version}" +RUN python3 -m pip install ansible${ANSIBLE_VERSION} + CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/buster/Dockerfile b/tests/buster/Dockerfile index 00ad2bb..0d50cc0 100644 --- a/tests/buster/Dockerfile +++ b/tests/buster/Dockerfile @@ -18,14 +18,8 @@ RUN apt-get update && apt-get install -y \ python3-pip \ && rm -rf /var/lib/apt/lists/* -# Ansible will require Python 3.8 or newer on the controller starting with -# Ansible 2.12 -ARG ansible_version=">=2.9.22" -ENV ANSIBLE_VERSION="<2.12,${ansible_version}" -RUN pip3 install ansible${ANSIBLE_VERSION} - ARG user=test -ARG repository=ansible-linuxbrew +ARG repository=markosamuli.linuxbrew # Create test user RUN useradd -m ${user} -s /bin/bash \ @@ -43,4 +37,12 @@ VOLUME ["/home/${user}/${repository}"] # Make sure we have the latest packages RUN apt-get update +USER ${user} + +# Ansible will require Python 3.8 or newer on the controller starting with +# Ansible 2.12 +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="<2.12,${ansible_version}" +RUN python3 -m pip install ansible${ANSIBLE_VERSION} + CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/fedora37/Dockerfile b/tests/fedora37/Dockerfile index c1b2249..665979a 100644 --- a/tests/fedora37/Dockerfile +++ b/tests/fedora37/Dockerfile @@ -10,12 +10,8 @@ RUN dnf -y install \ python3-pip \ && dnf clean all -ARG ansible_version=">=2.9.22" -ENV ANSIBLE_VERSION="${ansible_version}" -RUN pip install ansible${ANSIBLE_VERSION} - ARG user=test -ARG repository=ansible-linuxbrew +ARG repository=markosamuli.linuxbrew # Create test user RUN useradd -m -s /bin/bash ${user} \ @@ -30,4 +26,10 @@ RUN mkdir -p /home/${user}/${repository} ; \ chown -R ${user}:${user} /home/${user}/${repository} VOLUME ["/home/${user}/${repository}"] +USER ${user} + +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="${ansible_version}" +RUN python3 -m pip install ansible${ANSIBLE_VERSION} + CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/focal/Dockerfile b/tests/focal/Dockerfile index 1174cf5..63f4957 100644 --- a/tests/focal/Dockerfile +++ b/tests/focal/Dockerfile @@ -18,12 +18,8 @@ RUN apt-get update && apt-get install -y \ python3-pip \ && rm -rf /var/lib/apt/lists/* -ARG ansible_version=">=2.9.22" -ENV ANSIBLE_VERSION="${ansible_version}" -RUN pip install ansible${ANSIBLE_VERSION} - ARG user=test -ARG repository=ansible-linuxbrew +ARG repository=markosamuli.linuxbrew # Create test user RUN useradd -m ${user} -s /bin/bash \ @@ -41,4 +37,10 @@ VOLUME ["/home/${user}/${repository}"] # Make sure we have the latest packages RUN apt-get update +USER test + +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="${ansible_version}" +RUN python3 -m pip install ansible${ANSIBLE_VERSION} + CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/jammy/Dockerfile b/tests/jammy/Dockerfile index 1ca6b46..39d68e3 100644 --- a/tests/jammy/Dockerfile +++ b/tests/jammy/Dockerfile @@ -18,12 +18,8 @@ RUN apt-get update && apt-get install -y \ python3-pip \ && rm -rf /var/lib/apt/lists/* -ARG ansible_version=">=2.9.22" -ENV ANSIBLE_VERSION="${ansible_version}" -RUN pip install ansible${ANSIBLE_VERSION} - ARG user=test -ARG repository=ansible-linuxbrew +ARG repository=markosamuli.linuxbrew # Create test user RUN useradd -m ${user} -s /bin/bash \ @@ -41,4 +37,10 @@ VOLUME ["/home/${user}/${repository}"] # Make sure we have the latest packages RUN apt-get update +USER ${user} + +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="${ansible_version}" +RUN python3 -m pip install ansible${ANSIBLE_VERSION} + CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/run-tests-with-git b/tests/run-tests-with-git index 39bd6da..ea0372d 100755 --- a/tests/run-tests-with-git +++ b/tests/run-tests-with-git @@ -3,6 +3,15 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT=$(dirname "$DIR") +if [ -d "${HOME}/.local/bin" ]; then + export PATH="${HOME}/.local/bin:${PATH}" +fi + +command -v ansible-playbook >/dev/null || { + echo "ansible-playbook: command not found" + exit 127 +} + set -e # Variables to pass to ansible-playbook diff --git a/tests/run-tests-with-installer b/tests/run-tests-with-installer index a050add..0bd09b0 100755 --- a/tests/run-tests-with-installer +++ b/tests/run-tests-with-installer @@ -3,6 +3,15 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT=$(dirname "$DIR") +if [ -d "${HOME}/.local/bin" ]; then + export PATH="${HOME}/.local/bin:${PATH}" +fi + +command -v ansible-playbook >/dev/null || { + echo "ansible-playbook: command not found" + exit 127 +} + set -e # Variables to pass to ansible-playbook From b1df987f979636b2aadba68c6266e10e05f324f3 Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 17:39:43 +0000 Subject: [PATCH 11/13] ci: display release name on test step --- .github/workflows/pipeline.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 8cf66c5..ed913e0 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -67,7 +67,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Run tests + - name: Run tests on ${{ matrix.release }} run: ./tests/run-tests ${RELEASE} debian: @@ -84,7 +84,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Run tests + - name: Run tests on ${{ matrix.release }} run: ./tests/run-tests ${RELEASE} fedora: @@ -101,7 +101,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Run tests + - name: Run tests on ${{ matrix.release }} run: ./tests/run-tests ${RELEASE} release: From 004983f8c911587ed53a8932aece3396504bcde4 Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 18:12:51 +0000 Subject: [PATCH 12/13] feat: add distribution to test image name --- .github/workflows/pipeline.yml | 14 +++++----- Makefile | 7 +++++ README.md | 28 +++++++++---------- .../{bullseye => debian-bullseye}/Dockerfile | 0 tests/{buster => debian-buster}/Dockerfile | 0 tests/{fedora37 => fedora-37}/Dockerfile | 0 tests/{bionic => ubuntu-bionic}/Dockerfile | 0 tests/{focal => ubuntu-focal}/Dockerfile | 0 tests/{jammy => ubuntu-jammy}/Dockerfile | 0 9 files changed, 28 insertions(+), 21 deletions(-) rename tests/{bullseye => debian-bullseye}/Dockerfile (100%) rename tests/{buster => debian-buster}/Dockerfile (100%) rename tests/{fedora37 => fedora-37}/Dockerfile (100%) rename tests/{bionic => ubuntu-bionic}/Dockerfile (100%) rename tests/{focal => ubuntu-focal}/Dockerfile (100%) rename tests/{jammy => ubuntu-jammy}/Dockerfile (100%) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index ed913e0..f45e02a 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -67,8 +67,8 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Run tests on ${{ matrix.release }} - run: ./tests/run-tests ${RELEASE} + - name: Run tests on ${{ matrix.distrib }}:${{ matrix.release }} + run: ./tests/run-tests ${DISTRIB}-${RELEASE} debian: runs-on: ubuntu-latest @@ -84,15 +84,15 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Run tests on ${{ matrix.release }} - run: ./tests/run-tests ${RELEASE} + - name: Run tests on ${{ matrix.distrib }}:${{ matrix.release }} + run: ./tests/run-tests ${DISTRIB}-${RELEASE} fedora: runs-on: ubuntu-latest strategy: matrix: distrib: [fedora] - release: [fedora37] + release: [37] name: Test - ${{ matrix.distrib }} ${{ matrix.release }} env: @@ -101,8 +101,8 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Run tests on ${{ matrix.release }} - run: ./tests/run-tests ${RELEASE} + - name: Run tests on ${{ matrix.distrib }}:${{ matrix.release }} + run: ./tests/run-tests ${DISTRIB}-${RELEASE} release: name: Publish tagged releases to Ansible Galaxy diff --git a/Makefile b/Makefile index 65fbe03..47fe2b6 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,8 @@ endif .PHONY: help help: ## print this help @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort -d | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + @echo "" + $(MAKE) list-images PRE_COMMIT_HOOKS = .git/hooks/pre-commit @@ -21,6 +23,11 @@ setup: $(PRE_COMMIT_HOOKS) test: ## run tests with all available Docker images ./tests/run-tests +.PHONY: list-images +list-images: ## list available test images + @echo "Available test images:" + @for i in $(TEST_IMAGES); do echo "$$i" | awk '{printf "\033[36m%-30s\033[0m run tests with %s\n", $$1, $$1}'; done + .PHONY: $(TEST_IMAGES) $(TEST_IMAGES): ./tests/run-tests $@ diff --git a/README.md b/README.md index b52f73a..f268c92 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,14 @@ Run tests with a supported Docker image, for example with `bionic`: make bionic ``` -| Release | Docker image | Ansible | -| ---------------- | ---------------------- | ---------------- | -| Ubuntu 18.04 LTS | [`bionic`][bionic] | `<2.12,>=2.9.22` | -| Ubuntu 20.04 LTS | [`focal`][focal] | `>=2.9.22` | -| Ubuntu 22.04 LTS | [`jammy`][jammy] | `>=2.9.22` | -| Debian 10 | [`buster`][buster] | `<2.12,>=2.9.22` | -| Debian 11 | [`bullseye`][bullseye] | `>=2.9.22` | -| Fedora 37 | [`fedora37`][fedora37] | `>=2.9.22` | +| Release | Docker image | Ansible | +| ---------------- | ------------------------------------ | ---------------- | +| Debian 10 | [`debian-buster`][debian-buster] | `<2.12,>=2.9.22` | +| Debian 11 | [`debian-bullseye`][debian-bullseye] | `>=2.9.22` | +| Fedora 37 | [`fedora-37`][fedora-37] | `>=2.9.22` | +| Ubuntu 18.04 LTS | [`ubuntu-bionic`][ubuntu-bionic] | `<2.12,>=2.9.22` | +| Ubuntu 20.04 LTS | [`ubuntu-focal`][ubuntu-focal] | `>=2.9.22` | +| Ubuntu 22.04 LTS | [`ubuntu-jammy`][ubuntu-jammy] | `>=2.9.22` | If you want to add a new distribution or release version, please create a Docker image for it under the `tests/` directory and make sure the existing @@ -31,12 +31,12 @@ tests work. I'm developing this role currently in a black box using the Docker images included in the repository and not running it on live environments. -[bionic]: tests/bionic/Dockerfile -[focal]: tests/focal/Dockerfile -[jammy]: tests/jammy/Dockerfile -[buster]: tests/buster/Dockerfile -[bullseye]: tests/buster/Dockerfile -[fedora37]: tests/fedora37/Dockerfile +[ubuntu-bionic]: tests/ubuntu-bionic/Dockerfile +[ubuntu-focal]: tests/ubuntu-focal/Dockerfile +[ubuntu-jammy]: tests/ubuntu-jammy/Dockerfile +[debian-buster]: tests/debian-buster/Dockerfile +[debian-bullseye]: tests/debian-bullseye/Dockerfile +[fedora-37]: tests/fedora-37/Dockerfile ## Configuration diff --git a/tests/bullseye/Dockerfile b/tests/debian-bullseye/Dockerfile similarity index 100% rename from tests/bullseye/Dockerfile rename to tests/debian-bullseye/Dockerfile diff --git a/tests/buster/Dockerfile b/tests/debian-buster/Dockerfile similarity index 100% rename from tests/buster/Dockerfile rename to tests/debian-buster/Dockerfile diff --git a/tests/fedora37/Dockerfile b/tests/fedora-37/Dockerfile similarity index 100% rename from tests/fedora37/Dockerfile rename to tests/fedora-37/Dockerfile diff --git a/tests/bionic/Dockerfile b/tests/ubuntu-bionic/Dockerfile similarity index 100% rename from tests/bionic/Dockerfile rename to tests/ubuntu-bionic/Dockerfile diff --git a/tests/focal/Dockerfile b/tests/ubuntu-focal/Dockerfile similarity index 100% rename from tests/focal/Dockerfile rename to tests/ubuntu-focal/Dockerfile diff --git a/tests/jammy/Dockerfile b/tests/ubuntu-jammy/Dockerfile similarity index 100% rename from tests/jammy/Dockerfile rename to tests/ubuntu-jammy/Dockerfile From 7aaa59f36e6275b7facf9bb97f088f988a681f7c Mon Sep 17 00:00:00 2001 From: MSK Date: Fri, 17 Feb 2023 18:14:00 +0000 Subject: [PATCH 13/13] ci: display Docker base image on test name --- .github/workflows/pipeline.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index f45e02a..6a6f49c 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -60,7 +60,7 @@ jobs: distrib: [ubuntu] release: [focal, jammy, bionic] - name: Test - ${{ matrix.distrib }} ${{ matrix.release }} + name: Test on ${{ matrix.distrib }}:${{ matrix.release }} env: DISTRIB: ${{ matrix.distrib }} RELEASE: ${{ matrix.release }} @@ -77,7 +77,7 @@ jobs: distrib: [debian] release: [bullseye, buster] - name: Test - ${{ matrix.distrib }} ${{ matrix.release }} + name: Test on ${{ matrix.distrib }}:${{ matrix.release }} env: DISTRIB: ${{ matrix.distrib }} RELEASE: ${{ matrix.release }} @@ -94,7 +94,7 @@ jobs: distrib: [fedora] release: [37] - name: Test - ${{ matrix.distrib }} ${{ matrix.release }} + name: Test on ${{ matrix.distrib }}:${{ matrix.release }} env: DISTRIB: ${{ matrix.distrib }} RELEASE: ${{ matrix.release }}