From 7dd4f790f40fbdb2b27c12b92e8188d06e774fc9 Mon Sep 17 00:00:00 2001 From: Lissandre Date: Sat, 21 Sep 2019 21:31:00 +0200 Subject: [PATCH] Add traefik version choice (#10) * Add traefik version choice * Update to set traefik 1.7 by default --- stakkr/actions.py | 2 +- stakkr/proxy.py | 7 ++++--- stakkr/static/config_default.yml | 1 + stakkr/static/config_schema.yml | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/stakkr/actions.py b/stakkr/actions.py index 4b8de55..5866f22 100644 --- a/stakkr/actions.py +++ b/stakkr/actions.py @@ -130,7 +130,7 @@ def start(self, container: str, pull: bool, recreate: bool, proxy: bool): self._run_iptables_rules(cts) if proxy is True: conf = self.config['proxy'] - Proxy(conf.get('http_port'), conf.get('https_port')).start( + Proxy(conf.get('http_port'), conf.get('https_port'), version=conf.get('version')).start( docker.get_network_name(self.project_name)) def status(self): diff --git a/stakkr/proxy.py b/stakkr/proxy.py index ccb9c14..944e495 100644 --- a/stakkr/proxy.py +++ b/stakkr/proxy.py @@ -10,11 +10,12 @@ class Proxy: """Main class that does actions asked by the cli.""" - def __init__(self, http_port: int = 80, https_port: int = 443, ct_name: str = 'proxy_stakkr'): + def __init__(self, http_port: int = 80, https_port: int = 443, ct_name: str = 'proxy_stakkr', version: str = 'latest'): """Set the right values to start the proxy.""" self.ports = {'http': http_port, 'https': https_port} self.ct_name = ct_name self.docker_client = docker.get_client() + self.version = version def start(self, stakkr_network: str = None): """Start stakkr proxy if stopped.""" @@ -39,9 +40,9 @@ def _start_container(self): """Start proxy.""" proxy_conf_dir = get_dir('static/proxy') try: - self.docker_client.images.pull('traefik:latest') + self.docker_client.images.pull('traefik:{}'.format(self.version)) self.docker_client.containers.run( - 'traefik:latest', remove=True, detach=True, + 'traefik:{}'.format(self.version), remove=True, detach=True, hostname=self.ct_name, name=self.ct_name, volumes=[ '/var/run/docker.sock:/var/run/docker.sock', diff --git a/stakkr/static/config_default.yml b/stakkr/static/config_default.yml index 8506782..a3088be 100644 --- a/stakkr/static/config_default.yml +++ b/stakkr/static/config_default.yml @@ -17,6 +17,7 @@ proxy: domain: localhost http_port: 80 https_port: 443 + version: 1.7.0 project_name: '' diff --git a/stakkr/static/config_schema.yml b/stakkr/static/config_schema.yml index 5a2e7b1..31d5a62 100644 --- a/stakkr/static/config_schema.yml +++ b/stakkr/static/config_schema.yml @@ -60,7 +60,8 @@ properties: domain: { type: string } http_port: { type: integer } https_port: { type: integer } - required: [enabled, domain, http_port, https_port] + version: { type: [string, number] } + required: [enabled, domain, http_port, https_port, version] project_name: type: string