Merge pull request #160 from rvm/test_with_docker

Test rvm1-ansible using docker-compose
This commit is contained in:
Paul Montero
2017-09-21 01:02:01 +02:00
committed by GitHub
19 changed files with 443 additions and 59 deletions

3
.gitignore vendored
View File

@@ -3,4 +3,5 @@
._* ._*
.*.sw* .*.sw*
*~ *~
.idea/ .idea/
*.retry

View File

@@ -1,55 +1,40 @@
--- ---
language: 'python' language: generic
python: '2.7'
sudo: required
env: env:
- SITE_AND_INVENTORY='tests/test.yml -i tests/inventory' DOCKER_COMPOSE_VERSION: 1.16.1
services:
- docker
cache:
pip: true
directories:
- $HOME/docker
before_install: before_install:
- '__rvm_unload ; rm -rf ~/.rvm' - if [[ -d $HOME/docker ]]; then ls $HOME/docker/*.tar.gz | xargs -I {file} sh -c "zcat {file} | docker load"; fi
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
install: install:
- 'pip install ansible==2.2.0' - sudo pip install ansible==2.2.2 > /dev/null 2>&1
- 'printf "[defaults]\nroles_path = ../" > ansible.cfg'
script: script:
- cd tests
- docker-compose up -d > /dev/null 2>&1
- ansible-playbook user.yml -l centos
- ansible-playbook user.yml -l debian
- ansible-playbook user.yml -l ubuntu
before_cache:
- > - >
ruby -v mkdir -p $HOME/docker && docker images -a --filter='dangling=false' --format '{{.Repository}}:{{.Tag}} {{.ID}}'
| grep -q 'ruby' | xargs -n 2 -t sh -c 'test -e $HOME/docker/$1.tar.gz || docker save $0 | gzip -2 > $HOME/docker/$1.tar.gz'
&& (echo 'No ruby test: pass' && exit 1)
|| (echo 'No ruby test: fail' && exit 0)
- 'ansible-playbook $SITE_AND_INVENTORY --syntax-check'
- 'ansible-playbook $SITE_AND_INVENTORY --connection=local -vvvv'
- >
ansible-playbook $SITE_AND_INVENTORY --connection=local
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
- >
~/.rvm/wrappers/default/ruby -v
| grep -q '2.3.1'
&& (echo 'Default ruby test: pass' && exit 0)
|| (echo 'Default ruby test: fail' && exit 1)
- >
ls ~/.rvm/rubies
| grep -q 'ruby-2.2.5'
&& (echo 'Multiple rubies test: pass' && exit 0)
|| (echo 'Multiple rubies test: fail' && exit 1)
- >
ansible-playbook $SITE_AND_INVENTORY --connection=local --extra-vars='rvm1_delete_ruby=ruby-2.2.5'
| grep -q 'ok=1.*failed=0'
&& (echo 'Delete ruby test: pass' && exit 0)
|| (echo 'Delete ruby test: fail' && exit 1)
- >
ls ~/.rvm/rubies/ | wc -l
| grep -q '2'
&& (echo 'Really deleted ruby test: pass' && exit 0)
|| (echo 'Really deleted ruby test: fail' && exit 1)
- >
ls ~/.rvm/wrappers/default/
| grep -q 'bundler'
&& (echo 'Bundler symlinked on system path test: pass' && exit 0)
|| (echo 'Bundler symlinked on system path test: fail' && exit 1)
notifications: notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/ webhooks: https://galaxy.ansible.com/api/v1/notifications/

113
CHANGELOG.md Normal file
View File

@@ -0,0 +1,113 @@
# CHANGELOG
## MASTER
### v2.0.1
* Fix issue `src file does not exist` cause by testrb
### v2.0.0
* Bump ansible version to 2.2
* Update readme
### v1.3.9
* Fix bugs
* Use a non-root user by default for the installation.
### v1.3.8
* Bump ruby version to 2.2.2
* Fix Bundler symlinking on system path
* This fixes the location of the bundler pointing to the global ruby version
* Ensure a default value is supplied when detecting ruby, fixes #78
* Update rvm installer path
* Update become method
* Ensure installed rubies and gems are owned correctly by rvm1_user
### v1.3.7
* Fix #40 by using a proper gem path
### v1.3.6
* Recent changes to rvm made bundler not get installed by default
* This patch installs bundler by default
### v1.3.5
* Ensure rvm1_user owns all rvm related files
* Allow passing in custom configuration options when installing ruby
### v1.3.4
* Change the default system wide install dir back to /usr/local/rvm
* Add the rvm1_user: 'root' default variable to let you set the rvm directory owner
* Update the README on why setting sudo: True is necessary
### v1.3.3
* Fix an incorrect condition which caused Ansible to error out
### v1.3.2
* Import the GPG signature every time rvm runs get [version].
### v1.3.1
* Add gpg signature verification
### v1.3.0
* Remove the python-httplib2 dependency so it should work on CentOS 7
* Change how versions are set, check the readme
* Always run rvm update unless you disable it by overwriting rvm1_rvm_check_for_updates
### v1.2.0
* Add CentOS/RHEL support
### v1.1.1
* Fix #7 and #8 by no longer chowning the user:group
* Symlink the ruby related bins to /usr/local/bin when doing a system wide install
* Remove the temp install dir, always use /tmp
* Expose the rvm install flags in a new default variable rvm1_install_flags
* Change the default system wide install dir to /usr/local/lib/rvm
* Update the readme to be much more clear and provide 3 examples of how to install rvm
* Update the travis test to test against ansible 1.7.1 instead of 1.6.2
* Reformat all of the tasks to make them more readable and maintainable
### v1.0.2
* Force sudo as root when having to apt install python-httplib2, fixes #5.
### v1.0.1
* Install httplib2 if necessary (the ansible uri module depends on this)
### v1.0.0
* Add ability to define 1 or more ruby versions
* Add ability to delete ruby versions
* Expose a few useful variables and paths
* Switch over from nickjj.ruby to rvm1-ansible
### v0.1.9
* Really fix the detect tasks so they are idempotent
### v0.1.8
* Fix the detect tasks so they are idempotent
### v0.1.7
* Simplify the default ruby selection tasks into a single task
### v0.1.6
* Fix the default ruby selection task so it works for both local and system installs
### v0.1.5
* Fix a bug where /etc/profile.d/rvm.sh would be sourced even if it did not exist
* Add the --default flag to the rvm use command
### v0.1.4
* Bump the default version of ruby to 2.1.2
### v0.1.3
* Fix a bug with how the upgrade task was checking for rvm's existence
* Change how the role checks to determine if rvm is installed
### v0.1.2
* Allow you to specify a local path or url for the rvm installer script
* Allow you to specify a url or variable value for the latest rvm stable version number
### v0.1.1
* Auto upgrade rvm in an idempotent way but also allow you to turn this off
* Keep the rvm installer file on the server instead of deleting it in case http://get.rvm.io is down
* Toggle a variable to force update the installer
### v0.1.0
* View the readme to get a better understanding of what ansible-ruby does.

View File

@@ -1,4 +1,4 @@
## What is rvm1-ansible? [![Build Status](https://travis-ci.org/rvm/rvm1-ansible.svg?branch=master)](https://travis-ci.org/rvm/rvm1-ansible) ## What is rvm1-ansible? [![Build Status](https://travis-ci.org/rvm/rvm1-ansible.svg?branch=master)](https://travis-ci.org/rvm/rvm1-ansible) [![Ansible Role](https://img.shields.io/badge/role-rvm_io-red.svg)](https://galaxy.ansible.com/rvm_io/ruby/)
It is an [Ansible](http://www.ansible.com/home) role to install and manage ruby versions using rvm. It is an [Ansible](http://www.ansible.com/home) role to install and manage ruby versions using rvm.

3
tests/ansible.cfg Normal file
View File

@@ -0,0 +1,3 @@
[defaults]
inventory = inventory
roles_path = ../../

40
tests/assertions.yml Normal file
View File

@@ -0,0 +1,40 @@
---
- name: Check that ruby exists
shell: . $HOME/.bash_profile && ruby -v | cut -c1-4
args:
executable: /bin/bash
register: check_ruby
changed_when: false
- assert:
that:
- check_ruby.stdout == 'ruby'
- check_ruby.rc == 0
msg: No ruby installed
- name: Check default ruby
shell: ~/.rvm/wrappers/default/ruby -v | cut -c1-10
register: check_ruby_default
changed_when: false
- assert:
that:
- check_ruby_default.stdout == 'ruby 2.3.1'
msg: No default ruby installed
- name: Check multiple rubies
command: ls ~/.rvm/rubies
register: check_ruby_multiple
changed_when: false
- assert:
that:
- "'ruby-2.2.5' in check_ruby_multiple.stdout"
- "'ruby-2.3.1' in check_ruby_multiple.stdout"
msg: No multiple rubies installed
- name: Check bundler symlinked on system path
shell: ls ~/.rvm/wrappers/default/ |grep 'bundler'
register: check_ruby_bundler
changed_when: false
- assert:
that:
- check_ruby_bundler.stdout == 'bundler'
msg: No bundler symlinked on system path

26
tests/docker-compose.yml Normal file
View File

@@ -0,0 +1,26 @@
version: "3"
services:
centos6:
build: ./dockerfiles/centos6
cap_add:
- ALL
centos7:
build: ./dockerfiles/centos7
cap_add:
- ALL
debian8:
build: ./dockerfiles/debian8
cap_add:
- ALL
debian9:
build: ./dockerfiles/debian9
cap_add:
- ALL
ubuntu14:
build: ./dockerfiles/ubuntu14
cap_add:
- ALL
ubuntu16:
build: ./dockerfiles/ubuntu16
cap_add:
- ALL

View File

@@ -0,0 +1,12 @@
FROM centos:6
RUN yum update -y && \
yum install -y \
initscripts \
sudo \
&& yum clean all
RUN useradd -ms /bin/bash user \
&& echo 'user ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
CMD ["/sbin/init"]

View File

@@ -0,0 +1,12 @@
FROM centos:7
RUN yum update -y && \
yum install -y \
sudo \
which \
&& yum clean all
RUN useradd -ms /bin/bash user \
&& echo 'user ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
CMD ["/usr/sbin/init"]

View File

@@ -0,0 +1,23 @@
FROM debian:8
RUN apt-get update \
&& apt-get install -y \
curl \
build-essential \
libbz2-dev \
libffi-dev \
libncurses5-dev \
libreadline-dev \
libssl-dev \
sudo \
wget \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /opt/
COPY build /opt/build
RUN bash build
RUN useradd -ms /bin/bash user \
&& echo 'user ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
CMD ["/sbin/init"]

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
PI=/opt
EXPECTED_VERSION="2.7.10"
get_source(){
wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz
tar xvf Python-2.7.10.tar.xz
cd Python-2.7.10
}
install_configure(){
./configure
make
make install
}
remove(){
rm $PI/Python-2.7.10.tar.xz
rm -rf $PI/Python-2.7.10
}
update_alternatives(){
update-alternatives --install /usr/bin/python python /usr/local/bin/python 10
}
version(){
VERSION=$(python -c "print __import__('sys').version[0:6]")
if [ "$VERSION" == "$EXPECTED_VERSION" ];
then echo "Python $VERSION installed OK";
else echo "FAIL";
fi
}
cd $PI
get_source
install_configure
update_alternatives
remove
version

View File

@@ -0,0 +1,15 @@
FROM debian:9
RUN apt-get update && \
apt-get install -y \
curl \
gpg \
python \
sudo \
systemd \
&& rm -rf /var/lib/apt/lists/*
RUN useradd -ms /bin/bash user \
&& echo 'user ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
CMD ["/bin/systemd"]

View File

@@ -0,0 +1,23 @@
FROM ubuntu:14.04
RUN apt-get update && \
apt-get install -y \
curl \
build-essential \
libbz2-dev \
libffi-dev \
libncurses5-dev \
libreadline-dev \
libssl-dev \
sudo \
wget \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /opt/
COPY build /opt/build
RUN bash build
RUN useradd -ms /bin/bash user \
&& echo 'user ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
CMD ["/sbin/init"]

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
PI=/opt
EXPECTED_VERSION="2.7.10"
get_source(){
wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz
tar xvf Python-2.7.10.tar.xz
cd Python-2.7.10
}
install_configure(){
./configure
make
make install
}
remove(){
rm $PI/Python-2.7.10.tar.xz
rm -rf $PI/Python-2.7.10
}
update_alternatives(){
update-alternatives --install /usr/bin/python python /usr/local/bin/python 10
}
version(){
VERSION=$(python -c "print __import__('sys').version[0:6]")
if [ "$VERSION" == "$EXPECTED_VERSION" ];
then echo "Python $VERSION installed OK";
else echo "FAIL";
fi
}
cd $PI
get_source
install_configure
update_alternatives
remove
version

View File

@@ -0,0 +1,13 @@
FROM ubuntu:16.04
RUN apt-get update && \
apt-get install -y \
curl \
python \
sudo \
&& rm -rf /var/lib/apt/lists/*
RUN useradd -ms /bin/bash user \
&& echo 'user ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
CMD ["/sbin/init"]

View File

@@ -1 +1,9 @@
localhost [centos]
tests_centos6_1 ansible_connection=docker
tests_centos7_1 ansible_connection=docker
[debian]
tests_debian8_1 ansible_connection=docker
tests_debian9_1 ansible_connection=docker
[ubuntu]
tests_ubuntu14_1 ansible_connection=docker
tests_ubuntu16_1 ansible_connection=docker

19
tests/root.yml Normal file
View File

@@ -0,0 +1,19 @@
---
- hosts: all
gather_facts: false
vars:
rvm1_user: root
rvm1_install_flags: '--auto-dotfiles'
rvm1_install_path: '/home/{{ rvm1_user }}/.rvm'
rvm1_rubies:
- 'ruby-2.2.5'
- 'ruby-2.3.1'
roles:
- role: rvm1-ansible
# Asserts tasks
- hosts: all
gather_facts: false
tasks:
- name: Assert tasks
include: assertions.yml

View File

@@ -1,14 +0,0 @@
---
- hosts: localhost
remote_user: travis
vars:
rvm1_rubies:
- 'ruby-2.2.5'
- 'ruby-2.3.1'
rvm1_install_path: '/home/travis/.rvm'
rvm1_user: travis
roles:
- rvm1-ansible

21
tests/user.yml Normal file
View File

@@ -0,0 +1,21 @@
---
- hosts: all
gather_facts: false
remote_user: user
vars:
rvm1_user: user
rvm1_install_path: '/home/{{ rvm1_user }}/.rvm'
rvm1_rubies:
- 'ruby-2.2.5'
- 'ruby-2.3.1'
roles:
- role: rvm1-ansible
become: yes
# Asserts tasks
- hosts: all
gather_facts: false
remote_user: user
tasks:
- name: Assert tasks
include: assertions.yml