-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #977 from wainersm/docker_provider_v3
Merged by Jenkins
- Loading branch information
Showing
31 changed files
with
770 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
docker-new: | ||
topology: docker-new.yml | ||
layout: docker-new.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
9
docs/source/examples/workspaces/docker/layouts/docker-new.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
docs/source/examples/workspaces/docker/topologies/docker-new.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
linchpin/provision/roles/dependencies/tasks/docker_deps.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.