Add 'chartmuseum' role 37/117137/1
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Tue, 26 Jan 2021 14:30:12 +0000 (15:30 +0100)
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>
Tue, 26 Jan 2021 14:30:12 +0000 (15:30 +0100)
Added 'chartmuseum' role which runs Helm repository server using
chartmuseum.

Change-Id: I8745cd7e602e147fb656297e0afb8e82a5d058ff
Issue-ID: OOM-2665
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
ansible/roles/chartmuseum/.yamllint [new file with mode: 0644]
ansible/roles/chartmuseum/defaults/main.yml [new file with mode: 0644]
ansible/roles/chartmuseum/molecule/default/Dockerfile.j2 [new file with mode: 0644]
ansible/roles/chartmuseum/molecule/default/molecule.yml [new file with mode: 0644]
ansible/roles/chartmuseum/molecule/default/playbook.yml [new file with mode: 0644]
ansible/roles/chartmuseum/molecule/default/prepare.yml [new file with mode: 0644]
ansible/roles/chartmuseum/molecule/default/tests/test_default.py [new file with mode: 0644]
ansible/roles/chartmuseum/tasks/main.yml [new file with mode: 0644]
ansible/test/roles/prepare-chartmuseum/tasks/main.yml [new file with mode: 0644]

diff --git a/ansible/roles/chartmuseum/.yamllint b/ansible/roles/chartmuseum/.yamllint
new file mode 100644 (file)
index 0000000..ad0be76
--- /dev/null
@@ -0,0 +1,11 @@
+extends: default
+
+rules:
+  braces:
+    max-spaces-inside: 1
+    level: error
+  brackets:
+    max-spaces-inside: 1
+    level: error
+  line-length: disable
+  truthy: disable
diff --git a/ansible/roles/chartmuseum/defaults/main.yml b/ansible/roles/chartmuseum/defaults/main.yml
new file mode 100644 (file)
index 0000000..6816d15
--- /dev/null
@@ -0,0 +1,3 @@
+---
+chartmuseum_port: "8879"
+chartmuseum_storage_dir: "{{ app_data_path }}/chartmuseum"
diff --git a/ansible/roles/chartmuseum/molecule/default/Dockerfile.j2 b/ansible/roles/chartmuseum/molecule/default/Dockerfile.j2
new file mode 100644 (file)
index 0000000..e6aa95d
--- /dev/null
@@ -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/ansible/roles/chartmuseum/molecule/default/molecule.yml b/ansible/roles/chartmuseum/molecule/default/molecule.yml
new file mode 100644 (file)
index 0000000..07652b7
--- /dev/null
@@ -0,0 +1,33 @@
+---
+dependency:
+  name: galaxy
+driver:
+  name: docker
+lint:
+  name: yamllint
+platforms:
+  - name: instance-chartmuseum
+    image: centos:7
+    groups:
+      - infrastructure
+provisioner:
+  name: ansible
+  lint:
+    name: ansible-lint
+  env:
+    ANSIBLE_ROLES_PATH: ../../../../test/roles
+    ANSIBLE_LIBRARY: ../../../../library
+  inventory:
+    group_vars:
+      all:
+        app_name: moleculetestapp
+        app_data_path: "/opt/{{ app_name }}"
+        helm_bin_dir: /usr/local/bin
+        chartmuseum_storage_dir: "/opt/{{ app_name }}/chartmuseum"
+        chartmuseum_port: "1234"
+scenario:
+  name: default
+verifier:
+  name: testinfra
+  lint:
+    name: flake8
diff --git a/ansible/roles/chartmuseum/molecule/default/playbook.yml b/ansible/roles/chartmuseum/molecule/default/playbook.yml
new file mode 100644 (file)
index 0000000..2694582
--- /dev/null
@@ -0,0 +1,5 @@
+---
+- name: Converge
+  hosts: all
+  roles:
+    - chartmuseum
diff --git a/ansible/roles/chartmuseum/molecule/default/prepare.yml b/ansible/roles/chartmuseum/molecule/default/prepare.yml
new file mode 100644 (file)
index 0000000..5201bce
--- /dev/null
@@ -0,0 +1,5 @@
+---
+- name: Prepare infra
+  hosts: infrastructure
+  roles:
+    - prepare-chartmuseum
diff --git a/ansible/roles/chartmuseum/molecule/default/tests/test_default.py b/ansible/roles/chartmuseum/molecule/default/tests/test_default.py
new file mode 100644 (file)
index 0000000..71d1978
--- /dev/null
@@ -0,0 +1,16 @@
+import os
+
+import testinfra.utils.ansible_runner
+
+testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
+    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
+
+
+def test_chartmuseum(host):
+    ansible_vars = host.ansible.get_variables()
+    p = host.process.get(comm="chartmuseum")
+    assert 'chartmuseum --storage local --storage-local-rootdir /opt/' +\
+           ansible_vars['app_name'] + '/chartmuseum -port ' +\
+           ansible_vars['chartmuseum_port'] in p.args
+    assert host.file("/opt/" + ansible_vars['app_name'] +
+           "/chartmuseum").is_directory
diff --git a/ansible/roles/chartmuseum/tasks/main.yml b/ansible/roles/chartmuseum/tasks/main.yml
new file mode 100644 (file)
index 0000000..d7121a5
--- /dev/null
@@ -0,0 +1,20 @@
+---
+- name: Install chartmuseum
+  copy:
+    src: "{{ app_data_path }}/downloads/chartmuseum"
+    dest: "{{ helm_bin_dir }}"
+    remote_src: true
+    mode: 0755
+
+- name: Create storage directory for chartmuseum
+  file:
+    path: "{{ chartmuseum_storage_dir }}"
+    state: directory
+
+- name: Run Helm chart repository
+  shell: "{{ helm_bin_dir }}/chartmuseum --storage local --storage-local-rootdir {{ chartmuseum_storage_dir }} -port {{ chartmuseum_port }} &"
+  async: 10
+  poll: 3
+  register: chart_repository
+  changed_when: "'address already in use' not in chart_repository.stderr"
+  failed_when: "'Starting ChartMuseum' not in chart_repository.stderr"
diff --git a/ansible/test/roles/prepare-chartmuseum/tasks/main.yml b/ansible/test/roles/prepare-chartmuseum/tasks/main.yml
new file mode 100644 (file)
index 0000000..b0bb5d1
--- /dev/null
@@ -0,0 +1,12 @@
+---
+- name: "Ensure {{ app_data_path }}/downloads directory exists"
+  file:
+    path: "{{ app_data_path }}/downloads"
+    recurse: true
+    state: directory
+
+- name: "Download chartmuseum"
+  get_url:
+    url: "https://s3.amazonaws.com/chartmuseum/release/latest/bin/linux/amd64/chartmuseum"
+    dest: "{{ app_data_path }}/downloads"
+    remote_src: true