Page MenuHomeDevCentral

D1855.diff
No OneTemporary

D1855.diff

diff --git a/_modules/paas_docker.py b/_modules/paas_docker.py
new file mode 100644
--- /dev/null
+++ b/_modules/paas_docker.py
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+
+# -------------------------------------------------------------
+# Salt — PaaS Docker execution module
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Created: 2018-10-07
+# Description: Functions related to data format conversions
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+
+def get_image(default_image, args):
+ """
+ A function to output a pillar key in JSON.
+
+ State Example::
+
+ {% image = salt['paas_docker.get_image']("nasqueron/mysql", container) %}
+ """
+ image = default_image
+
+ if 'image' in args:
+ image = args['image']
+
+ if 'version' in args:
+ image += ":" + str(args['version'])
+
+ return image
diff --git a/_tests/modules/test_paas_docker.py b/_tests/modules/test_paas_docker.py
new file mode 100644
--- /dev/null
+++ b/_tests/modules/test_paas_docker.py
@@ -0,0 +1,41 @@
+from importlib.machinery import SourceFileLoader
+import unittest
+
+salt_test_case = SourceFileLoader('salt_test_case', "salt_test_case.py").load_module()
+docker = SourceFileLoader('docker', '../_modules/paas_docker.py').load_module()
+
+
+class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
+
+ def test_get_image(self):
+ container = {
+ "image": "foo",
+ "version": "42"
+ }
+
+ self.assertEqual("foo:42", docker.get_image("not_foo", container))
+
+ def test_get_image_without_version(self):
+ container = {
+ "image": "foo",
+ }
+
+ self.assertEqual("foo", docker.get_image("not_foo", container))
+
+ def test_get_image_without_image(self):
+ container = {
+ "version": "42"
+ }
+
+ self.assertEqual("not_foo:42", docker.get_image("not_foo", container))
+
+ def test_get_image_without_anything(self):
+ self.assertEqual("not_foo", docker.get_image("not_foo", {}))
+
+ def test_get_image_with_numeric_version(self):
+ container = {
+ "image": "foo",
+ "version": 2.5
+ }
+
+ self.assertEqual("foo:2.5", docker.get_image("not_foo", container))
diff --git a/pillar/paas/docker.sls b/pillar/paas/docker.sls
--- a/pillar/paas/docker.sls
+++ b/pillar/paas/docker.sls
@@ -24,6 +24,7 @@
dwellers:
# Core services
+ - nasqueron/mysql:5.7
- nasqueron/rabbitmq
# Infrastructure and development services
@@ -114,9 +115,16 @@
#
# Dwellers is the engine for Mastodon and CI intelligent bus services
#
-
dwellers:
- {}
+
+ #
+ # Core services
+ #
+
+ mysql:
+ bugzilla_db:
+ network: bugzilla
+ version: 5.7
#
# Equatower is the current production engine
diff --git a/roles/paas-docker/containers/mysql.sls b/roles/paas-docker/containers/mysql.sls
--- a/roles/paas-docker/containers/mysql.sls
+++ b/roles/paas-docker/containers/mysql.sls
@@ -9,7 +9,8 @@
{% set has_selinux = salt['grains.get']('selinux:enabled', False) %}
{% set containers = pillar['docker_containers'][grains['id']] %}
-{% for instance in containers['mysql'] %}
+{% for instance, container in containers['mysql'].items() %}
+{% set image = salt['paas_docker.get_image']("nasqueron/mysql", container) %}
# -------------------------------------------------------------
# Home directory
@@ -40,9 +41,12 @@
docker_container.running:
- detach: True
- interactive: True
- - image: nasqueron/mysql
+ - image: {{ image }}
- binds: /srv/{{ instance }}/mysql:/var/lib/mysql
- environment:
MYSQL_ROOT_PASSWORD: {{ salt['random.get_str'](31) }}
-
+{% if 'network' in container %}
+ - networks:
+ - {{ container['network'] }}
+{% endif %}
{% endfor %}

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 27, 12:20 (7 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2316905
Default Alt Text
D1855.diff (3 KB)

Event Timeline