Skip to content

Commit

Permalink
Merge pull request #977 from wainersm/docker_provider_v3
Browse files Browse the repository at this point in the history
Merged by Jenkins
  • Loading branch information
paas-bot authored May 8, 2019
2 parents c3745cd + 116d869 commit f3f1b1b
Show file tree
Hide file tree
Showing 31 changed files with 770 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/Dockerfiles/linchpin-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pip install .
pip install .[tests]
pip install .[libvirt]
pip install .[beaker]
pip install .[docker]

# If duffy.key is available then install duffy ansible module.
if [ -e "keys/duffy.key" ]; then
Expand Down
21 changes: 21 additions & 0 deletions config/Dockerfiles/tests.d/docker/01_docker-setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash -xe

# Verify linchpin setup docker. Other tests depend this installing docker right.
# distros.exclude: none
# providers.include: docker
# providers.exclude: none

DISTRO=${1}

PROVIDER=${2}

TEST_NAME="${DISTRO}/${PROVIDER}/01_docker-setup"
DESCRIPTION="Test ${PROVIDER} provider setup"

echo "Test Name: ${TEST_NAME}"
echo "${DESCRIPTION}"


pushd docs/source/examples/workspaces/${PROVIDER}

linchpin setup docker
33 changes: 33 additions & 0 deletions config/Dockerfiles/tests.d/docker/02_docker-container
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash -xe

# Verify docker container and image provisioning.
# distros.exclude: none
# providers.include: docker
# providers.exclude: none

DISTRO=${1}

PROVIDER=${2}

TARGETS="${PROVIDER}-new"
TEST_NAME="${DISTRO}/${PROVIDER}/01_docker-container"
DESCRIPTION="Test ${PROVIDER} provider with a simple up/destroy"

echo "Test Name: ${TEST_NAME}"
echo "${DESCRIPTION}"


pushd docs/source/examples/workspaces/${PROVIDER}

function clean_up {
set +e
D_RC=0
linchpin -w . -v destroy ${TARGET}
D_RC=(${?} -o ${D_RC})
if [ ${D_RC} -ne 0 ]; then
exit ${D_RC}
fi
}
trap clean_up EXIT SIGHUP SIGINT SIGTERM

linchpin -w . -vvvv up ${TARGET}
2 changes: 1 addition & 1 deletion config/Dockerfiles/tests.d/general/01_general
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Verify basic provisioning for all supplied providers
# distros.exclude: centos7 fedora28
# providers.include: none
# providers.exclude: vmware
# providers.exclude: vmware docker

DISTRO=${1}
PROVIDER=${2}
Expand Down
2 changes: 2 additions & 0 deletions config/Dockerfiles/tests.d/general/02_validate
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ elif [ "${PROVIDER}" == "duffy" ]; then
TARGETS="duffy-new"
elif [ "${PROVIDER}" == "openshift" ]; then
TARGETS="openshift-new"
elif [ "${PROVIDER}" == "docker" ]; then
TARGETS="docker-new"
else
TARGETS="dummy-new"
fi
Expand Down
2 changes: 1 addition & 1 deletion config/Dockerfiles/tests.d/inventory/01_template_inventory
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Verify template-based provisioning using complex template data file
# distros.exclude: centos7 fedora28
# providers.include: none
# providers.exclude: dummy openstack beaker duffy openshift gcloud aws
# providers.exclude: dummy openstack beaker duffy openshift gcloud aws docker

DISTRO=${1}
PROVIDER=${2}
Expand Down
44 changes: 44 additions & 0 deletions docs/source/docker.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Docker
======

The docker provider manages ``docker_container`` and ``docker_image`` resources.

* :docs1.5:`Topology Example <workspaces/docker/topologies/docker-new.yml>`

docker_container
----------------

The ``docker_container`` resource provides the ability to provision a Docker
container. It is implemented as a wrapper around the Ansible's `docker_container <https://docs.ansible.com/ansible/latest/modules/docker_container_module.html>`
module so that same requirements, parameters, and behavior are expected.

Topology Schema
~~~~~~~~~~~~~~

Within Linchpin, the :term:`docker_container` :term:`resource_definition` has more
options than what are shown in the examples above. For each :term:`docker_container`
definition, the same options of the Ansible `docker_container` module are available. The :term: name :term: option is required.

See the `docker_container parameters <https://docs.ansible.com/ansible/latest/modules/docker_container_module.html#parameters>` for the complete list and defaults.

docker_image
------------

The ``docker_image`` resource provides the ability to manage a Docker image. It is implemented as a wrapper around the Ansible's `docker_image <https://docs.ansible.com/ansible/latest/modules/docker_image_module.html>` module so that same requirements, parameters, and behavior are expected.

Topology Schema
~~~~~~~~~~~~~~~

Within Linchpin, the :term:`docker_image` :term:`resource_definition` has more
options than what are shown in the examples above. For each :term:`docker_image`
definition, the same options of the Ansible `docker_image` module are available. The :term: name :term: option is required.

See the `docker_image parameters <https://docs.ansible.com/ansible/latest/modules/docker_image_module.html#parameters>` for the complete list and defaults.

.. note:: The provider assume that the ``cacert_path``, ``cert_path``, ``path``, and ``load_path`` parameter value are relative to the workspace path, unless its value is absolute (e.g. /path/to/cert) or relative (e.g. ./path/to/cert) to the OS filesystem.

Additional Dependencies
-----------------------

The docker resource group requires the same dependencies of the Ansible docker_container module. See the `docker_container requirements <https://docs.ansible.com/ansible/latest/modules/docker_container_module.html#requirements>` documentation for the complete list of dependencies and any further detail.

4 changes: 4 additions & 0 deletions docs/source/examples/workspaces/docker/PinFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
docker-new:
topology: docker-new.yml
layout: docker-new.yml
3 changes: 3 additions & 0 deletions docs/source/examples/workspaces/docker/dockerfiles/fedora29
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM fedora:29

RUN dnf install -y python-devel
9 changes: 9 additions & 0 deletions docs/source/examples/workspaces/docker/layouts/docker-new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
inventory_layout:
vars:
ansible_connection: docker
hosts:
container:
count: 1
host_groups:
- fc29
17 changes: 17 additions & 0 deletions docs/source/examples/workspaces/docker/topologies/docker-new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
topology_name: "docker-new"
resource_groups:
- resource_group_name: docker
resource_group_type: docker
resource_definitions:
- role: docker_image
name: custom_fedora29
dockerfile: fedora29
path: dockerfiles
tag: python
- role: docker_container
name: myfedora29
command: sleep infinity
image: "custom_fedora29:python"
devices:
- "/dev/kvm:/dev/kvm"
1 change: 1 addition & 0 deletions docs/source/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ LinchPin has many default providers. This choose-your-own-adventure page takes y
beaker
duffy
ovirt
docker
openshift
rackspace
provider_external
Expand Down
34 changes: 34 additions & 0 deletions linchpin/InventoryFilters/DockerInventory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
try:
from StringIO import StringIO
except ImportError:
from io import StringIO

from .InventoryFilter import InventoryFilter


class DockerInventory(InventoryFilter):
DEFAULT_HOSTNAMES = ['Config.Hostname']

def get_host_data(self, res, config):
host_data = {}
# Only docker_container resource type produces host data.
if res['resource_type'] != 'docker_container_res':
return host_data
var_data = config.get('docker', {})
if var_data is None:
var_data = {}
host = self.get_hostname(res, var_data,
self.DEFAULT_HOSTNAMES)
hostname_var = host[0]
hostname = host[1]
host_data[hostname] = {}
if '__IP__' not in var_data.keys():
var_data['__IP__'] = hostname_var
self.set_config_values(host_data[hostname], res, var_data)
return host_data

def get_inventory(self, res, layout, config):
output = StringIO()
self.config.write(output)

return output.getvalue()
3 changes: 3 additions & 0 deletions linchpin/InventoryFilters/InventoryProviders.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .OpenstackInventory import OpenstackInventory
from .OvirtInventory import OvirtInventory
from .VMwareInventory import VMwareInventory
from .DockerInventory import DockerInventory

from .CFGInventoryFormatter import CFGInventoryFormatter
from .JSONInventoryFormatter import JSONInventoryFormatter
Expand All @@ -28,6 +29,8 @@
"os_server_res": OpenstackInventory,
"ovirt_vms_res": OvirtInventory,
"vmware_guest_res": VMwareInventory,
"docker_container_res": DockerInventory,
"docker_image_res": DockerInventory,
}

formatter_classes = {
Expand Down
6 changes: 6 additions & 0 deletions linchpin/provision/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ VMware
Provision virtual machines on ESXi hosts.

Reference: https://docs.ansible.com/ansible/latest/modules/vmware_guest_module.html

Docker
======
Provisions Docker containers and resources. See http://www.docker.com/ for more detail about Docker.

Reference: https://docs.ansible.com/ansible/latest/scenario_guides/guide_docker.html
20 changes: 20 additions & 0 deletions linchpin/provision/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# This playbook provisions the docker topology.

- name: "schema check and Pre Provisioning Activities on topology_file"
hosts: localhost
gather_facts: True
roles:
- { role: 'common' }

- name: "Provisioning Docker resources"
hosts: localhost
gather_facts: False
roles:
- { role: 'docker' }

- name: "Gather resources to the RunDB"
hosts: localhost
gather_facts: False
roles:
- { role: 'gather_resources' }
18 changes: 18 additions & 0 deletions linchpin/provision/filter_plugins/path_relative_to.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python

import os


def path_relative_to(path, base_path):
"""
If `path` is not an OS filesystem absolute or relative path then assume
it is relative to `base_path`.
"""
if path.startswith(('/', './', '../', '~/')):
return path
return os.path.join(base_path, path)


class FilterModule(object):
def filters(self):
return {'path_relative_to': path_relative_to}
28 changes: 28 additions & 0 deletions linchpin/provision/roles/dependencies/tasks/docker_deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- block:
- name: Get current user
set_fact:
current_user: "{{ lookup('env','USER') }}"

- name: Gather facts
setup:

- name: The geerlingguy.role is present
command: ansible-galaxy install geerlingguy.docker

- name: Setup selinux
include_tasks: setup_selinux_deps.yml

- name: Docker is present
include_role:
name: geerlingguy.docker
vars:
docker_edition: "ce"
docker_package: "docker-{{ docker_edition }}"
docker_package_state: present
docker_users: "{{ (current_user != '') | ternary([current_user], []) }}"

- name: Docker python library is present
pip:
name: docker-py
state: present
become: true
3 changes: 2 additions & 1 deletion linchpin/provision/roles/dependencies/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
msg: "{{ setup_providers }}"


- name: Install dependecies per provider
- name: Install dependencies per provider
include_tasks: "{{ indv_prov }}_deps.yml"
with_items: "{{ setup_providers }}"
loop_control:
Expand All @@ -19,6 +19,7 @@
- docs
- test
- setup_selinux
- docker
when: setup_providers | length == 0
loop_control:
loop_var: setup_prov
Loading

0 comments on commit f3f1b1b

Please sign in to comment.