Page MenuHomeDevCentral

D2968.id7570.diff
No OneTemporary

D2968.id7570.diff

diff --git a/_modules/paas_docker.py b/_modules/paas_docker.py
--- a/_modules/paas_docker.py
+++ b/_modules/paas_docker.py
@@ -91,6 +91,20 @@
]
+# -------------------------------------------------------------
+# Nginx
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def resolve_vhost_config_file(service, dir="roles/paas-docker/nginx/files/vhosts"):
+ candidate = f"{dir}/{service}.conf"
+
+ if __salt__["slsutil.file_exists"](candidate):
+ return candidate
+
+ return f"{dir}/_default.conf"
+
+
# -------------------------------------------------------------
# Monitoring
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/_tests/data/empty.conf b/_tests/data/empty.conf
new file mode 100644
diff --git a/_tests/modules/test_paas_docker.py b/_tests/modules/test_paas_docker.py
--- a/_tests/modules/test_paas_docker.py
+++ b/_tests/modules/test_paas_docker.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
from importlib.machinery import SourceFileLoader
+import os
import unittest
salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
@@ -17,6 +18,9 @@
self.mock_grains()
self.grains["id"] = "egladil"
+ self.mock_salt()
+ self.salt["slsutil.file_exists"] = lambda file: os.path.exists(file)
+
def test_get_image(self):
container = {"image": "foo", "version": "42"}
@@ -47,6 +51,16 @@
self.assertEqual("foo:2.5", docker.get_image("not_foo", container))
+ def test_resolve_vhost_config_file(self):
+ config_file = docker.resolve_vhost_config_file("empty", dir="data")
+
+ self.assertEqual("data/empty.conf", config_file)
+
+ def test_resolve_vhost_config_file_when_not_existing(self):
+ config_file = docker.resolve_vhost_config_file("foo", dir="notexisting")
+
+ self.assertEqual("notexisting/_default.conf", config_file)
+
def test_get_subnets(self):
expected = ["172.18.1.0/24", "172.18.2.0/24", "172.17.0.0/16"]
diff --git a/roles/paas-docker/nginx/config.sls b/roles/paas-docker/nginx/config.sls
--- a/roles/paas-docker/nginx/config.sls
+++ b/roles/paas-docker/nginx/config.sls
@@ -66,9 +66,11 @@
{% for instance, container in instances.items() %}
{% if 'host' in container %}
+{% set vhost_config = salt["paas_docker.resolve_vhost_config_file"](service) %}
+
{{ dirs.etc }}/nginx/vhosts/{{ service }}/{{ instance }}.conf:
file.managed:
- - source: salt://roles/paas-docker/nginx/files/vhosts/{{ service }}.conf
+ - source: salt://{{ vhost_config }}
- mode: 644
- makedirs: True
- template: jinja
diff --git a/roles/paas-docker/nginx/files/vhosts/hound.conf b/roles/paas-docker/nginx/files/vhosts/hound.conf
deleted file mode 100644
--- a/roles/paas-docker/nginx/files/vhosts/hound.conf
+++ /dev/null
@@ -1 +0,0 @@
-{% include 'roles/paas-docker/nginx/files/vhosts/_default.conf' %}

File Metadata

Mime Type
text/plain
Expires
Tue, Oct 1, 08:20 (19 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2168062
Default Alt Text
D2968.id7570.diff (2 KB)

Event Timeline