From 94a16a67311a2bc3ec63b8fbf6a7689b1be00cd1 Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Thu, 11 Jul 2019 12:42:28 +1000 Subject: [PATCH] DCD-484: Add ability to install from the tarball rather than the installer. --- roles/product_install/defaults/main.yml | 7 +++- .../molecule/jira_tarball/Dockerfile.j2 | 14 ++++++++ .../molecule/jira_tarball/molecule.yml | 32 +++++++++++++++++++ .../molecule/jira_tarball/playbook.yml | 12 +++++++ .../jira_tarball/tests/test_default.py | 28 ++++++++++++++++ roles/product_install/tasks/main.yml | 18 ++--------- .../tasks/unpack_installer.yml | 18 +++++++++++ .../product_install/tasks/unpack_tarball.yml | 15 +++++++++ 8 files changed, 127 insertions(+), 17 deletions(-) create mode 100644 roles/product_install/molecule/jira_tarball/Dockerfile.j2 create mode 100644 roles/product_install/molecule/jira_tarball/molecule.yml create mode 100644 roles/product_install/molecule/jira_tarball/playbook.yml create mode 100644 roles/product_install/molecule/jira_tarball/tests/test_default.py create mode 100644 roles/product_install/tasks/unpack_installer.yml create mode 100644 roles/product_install/tasks/unpack_tarball.yml diff --git a/roles/product_install/defaults/main.yml b/roles/product_install/defaults/main.yml index 9b26675..6cc5efd 100644 --- a/roles/product_install/defaults/main.yml +++ b/roles/product_install/defaults/main.yml @@ -8,9 +8,14 @@ atl_product_latest_version_url: "https://marketplace.atlassian.com/rest/2/applic atl_product_version_cache_dir: "{{ atl_product_home_shared }}" atl_product_version_cache: "{{ atl_product_home_shared }}/{{ atl_product_edition }}.version" +atl_download_format: 'installer' +atl_download_format_suffix_map: + installer: '-x64.bin' + tarball: '.tar.gz' + atl_release_base_url: "https://product-downloads.atlassian.com/software" atl_product_base_url: "{{ atl_release_base_url }}/{{ atl_product_family }}/downloads" -atl_product_download_url: "{{ atl_product_base_url }}/atlassian-{{ atl_download_edition | default(atl_product_edition) }}-{{ atl_product_version }}-x64.bin" +atl_product_download_url: "{{ atl_product_base_url }}/atlassian-{{ atl_download_edition | default(atl_product_edition) }}-{{ atl_product_version }}{{ atl_download_format_suffix_map[atl_download_format] }}" atl_product_download_filename: "{{ atl_download_edition | default(atl_product_edition) }}.{{ atl_product_version }}.bin" atl_product_download: "{{ atl_installer_temp }}/{{ atl_product_download_filename }}" diff --git a/roles/product_install/molecule/jira_tarball/Dockerfile.j2 b/roles/product_install/molecule/jira_tarball/Dockerfile.j2 new file mode 100644 index 0000000..e6aa95d --- /dev/null +++ b/roles/product_install/molecule/jira_tarball/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/product_install/molecule/jira_tarball/molecule.yml b/roles/product_install/molecule/jira_tarball/molecule.yml new file mode 100644 index 0000000..46049f8 --- /dev/null +++ b/roles/product_install/molecule/jira_tarball/molecule.yml @@ -0,0 +1,32 @@ +--- +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 + options: + skip-tags: runtime_pkg + lint: + name: ansible-lint + inventory: + links: + group_vars: ../../../../group_vars/ +verifier: + name: testinfra + additional_files_or_dirs: + - ../../resources/tests/test_*.py + lint: + name: flake8 + enabled: false diff --git a/roles/product_install/molecule/jira_tarball/playbook.yml b/roles/product_install/molecule/jira_tarball/playbook.yml new file mode 100644 index 0000000..7d49215 --- /dev/null +++ b/roles/product_install/molecule/jira_tarball/playbook.yml @@ -0,0 +1,12 @@ +--- +- name: Converge + hosts: all + vars: + atl_product_family: "jira" + atl_product_edition: "jira-core" + atl_product_user: "jira" + atl_download_format: "tarball" + roles: + - role: linux_common + - role: product_common + - role: product_install diff --git a/roles/product_install/molecule/jira_tarball/tests/test_default.py b/roles/product_install/molecule/jira_tarball/tests/test_default.py new file mode 100644 index 0000000..18c41a2 --- /dev/null +++ b/roles/product_install/molecule/jira_tarball/tests/test_default.py @@ -0,0 +1,28 @@ +import os +from six.moves import urllib + +import testinfra.utils.ansible_runner +import json + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_version_file_is_latest(host): + verfile = host.file('/media/atl/jira/shared/jira-core.version') + assert verfile.exists + + upstream_fd = urllib.request.urlopen("https://marketplace.atlassian.com/rest/2/applications/jira/versions/latest") + upstream_json = json.load(upstream_fd) + upstream = upstream_json['version'] + + assert verfile.content.decode("UTF-8").strip() == upstream.strip() + +def test_latest_is_downloaded(host): + upstream_fd = urllib.request.urlopen("https://marketplace.atlassian.com/rest/2/applications/jira/versions/latest") + upstream_json = json.load(upstream_fd) + upstream = upstream_json['version'] + + installer = host.file('/opt/atlassian/tmp/jira-core.'+upstream+'.bin') + assert installer.exists + assert installer.user == 'root' diff --git a/roles/product_install/tasks/main.yml b/roles/product_install/tasks/main.yml index 67a5251..5dcc2fc 100644 --- a/roles/product_install/tasks/main.yml +++ b/roles/product_install/tasks/main.yml @@ -137,22 +137,8 @@ mode: 0755 force: false -- name: Create installer varfile - template: - src: "{{ atl_product_family }}.varfile.j2" - dest: "{{ atl_product_varfile }}" - mode: 0755 - -# NOTE: We run the installer as the user rather than root to limit its -# actions. For example, if root and the 'jira' user exists then it -# will create 'jira1'; this potentially creates idempotency/upgrade -# issues down the line. -- name: Run the installer - command: /bin/sh "{{ atl_product_download }}" -q -varfile "{{ atl_product_varfile }}" - args: - creates: "{{ atl_product_installation_versioned }}/.install4j/" - become: true - become_user: "{{ atl_product_user }}" +- name: Unpack the downloaded application depending on format + include_tasks: "unpack_{{ atl_download_format }}.yml" - name: Symlink the installed version to current file: diff --git a/roles/product_install/tasks/unpack_installer.yml b/roles/product_install/tasks/unpack_installer.yml new file mode 100644 index 0000000..925dca0 --- /dev/null +++ b/roles/product_install/tasks/unpack_installer.yml @@ -0,0 +1,18 @@ +--- + +- name: Create installer varfile + template: + src: "{{ atl_product_family }}.varfile.j2" + dest: "{{ atl_product_varfile }}" + mode: 0755 + +# NOTE: We run the installer as the user rather than root to limit its +# actions. For example, if root and the 'jira' user exists then it +# will create 'jira1'; this potentially creates idempotency/upgrade +# issues down the line. +- name: Run the installer + command: /bin/sh "{{ atl_product_download }}" -q -varfile "{{ atl_product_varfile }}" + args: + creates: "{{ atl_product_installation_versioned }}/.install4j/" + become: true + become_user: "{{ atl_product_user }}" diff --git a/roles/product_install/tasks/unpack_tarball.yml b/roles/product_install/tasks/unpack_tarball.yml new file mode 100644 index 0000000..e192c0e --- /dev/null +++ b/roles/product_install/tasks/unpack_tarball.yml @@ -0,0 +1,15 @@ +--- + +- name: Unpack the product packages + unarchive: + remote_src: true + src: "{{ atl_product_download }}" + dest: "{{ atl_product_installation_versioned }}" + owner: "{{ atl_product_user }}" + group: "{{ atl_product_user }}" + mode: 0755 + # Strip off the lead product/version specific directory to normaise naming + extra_opts: + - "--strip-components=1" + # NOTE: Currently all products contain a `README.txt`, so use that as an 'unpacked' marker. + creates: "{{ atl_product_installation_versioned }}/README.txt"