stoobly-agent 1.6.7__py3-none-any.whl → 1.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
stoobly_agent/__init__.py CHANGED
@@ -1,2 +1,2 @@
1
1
  COMMAND = 'stoobly-agent'
2
- VERSION = '1.6.7'
2
+ VERSION = '1.7.0'
@@ -10,6 +10,7 @@ DOCKER_COMPOSE_CUSTOM = 'docker-compose.yml'
10
10
  DOCKER_COMPOSE_NETWORKS = '.docker-compose.networks.yml'
11
11
  DOCKERFILE_CONTEXT = '.Dockerfile.context'
12
12
  DOCKERFILE_SERVICE = 'Dockerfile.source'
13
+ GATEWAY_NGINX_TEMPLATE = 'nginx.tmpl'
13
14
 
14
15
  # TODO: add scaffold container name templates here
15
16
 
@@ -1,38 +1,25 @@
1
1
  import os
2
2
  import pdb
3
+ import shutil
3
4
  import yaml
4
5
 
5
6
  from typing import List
6
7
 
8
+ from stoobly_agent.config.data_dir import DATA_DIR_NAME, TMP_DIR_NAME
9
+ from stoobly_agent.app.cli.scaffold.constants import APP_DIR
7
10
  from stoobly_agent.app.cli.scaffold.service_config import ServiceConfig
8
- from stoobly_agent.app.cli.scaffold.docker.constants import DOCKER_COMPOSE_BASE, DOCKER_COMPOSE_BASE_TEMPLATE
11
+ from stoobly_agent.app.cli.scaffold.docker.constants import APP_INGRESS_NETWORK_NAME, APP_EGRESS_NETWORK_NAME, DOCKER_COMPOSE_BASE, DOCKER_COMPOSE_BASE_TEMPLATE, GATEWAY_NGINX_TEMPLATE
9
12
  from stoobly_agent.app.cli.scaffold.templates.constants import CORE_GATEWAY_SERVICE_NAME
13
+ from stoobly_agent.app.cli.scaffold.templates import run_template_path
10
14
 
11
15
  def configure_gateway(service_paths: List[str], no_publish = False):
12
16
  if len(service_paths) == 0:
13
17
  return
14
18
 
15
- ports = []
16
- hostnames = []
17
- for path in service_paths:
18
- config = ServiceConfig(path)
19
+ hostnames, ports = __find_hosts(service_paths)
19
20
 
20
- if not config.hostname:
21
- continue
22
-
23
- try:
24
- port = int(config.port)
25
- except Exception:
26
- continue
27
-
28
- port_mapping = f"{port}:{443 if config.scheme == 'https' else 80}"
29
- if port > 0 and port <= 65535 and port_mapping not in ports:
30
- ports.append(port_mapping)
31
-
32
- hostnames.append(config.hostname)
33
-
34
- app_dir_path = os.path.dirname(service_paths[0])
35
- gateway_service_path = os.path.join(app_dir_path, CORE_GATEWAY_SERVICE_NAME)
21
+ service_dir_path = os.path.dirname(service_paths[0])
22
+ gateway_service_path = os.path.join(service_dir_path, CORE_GATEWAY_SERVICE_NAME)
36
23
  docker_compose_src_path = os.path.join(gateway_service_path, DOCKER_COMPOSE_BASE_TEMPLATE)
37
24
  docker_compose_dest_path = os.path.join(gateway_service_path, DOCKER_COMPOSE_BASE)
38
25
 
@@ -50,12 +37,66 @@ def configure_gateway(service_paths: List[str], no_publish = False):
50
37
  if not no_publish:
51
38
  gateway_base['ports'] = ports
52
39
 
53
- gateway_base['networks'] = {
54
- 'app.egress': {},
55
- 'app.ingress': {
56
- 'aliases': hostnames
57
- }
58
- }
40
+ app_dir_path = os.path.dirname(os.path.dirname(service_dir_path))
41
+ __with_no_publish(gateway_base, app_dir_path)
42
+ __with_networks(gateway_base, hostnames)
59
43
 
60
44
  with open(docker_compose_dest_path, 'w') as fp:
61
- yaml.dump(compose, fp)
45
+ yaml.dump(compose, fp)
46
+
47
+ def __with_networks(config: dict, hostnames: List[str]):
48
+ networks = {}
49
+ config['networks'] = networks
50
+ networks[APP_EGRESS_NETWORK_NAME] = {}
51
+ networks[APP_INGRESS_NETWORK_NAME] = {
52
+ 'aliases': hostnames
53
+ }
54
+
55
+ def __with_no_publish(config: dict, app_dir_path: str):
56
+ if not config['volumes']:
57
+ config['volumes'] = []
58
+
59
+ # Copy nginx.tmpl to .stoobly/tmp
60
+ nginx_template_src_path = os.path.join(run_template_path(), GATEWAY_NGINX_TEMPLATE)
61
+ nginx_template_relative_path = os.path.join(DATA_DIR_NAME, TMP_DIR_NAME, GATEWAY_NGINX_TEMPLATE)
62
+ nginx_template_dest_path = os.path.join(app_dir_path, nginx_template_relative_path)
63
+
64
+ if not os.path.exists(os.path.dirname(nginx_template_dest_path)):
65
+ os.makedirs(os.path.dirname(nginx_template_dest_path), exist_ok=True)
66
+
67
+ shutil.copy(nginx_template_src_path, nginx_template_dest_path)
68
+
69
+ config['volumes'].append(
70
+ f"{os.path.join(APP_DIR, nginx_template_relative_path)}:/app/nginx.tmpl:ro"
71
+ )
72
+
73
+ environment = {}
74
+ if not config['environment']:
75
+ config['environment'] = environment
76
+ else:
77
+ environment = config['environment']
78
+
79
+ environment['HTTPS_METHOD'] = 'noredirect'
80
+
81
+ def __find_hosts(service_paths):
82
+ hostnames = []
83
+ ports = []
84
+ for path in service_paths:
85
+ config = ServiceConfig(path)
86
+
87
+ if not config.hostname:
88
+ continue
89
+
90
+ try:
91
+ port = int(config.port)
92
+ except Exception:
93
+ continue
94
+
95
+ port_mapping = f"{port}:{port}"
96
+ if port > 0 and port <= 65535 and port_mapping not in ports:
97
+ ports.append(port_mapping)
98
+
99
+ if config.hostname not in hostnames:
100
+ hostnames.append(config.hostname)
101
+
102
+ return hostnames, ports
@@ -0,0 +1,8 @@
1
+ import os
2
+ import pathlib
3
+
4
+ def __path():
5
+ return os.path.join(pathlib.Path(__file__).parent.resolve())
6
+
7
+ def run_template_path():
8
+ return os.path.join(__path(), 'run')
@@ -2,7 +2,7 @@ services:
2
2
  gateway_base:
3
3
  environment:
4
4
  TRUST_DOWNSTREAM_PROXY: true
5
- image: nginxproxy/nginx-proxy:1.5
5
+ image: nginxproxy/nginx-proxy:1.7
6
6
  profiles:
7
7
  - gateway_base
8
8
  volumes: