Skip to content

Commit

Permalink
Fixes #48 and #49
Browse files Browse the repository at this point in the history
  • Loading branch information
haxorof committed Oct 6, 2018
1 parent a8ade5b commit 96adc61
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 46 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased](../../releases/tag/X.Y.Z)

### Added

- Add support to install Docker Ansible module dependencies ([#48](../../issues/48))
- Add support to install packages after install via PiP or OS package manager ([#49](../../issues/49))

## [1.7.2](../../releases/tag/1.7.2) - 2018-09-27

### Fixed
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ docker_latest_version: true
docker_pkg_name: docker-ce
# If below variable is set to true it will remove older Docker installation before Docker CE.
docker_remove_pre_ce: false
# Ensures 'docker_container' Ansible module dependencies are installed
docker_container_deps: false
# Ensures 'docker_service' Ansible module dependencies are installed
docker_service_deps: false
# Ensures 'docker_stack' Ansible module dependencies are installed
docker_stack_deps: false
# Ensure PiP is upgraded before further use.
# IMPORTANT! Be carful to set this because it might cause dependecy problems
docker_pip_upgrade: false
# Additional PiP packages to install after Docker is configured and started
docker_additional_packages_pip: []
# Additional OS packages to install after Docker is configured and started
docker_additional_packages_os: []
```
## Dependencies
Expand Down
15 changes: 13 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
# defaults file for ansible-role-docker-ce

# Daemon configuration (https://docs.docker.com/engine/reference/commandline/dockerd/)
# Example:
# docker_daemon_config:
Expand Down Expand Up @@ -32,3 +30,16 @@ docker_latest_version: true
docker_pkg_name: docker-ce
# If below variable is set to true it will remove older Docker installation before Docker CE.
docker_remove_pre_ce: false
# Ensures 'docker_container' Ansible module dependencies are installed
docker_container_deps: false
# Ensures 'docker_service' Ansible module dependencies are installed
docker_service_deps: false
# Ensures 'docker_stack' Ansible module dependencies are installed
docker_stack_deps: false
# Ensure PiP is upgraded before further use.
# IMPORTANT! Be carful to set this because it might cause dependecy problems
docker_pip_upgrade: false
# Additional PiP packages to install after Docker is configured and started
docker_additional_packages_pip: []
# Additional OS packages to install after Docker is configured and started
docker_additional_packages_os: []
4 changes: 4 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@
- name: Configure Docker
include_tasks: configure-docker.yml
tags: ["configure"]

- name: Postinstall tasks
include_tasks: postinstall.yml
tags: ["install"]
61 changes: 61 additions & 0 deletions tasks/postinstall.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
- name: Reset internal variables for additional packages to be installed
set_fact:
_docker_additional_packages_os: []
_docker_additional_packages_pip: []

- name: Set facts to ensure 'docker_container' module works
set_fact:
_docker_additional_packages_pip: "{{ _docker_additional_packages_pip + docker_predefined_packages_pip[_docker_os_dist]['sdk'] }}"
when:
- docker_container_deps

- name: Set facts to ensure 'docker_service' module works
set_fact:
_docker_additional_packages_pip: "{{ _docker_additional_packages_pip + docker_predefined_packages_pip[_docker_os_dist]['compose'] }}"
when:
- docker_service_deps

- name: Set facts to ensure 'docker_stack' module works
set_fact:
_docker_additional_packages_pip: "{{ _docker_additional_packages_pip + docker_predefined_packages_pip[_docker_os_dist]['stack'] }}"
when:
- docker_stack_deps

- name: Set facts with additional package to be installed
set_fact:
_docker_additional_packages_pip: "{{ _docker_additional_packages_pip + docker_additional_packages_pip }}"
_docker_additional_packages_os: "{{ _docker_additional_packages_os + docker_additional_packages_os }}"

- name: Set facts to ensure PiP is installed if required
set_fact:
_docker_additional_packages_os: "{{ _docker_additional_packages_os + ['python-pip', 'python-virtualenv'] }}"
when:
- _docker_additional_packages_pip | length > 0

- name: Install additional packages (OS package manager)
become: true
package:
name: "{{ item }}"
state: present
with_items:
- "{{ _docker_additional_packages_os }}"
when: _docker_additional_packages_os | length > 0

- name: Upgrade PiP
become: true
pip:
name: pip
state: forcereinstall
when: docker_pip_upgrade

- name: Install additional packages (PiP)
become: true
pip:
name: "{{ item }}"
state: present
with_items:
- "{{ _docker_additional_packages_pip }}"
when: _docker_additional_packages_pip | length > 0
environment:
PYTHONWARNINGS: ignore
14 changes: 12 additions & 2 deletions tests/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ require 'yaml'

current_dir = File.dirname(File.expand_path(__FILE__))
configs = YAML.load_file("#{current_dir}/vagrant_config.yml")
config_key = ENV['CONFIG_KEY'] || configs['configs']['use']
vagrant_config = configs['configs'][config_key]
vagrant_config={}
if ENV.has_key?('CI')
config_key = "CI"
vagrant_config['box'] = ENV['VAGRANT_BOX']
vagrant_config['prep_yml'] = ENV['VAGRANT_PREP_YML']
vagrant_config['test_yml'] = ENV['VAGRANT_TEST_YML']
else
config_key = ENV['CONFIG_KEY'] || configs['configs']['use']
vagrant_config = configs['configs'][config_key]
end

# Plugins:
# vagrant plugin install vagrant-vbguest
Expand All @@ -29,6 +37,8 @@ Vagrant.configure("2") do |config|
# Print config in use
config.vm.provision "shell",
inline: "echo '" + config_key + "' > /var/tmp/provisioning-config"
config.vm.provision "shell",
inline: "echo '--> Using configuration key: " + config_key + "'"

# Prepare Ansible roles directory
config.vm.provision "shell",
Expand Down
102 changes: 60 additions & 42 deletions tests/ci-test.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
#!/usr/bin/env bash
YAML_INC_FILE=yamlparser.sh.inc
if [[ ! -f "$YAML_INC_FILE" ]]; then
echo "Fetching YAML parsing script..."
wget -O $YAML_INC_FILE -q https://raw.githubusercontent.com/jasperes/bash-yaml/master/yaml.sh
fi
. $YAML_INC_FILE

UBUNTU_ON_WIN=$(uname -a | grep Microsoft)
if [[ $? -eq 0 ]]; then
echo "Ubuntu on Windows - assuming Vagrant is installed in Windows."
VAGRANT_CMD=vagrant.exe
# To share CONFIG_KEY to Windows environment
export CONFIG_KEY=
export WSLENV=CONFIG_KEY/w
else
VAGRANT_CMD=vagrant
fi

BLDRED='\033[1;31m'
BLDGRN='\033[1;32m'
BLDBLU='\033[1;34m'
Expand Down Expand Up @@ -45,6 +27,29 @@ RedText() {
printf "%b\n" "${BLDRED}$1${TXTRST}"
}

Info() {
printf "%b\n" "${BLDBLU}[INFO]${TXTRST} $1"
}

SetupYamlParser() {
YAML_INC_FILE=yamlparser.sh.inc
if [[ ! -f "$YAML_INC_FILE" ]]; then
Info "Fetching YAML parsing script..."
wget -O $YAML_INC_FILE -q https://raw.githubusercontent.com/jasperes/bash-yaml/master/yaml.sh
fi
. $YAML_INC_FILE
}

DetectWSL() {
UBUNTU_ON_WIN=$(uname -a | grep Microsoft)
if [[ $? -eq 0 ]]; then
Info "Ubuntu on Windows - assuming Vagrant is installed in Windows."
VAGRANT_CMD=vagrant.exe
else
VAGRANT_CMD=vagrant
fi
}

VagrantExists() {
if ! vagrant_loc="$(type -p $VAGRANT_CMD)" || [[ -z $vagrant_loc ]]; then
echo "1"
Expand Down Expand Up @@ -89,10 +94,9 @@ VagrantBoxAdd() {
}

DownloadBoxes() {
echo "Downloading boxes..."
boxes=$(parse_yaml vagrant_config.yml | grep _box | cut -d= -f2 | sed 's/[\(\"\)]//g' | sed "s/'//g" | sort | uniq)
Info "Downloading boxes..."
exitCode=0
for box in $boxes; do
for box in ${boxes[*]}; do
if [[ "$box" != *"$LIMIT"* ]]; then
Skip "Download $box"
continue
Expand All @@ -109,36 +113,50 @@ DownloadBoxes() {
}

ExecuteTests() {
echo "Starting tests..."
configs=$(parse_yaml vagrant_config.yml | grep _box | awk '{split($0,a,"_box"); $1=a[1]; split($1,b,"configs_"); $2=b[2]; print $2}')
exitCode=0
for config in $configs; do
CONFIG_KEY=$config
export CONFIG_KEY
if [[ "$CONFIG_KEY" != *"$LIMIT"* ]]; then
Skip "$CONFIG_KEY"
continue
fi
VagrantUp
exitCode=$?
VagrantDestroy
if [[ $exitCode == "0" ]]; then
Pass "Test $CONFIG_KEY"
else
Fail "Test $CONFIG_KEY"
break
fi
Info "Starting tests..."
#configs=$(parse_yaml vagrant_config.yml | grep _box | awk '{split($0,a,"_box"); $1=a[1]; split($1,b,"configs_"); $2=b[2]; print $2}')
configs=
for index in $(seq 0 `expr ${#tests__name[@]} - 1`); do
for box in ${boxes[*]}; do
test_name=${tests__name[$index]}
WSLENV=CI:VAGRANT_BOX:VAGRANT_PREP_YML:VAGRANT_TEST_YML
CI=1
VAGRANT_BOX=$box
VAGRANT_PREP_YML=${tests__prep_yml[$index]}
VAGRANT_TEST_YML=${tests__test_yml[$index]}
if [[ "$test_name" != *"$LIMIT"* ]]; then
Skip "Test: $test_name"
continue
fi
Info "Test: ${tests__name[$index]} [$box]"
export WSLENV CI VAGRANT_BOX VAGRANT_PREP_YML VAGRANT_TEST_YML
VagrantUp
exitCode=$?
VagrantDestroy
if [[ $exitCode == "0" ]]; then
Pass "Test: $test_name"
else
Fail "Test: $test_name"
break
fi
done
done
echo "Ended with exit code $exitCode"
exitCode=0
Info "Ended with exit code $exitCode"
return $exitCode
}

SetupYamlParser
DetectWSL

LIMIT=$1

create_variables vagrant_config.yml

if [[ "$SKIP_DOWNLOAD" == "" ]]; then
DownloadBoxes
downloadResult=$?
echo "Download complete!"
Info "Download complete!"
if [[ "$DOWNLOAD_ONLY" != "" ]]; then
exit $downloadResult
fi
Expand Down
24 changes: 24 additions & 0 deletions tests/test_postinstall.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- hosts: test-host
vars:
docker_container_deps: true
docker_service_deps: true
docker_stack_deps: true
roles:
- haxorof.docker-ce
post_tasks:
- name: Test hello container
become: yes
docker_container:
name: hello
image: hello-world

- name: Test hello service
become: yes
docker_service:
project_name: hello
definition:
version: '3'
services:
hello:
image: "hello-world"
65 changes: 65 additions & 0 deletions tests/vagrant_config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
boxes:
- geerlingguy/centos7
- geerlingguy/ubuntu1404
- geerlingguy/ubuntu1604
- geerlingguy/ubuntu1804
- geerlingguy/debian8
- geerlingguy/debian9
tests:
-
name: No configuration
prep_yml: prepare.yml
test_yml: test_defaults.yml
-
name: Simple configuration
prep_yml: prepare.yml
test_yml: test_config.yml
-
name: Configuration via file
prep_yml: prepare.yml
test_yml: test_config_file.yml
-
name: Advanced configuration
prep_yml: prepare.yml
test_yml: test_config_adv.yml
-
name: Storage configuration
prep_yml: prepare_storage.yml
test_yml: test_config_storage.yml
-
name: Postinstall
prep_yml: prepare.yml
test_yml: test_postinstall.yml
-
name: Old version of Docker
prep_yml: prepare.yml
test_yml: test_old_version.yml
-
name: Issue 42
prep_yml: prepare.yml
test_yml: test_issue_42.yml
configs:
use: 'defaults_centos'
# CentOS 7
Expand All @@ -11,6 +51,31 @@ configs:
box: 'geerlingguy/centos7'
prep_yml: prepare.yml
test_yml: test_defaults.yml
# Postinstall tests
postinstall_centos:
box: 'geerlingguy/centos7'
prep_yml: prepare.yml
test_yml: test_postinstall.yml
postinstall_ubuntu_trusty:
box: 'geerlingguy/ubuntu1404'
prep_yml: prepare.yml
test_yml: test_postinstall.yml
postinstall_ubuntu_xenial:
box: 'geerlingguy/ubuntu1604'
prep_yml: prepare.yml
test_yml: test_postinstall.yml
postinstall_ubuntu_bionic:
box: 'geerlingguy/ubuntu1804'
prep_yml: prepare.yml
test_yml: test_postinstall.yml
postinstall_debian_jessie:
box: 'geerlingguy/debian8'
prep_yml: prepare.yml
test_yml: test_postinstall.yml
postinstall_debian_stretch:
box: 'geerlingguy/debian9'
prep_yml: prepare.yml
test_yml: test_postinstall.yml
# Config tests
config_centos:
box: 'geerlingguy/centos7'
Expand Down
Loading

0 comments on commit 96adc61

Please sign in to comment.