From 0a6769a8bd95112d4a2b592800659290f24d6d35 Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Wed, 17 Jul 2019 13:48:57 +1000 Subject: [PATCH] DCD-486: Add optional Docker installation. --- aws_jira_dc_node_docker.yml | 2 ++ roles/linux_common/defaults/main.yml | 1 + .../molecule/default/tests/test_default.py | 1 + .../molecule/docker/Dockerfile.j2 | 14 ++++++++++ .../linux_common/molecule/docker/molecule.yml | 27 +++++++++++++++++++ .../linux_common/molecule/docker/playbook.yml | 8 ++++++ .../molecule/docker/tests/test_default.py | 11 ++++++++ roles/linux_common/tasks/amazon.yml | 6 +++++ roles/linux_common/tasks/ubuntu.yml | 6 +++++ 9 files changed, 76 insertions(+) create mode 100644 roles/linux_common/molecule/docker/Dockerfile.j2 create mode 100644 roles/linux_common/molecule/docker/molecule.yml create mode 100644 roles/linux_common/molecule/docker/playbook.yml create mode 100644 roles/linux_common/molecule/docker/tests/test_default.py diff --git a/aws_jira_dc_node_docker.yml b/aws_jira_dc_node_docker.yml index 941d0e4..786fd1f 100644 --- a/aws_jira_dc_node_docker.yml +++ b/aws_jira_dc_node_docker.yml @@ -8,6 +8,8 @@ atl_product_user: "jira" atl_product_edition: "jira-{{ lookup('env', 'ATL_PRODUCT_EDITION') | lower }}" + alt_docker_install: true + roles: - role: linux_common - role: aws_common diff --git a/roles/linux_common/defaults/main.yml b/roles/linux_common/defaults/main.yml index 561baf2..ac4cd7f 100644 --- a/roles/linux_common/defaults/main.yml +++ b/roles/linux_common/defaults/main.yml @@ -1,3 +1,4 @@ --- +atl_docker_install: false atl_product_user_uid: '2001' diff --git a/roles/linux_common/molecule/default/tests/test_default.py b/roles/linux_common/molecule/default/tests/test_default.py index 123aa3c..f243e41 100644 --- a/roles/linux_common/molecule/default/tests/test_default.py +++ b/roles/linux_common/molecule/default/tests/test_default.py @@ -14,3 +14,4 @@ def test_user_prereq(host): def test_support_packages(host): assert host.file('/usr/bin/jq').exists assert host.file('/usr/bin/curl').exists + assert not host.file('/usr/bin/docker').exists diff --git a/roles/linux_common/molecule/docker/Dockerfile.j2 b/roles/linux_common/molecule/docker/Dockerfile.j2 new file mode 100644 index 0000000..e6aa95d --- /dev/null +++ b/roles/linux_common/molecule/docker/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/roles/linux_common/molecule/docker/molecule.yml b/roles/linux_common/molecule/docker/molecule.yml new file mode 100644 index 0000000..bf5d3fc --- /dev/null +++ b/roles/linux_common/molecule/docker/molecule.yml @@ -0,0 +1,27 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: amazon_linux2 + image: amazonlinux:2 + groups: + - aws_node_local + - name: ubuntu_lts + image: ubuntu:bionic + groups: + - aws_node_local +provisioner: + name: ansible + lint: + name: ansible-lint + inventory: + links: + group_vars: ../../../../group_vars/ +verifier: + name: testinfra + lint: + name: flake8 diff --git a/roles/linux_common/molecule/docker/playbook.yml b/roles/linux_common/molecule/docker/playbook.yml new file mode 100644 index 0000000..78c265c --- /dev/null +++ b/roles/linux_common/molecule/docker/playbook.yml @@ -0,0 +1,8 @@ +--- +- name: Converge + hosts: all + vars: + atl_product_user: "jira" + atl_docker_install: true + roles: + - role: linux_common diff --git a/roles/linux_common/molecule/docker/tests/test_default.py b/roles/linux_common/molecule/docker/tests/test_default.py new file mode 100644 index 0000000..0b526fc --- /dev/null +++ b/roles/linux_common/molecule/docker/tests/test_default.py @@ -0,0 +1,11 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_support_packages(host): + assert host.file('/usr/bin/docker').exists + diff --git a/roles/linux_common/tasks/amazon.yml b/roles/linux_common/tasks/amazon.yml index 3be04db..a445437 100644 --- a/roles/linux_common/tasks/amazon.yml +++ b/roles/linux_common/tasks/amazon.yml @@ -6,3 +6,9 @@ - shadow-utils - libxml2 - git-{{ git_version }} + +- name: Install Docker if necessary + command: amazon-linux-extras install -y docker + args: + creates: /usr/bin/docker + when: atl_docker_install diff --git a/roles/linux_common/tasks/ubuntu.yml b/roles/linux_common/tasks/ubuntu.yml index b5c542c..435a96f 100644 --- a/roles/linux_common/tasks/ubuntu.yml +++ b/roles/linux_common/tasks/ubuntu.yml @@ -6,3 +6,9 @@ - python3-psycopg2 - libxml2-utils - git + +- name: Install Docker if necessary + apt: + name: + - docker.io + when: atl_docker_install