stoobly-agent 1.6.6__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.
Files changed (48) hide show
  1. stoobly_agent/__init__.py +1 -1
  2. stoobly_agent/app/cli/scaffold/constants.py +1 -0
  3. stoobly_agent/app/cli/scaffold/docker/constants.py +1 -0
  4. stoobly_agent/app/cli/scaffold/docker/service/builder.py +98 -13
  5. stoobly_agent/app/cli/scaffold/docker/service/configure_gateway.py +69 -28
  6. stoobly_agent/app/cli/scaffold/docker/workflow/builder.py +12 -60
  7. stoobly_agent/app/cli/scaffold/service_create_command.py +1 -1
  8. stoobly_agent/app/cli/scaffold/templates/__init__.py +8 -0
  9. stoobly_agent/app/cli/scaffold/templates/app/build/.docker-compose.base.yml +4 -2
  10. stoobly_agent/app/cli/scaffold/templates/app/build/mock/.docker-compose.mock.yml +2 -2
  11. stoobly_agent/app/cli/scaffold/templates/app/build/mock/docker-compose.yml +7 -0
  12. stoobly_agent/app/cli/scaffold/templates/app/build/record/.docker-compose.record.yml +2 -2
  13. stoobly_agent/app/cli/scaffold/templates/app/build/record/docker-compose.yml +7 -0
  14. stoobly_agent/app/cli/scaffold/templates/app/build/test/.docker-compose.test.yml +2 -2
  15. stoobly_agent/app/cli/scaffold/templates/app/build/test/docker-compose.yml +7 -0
  16. stoobly_agent/app/cli/scaffold/templates/app/entrypoint/.docker-compose.base.yml +4 -5
  17. stoobly_agent/app/cli/scaffold/templates/app/entrypoint/mock/.docker-compose.mock.yml +2 -8
  18. stoobly_agent/app/cli/scaffold/templates/app/entrypoint/mock/docker-compose.yml +4 -11
  19. stoobly_agent/app/cli/scaffold/templates/app/entrypoint/record/.docker-compose.record.yml +2 -8
  20. stoobly_agent/app/cli/scaffold/templates/app/entrypoint/record/docker-compose.yml +3 -6
  21. stoobly_agent/app/cli/scaffold/templates/app/entrypoint/test/.docker-compose.test.yml +2 -8
  22. stoobly_agent/app/cli/scaffold/templates/app/entrypoint/test/docker-compose.yml +3 -6
  23. stoobly_agent/app/cli/scaffold/templates/app/gateway/.docker-compose.base.template.yml +1 -1
  24. stoobly_agent/app/cli/scaffold/templates/build/services/build/mock/.init +1 -1
  25. stoobly_agent/app/cli/scaffold/templates/build/services/build/record/.init +1 -1
  26. stoobly_agent/app/cli/scaffold/templates/build/services/build/test/.init +1 -1
  27. stoobly_agent/app/cli/scaffold/templates/build/services/entrypoint/mock/.init +1 -1
  28. stoobly_agent/app/cli/scaffold/templates/build/services/entrypoint/record/.init +1 -1
  29. stoobly_agent/app/cli/scaffold/templates/build/services/entrypoint/test/.init +1 -1
  30. stoobly_agent/app/cli/scaffold/templates/build/workflows/mock/.init +1 -1
  31. stoobly_agent/app/cli/scaffold/templates/build/workflows/record/.init +1 -1
  32. stoobly_agent/app/cli/scaffold/templates/build/workflows/test/.init +1 -1
  33. stoobly_agent/app/cli/scaffold/templates/run/nginx.tmpl +1060 -0
  34. stoobly_agent/app/cli/scaffold/templates/workflow/mock/bin/configure +2 -2
  35. stoobly_agent/app/cli/scaffold/templates/workflow/mock/bin/init +3 -1
  36. stoobly_agent/app/cli/scaffold/templates/workflow/record/bin/configure +4 -4
  37. stoobly_agent/app/cli/scaffold/templates/workflow/record/bin/init +3 -1
  38. stoobly_agent/app/cli/scaffold/templates/workflow/test/bin/configure +2 -2
  39. stoobly_agent/app/cli/scaffold/templates/workflow/test/bin/init +3 -1
  40. stoobly_agent/app/cli/scaffold/workflow_create_command.py +4 -2
  41. stoobly_agent/app/cli/scaffold_cli.py +2 -2
  42. stoobly_agent/config/data_dir.py +5 -4
  43. stoobly_agent/test/app/models/schemas/.stoobly/db/VERSION +1 -1
  44. {stoobly_agent-1.6.6.dist-info → stoobly_agent-1.7.0.dist-info}/METADATA +1 -1
  45. {stoobly_agent-1.6.6.dist-info → stoobly_agent-1.7.0.dist-info}/RECORD +48 -44
  46. {stoobly_agent-1.6.6.dist-info → stoobly_agent-1.7.0.dist-info}/WHEEL +1 -1
  47. {stoobly_agent-1.6.6.dist-info → stoobly_agent-1.7.0.dist-info}/LICENSE +0 -0
  48. {stoobly_agent-1.6.6.dist-info → stoobly_agent-1.7.0.dist-info}/entry_points.txt +0 -0
stoobly_agent/__init__.py CHANGED
@@ -1,2 +1,2 @@
1
1
  COMMAND = 'stoobly-agent'
2
- VERSION = '1.6.6'
2
+ VERSION = '1.7.0'
@@ -4,6 +4,7 @@ from typing import Literal
4
4
 
5
5
  from stoobly_agent.config.data_dir import CERTS_DIR_NAME, DATA_DIR_NAME
6
6
 
7
+ APP_DIR = '${APP_DIR}'
7
8
  APP_DIR_ENV = 'APP_DIR'
8
9
  APP_NETWORK_ENV = 'APP_NETWORK'
9
10
  APP_NAME_ENV = 'APP_NAME'
@@ -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,8 +1,17 @@
1
1
  import os
2
2
  import pdb
3
3
 
4
+ from typing import List
5
+
6
+ from stoobly_agent.config.data_dir import DATA_DIR_NAME
7
+
4
8
  from ...app_config import AppConfig
5
- from ...constants import WORKFLOW_SCRIPTS, WORKFLOW_TEMPLATE
9
+ from ...constants import (
10
+ APP_DIR, DOCKER_NAMESPACE, SERVICE_NAME, SERVICE_NAME_ENV,
11
+ SERVICE_HOSTNAME, SERVICE_HOSTNAME_ENV, SERVICE_NAME_ENV, SERVICE_PORT, SERVICE_PORT_ENV, SERVICE_SCHEME, SERVICE_SCHEME_ENV,
12
+ STOOBLY_HOME_DIR, STOOBLY_HOME_DIR,
13
+ WORKFLOW_NAME, WORKFLOW_NAME_ENV, WORKFLOW_SCRIPTS, WORKFLOW_TEMPLATE
14
+ )
6
15
  from ...service_config import ServiceConfig
7
16
  from ..app_builder import AppBuilder
8
17
  from ..builder import Builder
@@ -20,16 +29,16 @@ class ServiceBuilder(Builder):
20
29
  self.app_builder = app_builder
21
30
 
22
31
  self.__config = config
32
+ self.__env = [SERVICE_NAME_ENV, WORKFLOW_NAME_ENV]
23
33
  self.__service_name = os.path.basename(service_path)
34
+ self.__working_dir = os.path.join(
35
+ STOOBLY_HOME_DIR, DATA_DIR_NAME, DOCKER_NAMESPACE, SERVICE_NAME, WORKFLOW_NAME
36
+ )
24
37
 
25
38
  @property
26
39
  def app_base(self):
27
40
  return f"{self.service_name}.app_base"
28
41
 
29
- @property
30
- def init_base(self):
31
- return f"{self.service_name}.init_base"
32
-
33
42
  @property
34
43
  def config(self):
35
44
  return self.__config
@@ -49,6 +58,14 @@ class ServiceBuilder(Builder):
49
58
  else:
50
59
  return self.app_builder.context_base
51
60
 
61
+ @property
62
+ def init_base(self):
63
+ return f"{self.service_name}.init_base"
64
+
65
+ @property
66
+ def init_base_service(self):
67
+ return self.services.get(self.init_base)
68
+
52
69
  @property
53
70
  def proxy_base(self):
54
71
  return f"{self.service_name}.proxy_base"
@@ -74,15 +91,45 @@ class ServiceBuilder(Builder):
74
91
  if not self.config.hostname:
75
92
  return
76
93
 
77
- self.with_service(self.proxy_base, {
94
+ environment = { **self.env_dict() }
95
+ volumes = []
96
+
97
+ environment['VIRTUAL_HOST'] = SERVICE_HOSTNAME
98
+ environment['VIRTUAL_PORT'] = SERVICE_PORT
99
+ environment['VIRTUAL_PROTO'] = SERVICE_SCHEME
100
+
101
+ if self.config.detached:
102
+ volumes.append(f"{self.service_name}:{STOOBLY_HOME_DIR}/{DATA_DIR_NAME}")
103
+ volumes.append(f"../..:{STOOBLY_HOME_DIR}/{DATA_DIR_NAME}/{DOCKER_NAMESPACE}")
104
+
105
+ base = {
106
+ 'environment': environment,
78
107
  'extends': {
79
108
  'file': os.path.relpath(self.app_builder.compose_file_path, self.dir_path),
80
109
  'service': self.extends_service
81
110
  },
82
- })
111
+ 'working_dir': self.__working_dir,
112
+ }
113
+
114
+ if len(volumes):
115
+ base['volumes'] = volumes
116
+
117
+ self.with_service(self.proxy_base, base)
83
118
 
84
119
  def build_init_base(self):
85
- environment = {}
120
+ environment = { **self.env_dict() }
121
+ volumes = [f"{APP_DIR}:/app"]
122
+
123
+ if self.config.hostname:
124
+ self.__with_url_environment(environment)
125
+
126
+ if self.config.detached:
127
+ # Mount named volume
128
+ volumes.append(f"{self.service_name}:{STOOBLY_HOME_DIR}/{DATA_DIR_NAME}")
129
+
130
+ # Mount docker folder
131
+ volumes.append(f"../..:{STOOBLY_HOME_DIR}/{DATA_DIR_NAME}/{DOCKER_NAMESPACE}")
132
+
86
133
  self.with_service(self.init_base, {
87
134
  'command': [f"{WORKFLOW_SCRIPTS}/{WORKFLOW_TEMPLATE}/.init", 'bin/init'],
88
135
  'environment': environment,
@@ -90,18 +137,47 @@ class ServiceBuilder(Builder):
90
137
  'file': os.path.relpath(self.app_builder.compose_file_path, self.dir_path),
91
138
  'service': self.extends_service
92
139
  },
140
+ 'volumes': volumes,
141
+ 'working_dir': self.__working_dir,
93
142
  })
94
143
 
95
144
  def build_configure_base(self):
96
- environment = {}
97
- self.with_service(self.configure_base, {
145
+ environment = { **self.env_dict() }
146
+ volumes = []
147
+
148
+ if self.config.hostname:
149
+ self.__with_url_environment(environment)
150
+
151
+ if self.config.detached:
152
+ volumes.append(f"{self.service_name}:{STOOBLY_HOME_DIR}/${DATA_DIR_NAME}")
153
+ volumes.append(f"../..:{STOOBLY_HOME_DIR}/{DATA_DIR_NAME}/{DOCKER_NAMESPACE}")
154
+
155
+ base = {
98
156
  'command': [f"{WORKFLOW_SCRIPTS}/{WORKFLOW_TEMPLATE}/.configure", 'bin/configure'],
99
157
  'environment': environment,
100
158
  'extends': {
101
159
  'file': os.path.relpath(self.app_builder.compose_file_path, self.dir_path),
102
160
  'service': self.extends_service
103
- }
104
- })
161
+ },
162
+ 'working_dir': self.__working_dir,
163
+ }
164
+
165
+ if len(volumes):
166
+ base['volumes'] = volumes
167
+
168
+ self.with_service(self.configure_base, base)
169
+
170
+ def env_dict(self):
171
+ env = {}
172
+ for e in self.__env:
173
+ env[e] = '${' + e + '}'
174
+ return env
175
+
176
+ def with_env(self, v: List[str]):
177
+ if not isinstance(v, list):
178
+ return self
179
+ self.__env += v
180
+ return self
105
181
 
106
182
  def write(self):
107
183
  self.build_init_base()
@@ -117,4 +193,13 @@ class ServiceBuilder(Builder):
117
193
  if self.networks:
118
194
  compose['networks'] = self.networks
119
195
 
120
- super().write(compose)
196
+ super().write(compose)
197
+
198
+ def __with_url_environment(self, environment):
199
+ environment[SERVICE_HOSTNAME_ENV] = SERVICE_HOSTNAME
200
+
201
+ if self.config.scheme:
202
+ environment[SERVICE_SCHEME_ENV] = SERVICE_SCHEME
203
+
204
+ if self.config.port:
205
+ environment[SERVICE_PORT_ENV] = SERVICE_PORT
@@ -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
@@ -1,14 +1,10 @@
1
1
  import os
2
2
  import pdb
3
3
 
4
- from typing import List
5
-
6
- from stoobly_agent.config.data_dir import DATA_DIR_NAME
7
-
8
4
  from ...constants import (
9
- COMPOSE_TEMPLATE, DOCKER_NAMESPACE, STOOBLY_HOME_DIR, SERVICE_HOSTNAME, SERVICE_HOSTNAME_ENV, SERVICE_NAME_ENV,
10
- SERVICE_PORT, SERVICE_PORT_ENV, SERVICE_SCHEME, SERVICE_SCHEME_ENV,
11
- WORKFLOW_CONTAINER_CONFIGURE_TEMPLATE, WORKFLOW_CONTAINER_INIT_TEMPLATE, WORKFLOW_CONTAINER_PROXY_TEMPLATE, WORKFLOW_NAME_ENV
5
+ COMPOSE_TEMPLATE, SERVICE_HOSTNAME,
6
+ SERVICE_HOSTNAME_ENV, SERVICE_NAME_ENV, SERVICE_PORT, SERVICE_PORT_ENV, SERVICE_SCHEME, SERVICE_SCHEME_ENV,
7
+ WORKFLOW_CONTAINER_CONFIGURE_TEMPLATE, WORKFLOW_CONTAINER_INIT_TEMPLATE, WORKFLOW_CONTAINER_PROXY_TEMPLATE, WORKFLOW_NAME, WORKFLOW_NAME_ENV
12
8
  )
13
9
  from ..builder import Builder
14
10
  from ..service.builder import ServiceBuilder
@@ -21,16 +17,13 @@ class WorkflowBuilder(Builder):
21
17
  super().__init__(workflow_path, COMPOSE_TEMPLATE.format(workflow=self.__workflow_name))
22
18
 
23
19
  self.__context = '../'
24
- self.__profiles = [self.__workflow_name]
20
+ self.__profiles = [WORKFLOW_NAME]
25
21
 
26
22
  if not service_builder:
27
23
  service_path = os.path.dirname(workflow_path)
28
24
  service_builder = ServiceBuilder(service_path)
29
25
 
30
26
  self.__service_builder = service_builder
31
- self.__working_dir = os.path.join(
32
- STOOBLY_HOME_DIR, DATA_DIR_NAME, DOCKER_NAMESPACE, self.service_builder.service_name, self.workflow_name
33
- )
34
27
 
35
28
  @property
36
29
  def app(self):
@@ -40,10 +33,6 @@ class WorkflowBuilder(Builder):
40
33
  def base_compose_file_path(self):
41
34
  return os.path.relpath(self.service_builder.compose_file_path, self.dir_path)
42
35
 
43
- @property
44
- def init(self):
45
- return WORKFLOW_CONTAINER_INIT_TEMPLATE.format(service_name=self.namespace)
46
-
47
36
  @property
48
37
  def config(self):
49
38
  return self.service_builder.config
@@ -60,6 +49,10 @@ class WorkflowBuilder(Builder):
60
49
  def context_docker_file_path(self):
61
50
  return os.path.relpath(self.service_builder.app_builder.context_docker_file_path, self.service_path)
62
51
 
52
+ @property
53
+ def init(self):
54
+ return WORKFLOW_CONTAINER_INIT_TEMPLATE.format(service_name=self.namespace)
55
+
63
56
  @property
64
57
  def namespace(self):
65
58
  return f"{self.service_builder.service_name}"
@@ -97,26 +90,16 @@ class WorkflowBuilder(Builder):
97
90
  self.build_proxy() # Depends on configure, must call build_configure first
98
91
 
99
92
  def build_init(self):
100
- environment = { **self.env_dict() }
101
- volumes = []
93
+ # If the init_base service does not exist, we can't extend from it, return
94
+ if not self.service_builder.init_base_service:
95
+ return
102
96
 
97
+ return
103
98
  service = {
104
- 'environment': environment,
105
99
  'extends': self.service_builder.build_extends_init_base(self.dir_path),
106
100
  'profiles': self.profiles,
107
- 'volumes': volumes,
108
- 'working_dir': self.__working_dir,
109
101
  }
110
102
 
111
- if self.config.hostname:
112
- self.__with_url_environment(environment)
113
-
114
- if self.config.detached:
115
- # Mount named volume
116
- volumes.append(f"{self.service_builder.service_name}:{STOOBLY_HOME_DIR}/.stoobly")
117
- # Mount docker folder
118
- volumes.append(f"../..:{STOOBLY_HOME_DIR}/.stoobly/docker")
119
-
120
103
  self.with_service(self.init, service)
121
104
 
122
105
  def build_configure(self):
@@ -125,30 +108,18 @@ class WorkflowBuilder(Builder):
125
108
  return
126
109
 
127
110
  depends_on = {}
128
- environment = { **self.env_dict() }
129
- volumes = []
130
111
 
131
112
  service = {
132
113
  'depends_on': depends_on,
133
- 'environment': environment,
134
114
  'extends': self.service_builder.build_extends_configure_base(self.dir_path),
135
115
  'profiles': self.profiles,
136
- 'volumes': volumes,
137
- 'working_dir': self.__working_dir,
138
116
  }
139
117
 
140
- if self.config.hostname:
141
- self.__with_url_environment(environment)
142
-
143
118
  if self.init in self.services:
144
119
  depends_on[self.init] = {
145
120
  'condition': 'service_completed_successfully',
146
121
  }
147
122
 
148
- if self.config.detached:
149
- volumes.append(f"{self.service_builder.service_name}:{STOOBLY_HOME_DIR}/.stoobly")
150
- volumes.append(f"../..:{STOOBLY_HOME_DIR}/.stoobly/docker")
151
-
152
123
  self.with_service(self.configure, service)
153
124
 
154
125
  def build_proxy(self):
@@ -157,18 +128,13 @@ class WorkflowBuilder(Builder):
157
128
  return
158
129
 
159
130
  depends_on = {}
160
- environment = { **self.env_dict() }
161
131
  networks = {}
162
- volumes = []
163
132
 
164
133
  service = {
165
134
  'depends_on': depends_on,
166
- 'environment': environment,
167
135
  'extends': self.service_builder.build_extends_proxy_base(self.dir_path),
168
136
  'networks': networks,
169
137
  'profiles': self.profiles,
170
- 'volumes': volumes,
171
- 'working_dir': self.__working_dir,
172
138
  }
173
139
 
174
140
  if self.configure in self.services:
@@ -180,18 +146,10 @@ class WorkflowBuilder(Builder):
180
146
  'condition': 'service_completed_successfully',
181
147
  }
182
148
 
183
- environment['VIRTUAL_HOST'] = SERVICE_HOSTNAME
184
- environment['VIRTUAL_PORT'] = SERVICE_PORT
185
- environment['VIRTUAL_PROTO'] = SERVICE_SCHEME
186
-
187
149
  # Expose this container service to the public network
188
150
  # so that it is accessible to other Stoobly services
189
151
  networks[self.egress_network_name] = {}
190
152
 
191
- if self.config.detached:
192
- volumes.append(f"{self.service_builder.service_name}:{STOOBLY_HOME_DIR}/.stoobly")
193
- volumes.append(f"../..:{STOOBLY_HOME_DIR}/.stoobly/docker")
194
-
195
153
  self.with_service(self.proxy, service)
196
154
 
197
155
  def env_dict(self):
@@ -213,12 +171,6 @@ class WorkflowBuilder(Builder):
213
171
 
214
172
  super().write(compose, dest)
215
173
 
216
- def with_env(self, v: List[str]):
217
- if not isinstance(v, list):
218
- return self
219
- self._env += v
220
- return self
221
-
222
174
  def write(self):
223
175
  compose = {
224
176
  'services': self.services,
@@ -27,6 +27,7 @@ class ServiceCreateCommand(ServiceCommand):
27
27
 
28
28
  def build(self):
29
29
  service_builder = ServiceBuilder(self.service_config)
30
+ service_builder.with_env(list(self.env_vars))
30
31
  service_decorators = []
31
32
 
32
33
  for service_decorator in service_decorators:
@@ -36,7 +37,6 @@ class ServiceCreateCommand(ServiceCommand):
36
37
 
37
38
  workflow_kwargs = {
38
39
  'app_dir_path': self.app_dir_path,
39
- 'env': self.env_vars,
40
40
  'namespace': self.namespace,
41
41
  'service_name': self.service_name,
42
42
  }
@@ -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')
@@ -6,7 +6,7 @@ services:
6
6
  extends:
7
7
  file: ../.docker-compose.base.yml
8
8
  service: context_base
9
- working_dir: /home/stoobly/.stoobly/docker/build/${WORKFLOW_NAME}
9
+ working_dir: /home/stoobly/.stoobly/docker/${SERVICE_NAME}/${WORKFLOW_NAME}
10
10
  build.init_base:
11
11
  command:
12
12
  - ${SERVICE_SCRIPTS}/${SERVICE_NAME}/${WORKFLOW_TEMPLATE}/.init
@@ -14,4 +14,6 @@ services:
14
14
  extends:
15
15
  file: ../.docker-compose.base.yml
16
16
  service: context_base
17
- working_dir: /home/stoobly/.stoobly/docker/build/${WORKFLOW_NAME}
17
+ volumes:
18
+ - ${APP_DIR}:/app
19
+ working_dir: /home/stoobly/.stoobly/docker/${SERVICE_NAME}/${WORKFLOW_NAME}
@@ -5,7 +5,7 @@ services:
5
5
  service: build.init_base
6
6
  image: stoobly.${USER_ID}
7
7
  profiles:
8
- - mock
8
+ - ${WORKFLOW_NAME}
9
9
  build.configure:
10
10
  depends_on:
11
11
  build.init:
@@ -15,4 +15,4 @@ services:
15
15
  service: build.configure_base
16
16
  image: stoobly.${USER_ID}
17
17
  profiles:
18
- - mock
18
+ - ${WORKFLOW_NAME}
@@ -0,0 +1,7 @@
1
+ # Define services here
2
+ #
3
+ # Container services that are intended to be run as part of a workflow need to have the workflow name added to the 'profiles' property
4
+ # e.g. If we want to run a service as part of the 'mock' workflow, then the following should be added
5
+ # profiles:
6
+ # - mock
7
+ services: {}
@@ -5,7 +5,7 @@ services:
5
5
  service: build.init_base
6
6
  image: stoobly.${USER_ID}
7
7
  profiles:
8
- - record
8
+ - ${WORKFLOW_NAME}
9
9
  build.configure:
10
10
  depends_on:
11
11
  build.init:
@@ -15,4 +15,4 @@ services:
15
15
  service: build.configure_base
16
16
  image: stoobly.${USER_ID}
17
17
  profiles:
18
- - record
18
+ - ${WORKFLOW_NAME}
@@ -0,0 +1,7 @@
1
+ # Define services here
2
+ #
3
+ # Container services that are intended to be run as part of a workflow need to have the workflow name added to the 'profiles' property
4
+ # e.g. If we want to run a service as part of the 'record' workflow, then the following should be added
5
+ # profiles:
6
+ # - record
7
+ services: {}
@@ -5,7 +5,7 @@ services:
5
5
  service: build.init_base
6
6
  image: stoobly.${USER_ID}
7
7
  profiles:
8
- - test
8
+ - ${WORKFLOW_NAME}
9
9
  build.configure:
10
10
  depends_on:
11
11
  build.init:
@@ -15,4 +15,4 @@ services:
15
15
  service: build.configure_base
16
16
  image: stoobly.${USER_ID}
17
17
  profiles:
18
- - test
18
+ - ${WORKFLOW_NAME}
@@ -0,0 +1,7 @@
1
+ # Define services here
2
+ #
3
+ # Container services that are intended to be run as part of a workflow need to have the workflow name added to the 'profiles' property
4
+ # e.g. If we want to run a service as part of the 'test' workflow, then the following should be added
5
+ # profiles:
6
+ # - test
7
+ services: {}
@@ -1,20 +1,19 @@
1
- networks: {}
2
1
  services:
3
2
  entrypoint.configure_base:
4
3
  command:
5
4
  - ${SERVICE_SCRIPTS}/${SERVICE_NAME}/${WORKFLOW_TEMPLATE}/.configure
6
5
  - bin/configure
7
- environment: {}
8
6
  extends:
9
7
  file: ../.docker-compose.base.yml
10
8
  service: context_base
11
- working_dir: /home/stoobly/.stoobly/docker/entrypoint/${WORKFLOW_NAME}
9
+ working_dir: /home/stoobly/.stoobly/docker/${SERVICE_NAME}/${WORKFLOW_NAME}
12
10
  entrypoint.init_base:
13
11
  command:
14
12
  - ${SERVICE_SCRIPTS}/${SERVICE_NAME}/${WORKFLOW_TEMPLATE}/.init
15
13
  - bin/init
16
- environment: {}
17
14
  extends:
18
15
  file: ../.docker-compose.base.yml
19
16
  service: context_base
20
- working_dir: /home/stoobly/.stoobly/docker/entrypoint/${WORKFLOW_NAME}
17
+ volumes:
18
+ - ${APP_DIR}:/app
19
+ working_dir: /home/stoobly/.stoobly/docker/${SERVICE_NAME}/${WORKFLOW_NAME}
@@ -1,25 +1,19 @@
1
- networks:
2
- entrypoint:
3
- name: entrypoint
4
1
  services:
5
2
  entrypoint.configure:
6
3
  depends_on:
7
4
  entrypoint.init:
8
5
  condition: service_completed_successfully
9
- environment: {}
10
6
  extends:
11
7
  file: ../.docker-compose.base.yml
12
8
  service: entrypoint.configure_base
13
9
  image: stoobly.${USER_ID}
14
10
  profiles:
15
- - mock
11
+ - ${WORKFLOW_NAME}
16
12
  volumes: []
17
13
  entrypoint.init:
18
- environment: {}
19
14
  extends:
20
15
  file: ../.docker-compose.base.yml
21
16
  service: entrypoint.init_base
22
17
  image: stoobly.${USER_ID}
23
18
  profiles:
24
- - mock
25
- volumes: {}
19
+ - ${WORKFLOW_NAME}
@@ -1,15 +1,8 @@
1
- # Define custom services here
1
+ # Define services here
2
2
  #
3
- # Container services that need to make request(s) to a Stoobly defined service
4
- # need to have either 'app.ingress' or 'app.egress' added to the 'networks' property
5
- #
6
- # e.g. If we want to make a request by hostname, then the following should be added
7
- # networks:
8
- # - app.ingress
9
- #
10
- # e.g. If we want to make a request by container service name, then the following should be added
11
- # networks:
12
- # - app.egress
3
+ # If a container service needs access to a Stoobly defined service,
4
+ # then the container service needs to add one of the scaffolded networks to the 'networks' property
5
+ # See https://docs.stoobly.com/core-concepts/scaffold
13
6
  #
14
7
  # Container services that are intended to be run as part of a workflow need to have the workflow name added to the 'profiles' property
15
8
  # e.g. If we want to run a service as part of the 'mock' workflow, then the following should be added