summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2021-01-26 15:30:12 +0100
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>2021-01-26 15:30:12 +0100
commit283ecef8914e6397b4a8b88e4a31b2908d4aa078 (patch)
tree7e3556d0ee37a8e61569d047a4bae8cdef5b6302
parent8b2864df4f19783062f3a460227994032d923ff4 (diff)
Add 'chartmuseum' role
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>
-rw-r--r--ansible/roles/chartmuseum/.yamllint11
-rw-r--r--ansible/roles/chartmuseum/defaults/main.yml3
-rw-r--r--ansible/roles/chartmuseum/molecule/default/Dockerfile.j214
-rw-r--r--ansible/roles/chartmuseum/molecule/default/molecule.yml33
-rw-r--r--ansible/roles/chartmuseum/molecule/default/playbook.yml5
-rw-r--r--ansible/roles/chartmuseum/molecule/default/prepare.yml5
-rw-r--r--ansible/roles/chartmuseum/molecule/default/tests/test_default.py16
-rw-r--r--ansible/roles/chartmuseum/tasks/main.yml20
-rw-r--r--ansible/test/roles/prepare-chartmuseum/tasks/main.yml12
9 files changed, 119 insertions, 0 deletions
diff --git a/ansible/roles/chartmuseum/.yamllint b/ansible/roles/chartmuseum/.yamllint
new file mode 100644
index 00000000..ad0be760
--- /dev/null
+++ b/ansible/roles/chartmuseum/.yamllint
@@ -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
index 00000000..6816d151
--- /dev/null
+++ b/ansible/roles/chartmuseum/defaults/main.yml
@@ -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
index 00000000..e6aa95d3
--- /dev/null
+++ b/ansible/roles/chartmuseum/molecule/default/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/ansible/roles/chartmuseum/molecule/default/molecule.yml b/ansible/roles/chartmuseum/molecule/default/molecule.yml
new file mode 100644
index 00000000..07652b7a
--- /dev/null
+++ b/ansible/roles/chartmuseum/molecule/default/molecule.yml
@@ -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
index 00000000..2694582a
--- /dev/null
+++ b/ansible/roles/chartmuseum/molecule/default/playbook.yml
@@ -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
index 00000000..5201bcec
--- /dev/null
+++ b/ansible/roles/chartmuseum/molecule/default/prepare.yml
@@ -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
index 00000000..71d1978d
--- /dev/null
+++ b/ansible/roles/chartmuseum/molecule/default/tests/test_default.py
@@ -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
index 00000000..d7121a53
--- /dev/null
+++ b/ansible/roles/chartmuseum/tasks/main.yml
@@ -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
index 00000000..b0bb5d11
--- /dev/null
+++ b/ansible/test/roles/prepare-chartmuseum/tasks/main.yml
@@ -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