diff --git a/roles/product_common/defaults/main.yml b/roles/product_common/defaults/main.yml index 70c4ee2..cb807b0 100644 --- a/roles/product_common/defaults/main.yml +++ b/roles/product_common/defaults/main.yml @@ -6,4 +6,4 @@ git_version: "2.14.4" # Disable these when using the product installer, otherwise we end up # fighting with it. -use_system_jdk: false +atl_use_system_jdk: false diff --git a/roles/product_common/molecule/system_jdk/Dockerfile.j2 b/roles/product_common/molecule/system_jdk/Dockerfile.j2 new file mode 100644 index 0000000..e6aa95d --- /dev/null +++ b/roles/product_common/molecule/system_jdk/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_common/molecule/system_jdk/molecule.yml b/roles/product_common/molecule/system_jdk/molecule.yml new file mode 100644 index 0000000..c6a6d26 --- /dev/null +++ b/roles/product_common/molecule/system_jdk/molecule.yml @@ -0,0 +1,20 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: amazon_linux2 + image: amazonlinux:2 + - name: ubuntu_lts + image: ubuntu:bionic +provisioner: + name: ansible + lint: + name: ansible-lint +verifier: + name: testinfra + lint: + name: flake8 diff --git a/roles/product_common/molecule/system_jdk/playbook.yml b/roles/product_common/molecule/system_jdk/playbook.yml new file mode 100644 index 0000000..8fec31a --- /dev/null +++ b/roles/product_common/molecule/system_jdk/playbook.yml @@ -0,0 +1,14 @@ +--- +- name: Converge + hosts: all + vars: + atl_product_user: "testuser" + atl_product_home: "/opt/atlassian/product" + atl_product_installation_base: "/opt/atlassian/product/install" + atl_installer_temp: "/opt/atlassian/temp" + atl_product_home_shared: "/media/atl/jira/shared" + atl_product_shared_plugins: "/media/atl/jira/shared/plugins/" + atl_use_system_jdk: true + roles: + - role: linux_common + - role: product_common diff --git a/roles/product_common/molecule/system_jdk/tests/test_default.py b/roles/product_common/molecule/system_jdk/tests/test_default.py new file mode 100644 index 0000000..77d3c52 --- /dev/null +++ b/roles/product_common/molecule/system_jdk/tests/test_default.py @@ -0,0 +1,20 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_user_created(host): + user = host.user('testuser') + assert user.exists + + +@pytest.mark.parametrize('exe', [ + '/usr/bin/git', + '/usr/bin/javac' +]) +def test_package_exes(host, exe): + assert host.file(exe).exists diff --git a/roles/product_common/tasks/amazon.yml b/roles/product_common/tasks/amazon.yml index c34c322..c02f864 100644 --- a/roles/product_common/tasks/amazon.yml +++ b/roles/product_common/tasks/amazon.yml @@ -4,7 +4,7 @@ yum: name: - java-{{ java_version }}-openjdk-devel - when: use_system_jdk + when: atl_use_system_jdk - name: Install other base packages on Amazon Linux yum: diff --git a/roles/product_common/tasks/ubuntu.yml b/roles/product_common/tasks/ubuntu.yml index 68a20ff..55c6311 100644 --- a/roles/product_common/tasks/ubuntu.yml +++ b/roles/product_common/tasks/ubuntu.yml @@ -4,7 +4,7 @@ package: name: - openjdk-{{ java_major_version }}-jdk-headless - when: use_system_jdk + when: atl_use_system_jdk tags: - runtime_pkg diff --git a/roles/product_install/defaults/main.yml b/roles/product_install/defaults/main.yml index b81fd0c..b3c5cec 100644 --- a/roles/product_install/defaults/main.yml +++ b/roles/product_install/defaults/main.yml @@ -8,13 +8,19 @@ 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_download_suffix: "{{ atl_download_format_suffix_map[atl_download_format] }}" + 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_crowd_download_url: "{{ atl_product_base_url }}/atlassian-{{ atl_download_edition | default(atl_product_edition) }}-{{ atl_product_version }}.tar.gz" -atl_crowd_latest_url: "https://www.atlassian.com/software/crowd/downloads/binary/crowd-standalone-distribution-{{atl_latest_version}}.tar.gz" +#atl_crowd_download_url: "{{ atl_product_base_url }}/atlassian-{{ atl_download_edition | default(atl_product_edition) }}-{{ atl_product_version }}.tar.gz" +#atl_crowd_latest_url: "https://www.atlassian.com/software/crowd/downloads/binary/crowd-standalone-distribution-{{atl_latest_version}}.tar.gz" +atl_product_download_url: "{{ atl_product_base_url }}/atlassian-{{ atl_download_edition | default(atl_product_edition) }}-{{ atl_product_version }}{{ atl_download_suffix }}" -atl_product_download_filename: "{{ atl_download_edition | default(atl_product_edition) }}.{{ atl_product_version }}.bin" +atl_product_download_filename: "{{ atl_download_edition | default(atl_product_edition) }}.{{ atl_product_version }}{{ atl_download_suffix }}" atl_product_download: "{{ atl_installer_temp }}/{{ atl_product_download_filename }}" atl_product_varfile: "{{ atl_installer_temp }}/{{ atl_product_family }}.varfile" 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..2f5d09b --- /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+'.tar.gz') + assert installer.exists + assert installer.user == 'root' diff --git a/roles/product_install/tasks/main.yml b/roles/product_install/tasks/main.yml index 9ae3ce8..6be897f 100644 --- a/roles/product_install/tasks/main.yml +++ b/roles/product_install/tasks/main.yml @@ -159,6 +159,9 @@ - import_tasks: crowd_install.yml when: atl_product_edition == "crowd" +- name: Unpack the downloaded application depending on format + include_tasks: "unpack_{{ atl_download_format }}.yml" + - name: Symlink the installed version to current file: src: "{{ atl_product_installation_versioned }}" 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..196928f --- /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 normalise 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"