Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F56999505
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/_modules/paas_docker.py b/_modules/paas_docker.py
index 8e4fb59..64b14c6 100644
--- a/_modules/paas_docker.py
+++ b/_modules/paas_docker.py
@@ -1,148 +1,162 @@
# -*- 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
def list_images():
"""
A function to get the list of images used on a Docker engine.
Example:
salt docker-002 paas_docker.list_images
"""
images = __pillar__.get("docker_images", [])
# Workaround for a merge issue for lists:
# Salt Tower concatenates them, a set will dedup them.
return set(images)
def get_subnets():
"""
A function to get the Docker subnets list.
CLI Example:
salt * paas_docker.get_subnets
"""
try:
networks = __pillar__["docker_networks"]
except KeyError:
networks = {}
# Defined Docker subnet
subnets = [network["subnet"] for network in networks.values()]
# Default Docker subnet
subnets.append("172.17.0.0/16")
return subnets
def _get_containers():
try:
return __pillar__["docker_containers"]
except KeyError:
return {}
def list_containers():
"""
A function to list all the containers provisionned on a Docker engine.
This function uses the pillar docker_containers as authoritative source,
so it documents the expected configuration, not the actual containers
running. That allows to compare both states.
CLI Example:
salt * paas_docker.list_containers
"""
return [
key
for service, service_containers in _get_containers().items()
for key in service_containers.keys()
]
+# -------------------------------------------------------------
+# Docker configuration
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def build_daemon_config():
+ network = __salt__["node.resolve_network"]()
+
+ config = __pillar__.get("docker_daemon", {})
+ config["metrics-addr"] = network["private_ipv4_address"] + ":9323"
+
+ return config
+
+
# -------------------------------------------------------------
# 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
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def _get_health_check_url(check_type, container, url):
if check_type[-6:] == "_proxy":
return f"https://{container['host']}{url}"
return f"http://localhost:{container['app_port']}{url}"
def get_health_checks():
"""
A function to get a dictionary with health checks
for known containers to use with our monitoring.
CLI Example:
salt * paas_docker.get_health_checks
"""
containers = _get_containers()
monitoring = __pillar__["docker_containers_monitoring"]
return {
check_type: {
instance: _get_health_check_url(check_type, container, url)
for service, url in monitoring[check_type].items()
for instance, container in containers.get(service, {}).items()
}
for check_type in monitoring.keys()
}
# -------------------------------------------------------------
# Format
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def format_env_list(values, separator=",", assign_op="-"):
return separator.join([f"{k}{assign_op}{v}" for k, v in values.items()])
diff --git a/roles/paas-docker/docker/config.sls b/roles/paas-docker/docker/config.sls
index a02d8c1..954cef3 100644
--- a/roles/paas-docker/docker/config.sls
+++ b/roles/paas-docker/docker/config.sls
@@ -1,25 +1,23 @@
# -------------------------------------------------------------
# Salt — Provision Docker engine
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Created: 2018-09-18
# License: Trivial work, not eligible to copyright
# -------------------------------------------------------------
{% from "map.jinja" import dirs with context %}
# -------------------------------------------------------------
# Configure Docker engine
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-{% set daemon = pillar['docker_daemon'] %}
+{% set daemon = salt["paas_docker.build_daemon_config"]() %}
-{% if daemon %}
{{ dirs.etc }}/docker/daemon.json:
file.managed:
- source: salt://roles/paas-docker/docker/files/daemon.json.jinja
- template: jinja
- mode: 644
- context:
daemon: {{ daemon }}
-{% endif %}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Nov 14, 19:18 (4 d, 19 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4246744
Default Alt Text
(5 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment