shoestring-assembler 0.0.4__tar.gz → 0.0.6__tar.gz
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.
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/PKG-INFO +2 -1
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/pyproject.toml +2 -1
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/src/shoestring_assembler/__init__.py +1 -1
- shoestring_assembler-0.0.6/src/shoestring_assembler/assembler.py +232 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/cli copy.py +297 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/cli.py +183 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/constants.py +28 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/display.py +165 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/docker.py +87 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/engine/__init__.py +0 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/engine/engine.py +204 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/engine/process.MD +46 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/engine/step_definitions.py +167 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/filesystem.py +181 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/git.py +354 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/layout.tcss +10 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/models/__init__.py +7 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/models/base_module.py +58 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/models/common.py +37 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/models/container.py +146 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/models/infrastructure_module.py +8 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/models/recipe.py +119 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/models/service_module.py +10 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/models/solution.py +164 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/models/source.py +66 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/models/user_config.py +223 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/schemas/__init__.py +2 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/schemas/schema_validators.py +50 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/solution_picker.py +116 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/user_config.py +98 -0
- {shoestring_assembler-0.0.4/src/shoestring_assembler → shoestring_assembler-0.0.6/src/shoestring_assembler/utilities}/minimal_mustache.py +6 -1
- shoestring_assembler-0.0.6/src/shoestring_assembler/utilities/path.py +7 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/views/__init__.py +0 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/views/cli_app.py +38 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/views/interface/updates.py +59 -0
- shoestring_assembler-0.0.6/src/shoestring_assembler/views/plain_cli.py +216 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/src/shoestring_assembler.egg-info/PKG-INFO +2 -1
- shoestring_assembler-0.0.6/src/shoestring_assembler.egg-info/SOURCES.txt +62 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/src/shoestring_assembler.egg-info/requires.txt +1 -0
- shoestring_assembler-0.0.4/src/shoestring_assembler/assembler.py +0 -1026
- shoestring_assembler-0.0.4/src/shoestring_assembler/cli.py +0 -315
- shoestring_assembler-0.0.4/src/shoestring_assembler/display.py +0 -108
- shoestring_assembler-0.0.4/src/shoestring_assembler/solution_picker.py +0 -80
- shoestring_assembler-0.0.4/src/shoestring_assembler.egg-info/SOURCES.txt +0 -34
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/AUTHORS.rst +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/CONTRIBUTING.rst +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/HISTORY.rst +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/LICENSE +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/MANIFEST.in +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/README.rst +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/docs/Makefile +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/docs/authors.rst +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/docs/conf.py +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/docs/contributing.rst +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/docs/history.rst +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/docs/index.rst +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/docs/installation.rst +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/docs/make.bat +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/docs/readme.rst +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/docs/usage.rst +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/setup.cfg +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/src/shoestring_assembler/schemas/meta.schema.json +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/src/shoestring_assembler/schemas/recipe.schema.json +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/src/shoestring_assembler.egg-info/dependency_links.txt +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/src/shoestring_assembler.egg-info/entry_points.txt +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/src/shoestring_assembler.egg-info/top_level.txt +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/tests/__init__.py +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/tests/console.log +0 -0
- {shoestring_assembler-0.0.4 → shoestring_assembler-0.0.6}/tests/test_shoestring_assembler.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: shoestring_assembler
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
4
4
|
Summary: Assembles Shoestring Solutions from a solution recipe
|
|
5
5
|
Author-email: Greg Hawkridge <gth24@cam.ac.uk>
|
|
6
6
|
Maintainer-email: Greg Hawkridge <gth24@cam.ac.uk>
|
|
@@ -23,6 +23,7 @@ Requires-Dist: typer==0.15.2
|
|
|
23
23
|
Requires-Dist: tomli==2.2.1; python_version < "3.11"
|
|
24
24
|
Requires-Dist: jsonschema[format-nongpl]==4.21.1
|
|
25
25
|
Requires-Dist: pyyaml==6.0.2
|
|
26
|
+
Requires-Dist: Jinja2==3.1.6
|
|
26
27
|
Requires-Dist: textual==2.1.2
|
|
27
28
|
Provides-Extra: dev
|
|
28
29
|
Requires-Dist: coverage; extra == "dev"
|
|
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "shoestring_assembler"
|
|
9
|
-
version = "0.0.
|
|
9
|
+
version = "0.0.6"
|
|
10
10
|
description = "Assembles Shoestring Solutions from a solution recipe"
|
|
11
11
|
readme = "README.rst"
|
|
12
12
|
authors = [
|
|
@@ -33,6 +33,7 @@ dependencies = [
|
|
|
33
33
|
"tomli==2.2.1;python_version<'3.11'",
|
|
34
34
|
"jsonschema[format-nongpl]==4.21.1",
|
|
35
35
|
"pyyaml==6.0.2",
|
|
36
|
+
"Jinja2==3.1.6",
|
|
36
37
|
"textual==2.1.2"
|
|
37
38
|
]
|
|
38
39
|
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import rich.progress
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import yaml
|
|
5
|
+
|
|
6
|
+
from .display import Display
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
from .utilities import minimal_mustache
|
|
10
|
+
from .constants import Contants
|
|
11
|
+
from .filesystem import FilesystemSource
|
|
12
|
+
from .git import GitSource
|
|
13
|
+
from shoestring_assembler.views.interface.updates import FatalError
|
|
14
|
+
|
|
15
|
+
# import for typing
|
|
16
|
+
from shoestring_assembler.models import SolutionModel, ServiceModuleModel, BaseModule
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Assembler:
|
|
20
|
+
|
|
21
|
+
def __init__(self, solution_model: SolutionModel):
|
|
22
|
+
self.solution_model = solution_model
|
|
23
|
+
|
|
24
|
+
def load_sources(self, do_gather):
|
|
25
|
+
Display.print_header("Gathering Service Module Sources")
|
|
26
|
+
|
|
27
|
+
if not do_gather:
|
|
28
|
+
Display.print_complete(
|
|
29
|
+
"Fetching service module sources disabled by command line arguements"
|
|
30
|
+
)
|
|
31
|
+
else:
|
|
32
|
+
with (
|
|
33
|
+
rich.progress.Progress() as progress
|
|
34
|
+
): # displays progress bar on console
|
|
35
|
+
|
|
36
|
+
used_sources = {module.source for module in self.solution_model.module_iterator()} # this is a set, not a dict to prevent duplicates
|
|
37
|
+
|
|
38
|
+
task = progress.add_task(
|
|
39
|
+
"[cyan] Gathering Service Module Sources",
|
|
40
|
+
total=len(used_sources)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
for source in used_sources:
|
|
44
|
+
Display.print_log(
|
|
45
|
+
f"Fetching {source.name}", console=progress.console
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if "file" in source.spec:
|
|
49
|
+
result = FilesystemSource.fetch(
|
|
50
|
+
source.name,
|
|
51
|
+
source.spec["file"],
|
|
52
|
+
console=progress.console,
|
|
53
|
+
)
|
|
54
|
+
elif "git" in source.spec:
|
|
55
|
+
result = GitSource.fetch(
|
|
56
|
+
source.name,
|
|
57
|
+
source.spec["git"],
|
|
58
|
+
console=progress.console,
|
|
59
|
+
progress=progress,
|
|
60
|
+
)
|
|
61
|
+
else:
|
|
62
|
+
# this should never happen due to recipe validation
|
|
63
|
+
raise FatalError(
|
|
64
|
+
f"Source {source.name} does not include details on where to get it",
|
|
65
|
+
console=progress.console,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
if result:
|
|
69
|
+
Display.print_complete(
|
|
70
|
+
f"Fetched '{source.name}' ", console=progress.console
|
|
71
|
+
)
|
|
72
|
+
progress.update(task, advance=1) # updates progress bar
|
|
73
|
+
else:
|
|
74
|
+
progress.update(task, visible=False)
|
|
75
|
+
raise FatalError(
|
|
76
|
+
f"An error occured while fetching '{source.name}'",
|
|
77
|
+
console=progress.console,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
Display.print_complete("All Service Module Sources Gathered")
|
|
81
|
+
|
|
82
|
+
def generate_compose_file(self):
|
|
83
|
+
Display.print_header("Generating Compose File")
|
|
84
|
+
compose_definition = {
|
|
85
|
+
"services": {},
|
|
86
|
+
"networks": {Contants.DOCKER_NETWORK_NAME: {"name": "shoestring-internal"}},
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
for service_module in self.solution_model.service_modules:
|
|
90
|
+
service_set = self.generate_docker_services_for_module(
|
|
91
|
+
service_module
|
|
92
|
+
)
|
|
93
|
+
compose_definition["services"].update(service_set)
|
|
94
|
+
|
|
95
|
+
for infrastructure_module in self.solution_model.infrastructure:
|
|
96
|
+
service_set = self.generate_docker_services_for_module(
|
|
97
|
+
infrastructure_module
|
|
98
|
+
)
|
|
99
|
+
compose_definition["services"].update(service_set)
|
|
100
|
+
|
|
101
|
+
compose_definition["x-shoestring"] = {
|
|
102
|
+
"recipe": {
|
|
103
|
+
"filename": self.solution_model.recipe._filepath_provided,
|
|
104
|
+
"hash": self.solution_model.recipe._hash,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
self.solution_model.save_compose_spec(compose_definition)
|
|
109
|
+
|
|
110
|
+
Display.print_complete(f"Compose file complete")
|
|
111
|
+
|
|
112
|
+
def generate_docker_services_for_module(self, module: BaseModule):
|
|
113
|
+
Display.print_log(f"[cyan]* {module.name}")
|
|
114
|
+
module_services = {}
|
|
115
|
+
|
|
116
|
+
for container in module.containers:
|
|
117
|
+
if len(module.containers) > 1:
|
|
118
|
+
Display.print_log(f"[cyan]** {container.identifier}")
|
|
119
|
+
|
|
120
|
+
# form base
|
|
121
|
+
service_definition = {
|
|
122
|
+
"build": {
|
|
123
|
+
"context": str(module.source.relative_directory_path),
|
|
124
|
+
"dockerfile": f"./{container.meta.get('dockerfile','Dockerfile')}",
|
|
125
|
+
"additional_contexts": [
|
|
126
|
+
f"solution_config={module.source.solution_config_dir}"
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
"networks": {
|
|
130
|
+
Contants.DOCKER_NETWORK_NAME: {
|
|
131
|
+
"aliases": [f"{container.alias}{Contants.DOCKER_ALIAS_SUFFIX}"]
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
"logging": {
|
|
135
|
+
"driver": "syslog",
|
|
136
|
+
"options": {"tag": f"docker-{container.identifier}"},
|
|
137
|
+
},
|
|
138
|
+
"labels": {
|
|
139
|
+
"net.digitalshoestring.solution": self.solution_model.spec["slug"],
|
|
140
|
+
"net.digitalshoestring.function": module.type,
|
|
141
|
+
},
|
|
142
|
+
"restart": "unless-stopped",
|
|
143
|
+
}
|
|
144
|
+
# extend with partials
|
|
145
|
+
raw_partials_string = container.partial_compose_snippet
|
|
146
|
+
if raw_partials_string:
|
|
147
|
+
template_applied_string = minimal_mustache.render(
|
|
148
|
+
raw_partials_string, module.spec.get("template", {})
|
|
149
|
+
)
|
|
150
|
+
partials = yaml.safe_load(template_applied_string)
|
|
151
|
+
else:
|
|
152
|
+
partials = {}
|
|
153
|
+
|
|
154
|
+
service_definition = {
|
|
155
|
+
**partials,
|
|
156
|
+
**service_definition,
|
|
157
|
+
} # update in this way to prevent partials from overwriting service_definition keys
|
|
158
|
+
|
|
159
|
+
# sort out volumes
|
|
160
|
+
# volumes = {
|
|
161
|
+
# "data": {"host": f"./{Contants.DATA_DIR}/{module.name}"},
|
|
162
|
+
# "user_config": {"host": f"./{Contants.USER_CONFIG_DIR}/{module.name}"},
|
|
163
|
+
# } # defaults
|
|
164
|
+
|
|
165
|
+
container.volumes.apply_container_spec(container.meta.get("volume", {}))
|
|
166
|
+
|
|
167
|
+
compose_volumes = []
|
|
168
|
+
for volume in container.volumes.values():
|
|
169
|
+
if volume.ignored: # container doesn't use this volume
|
|
170
|
+
continue
|
|
171
|
+
volume.check_valid() # throws errors if problems exist
|
|
172
|
+
compose_volumes.append(volume.formatted())
|
|
173
|
+
|
|
174
|
+
if len(compose_volumes) > 0:
|
|
175
|
+
service_definition["volumes"] = compose_volumes
|
|
176
|
+
|
|
177
|
+
# map in ports
|
|
178
|
+
ports = {} # defaults
|
|
179
|
+
|
|
180
|
+
# map in container ports
|
|
181
|
+
container_ports = container.meta.get("ports", {})
|
|
182
|
+
for name, port_number in container_ports.items():
|
|
183
|
+
if name not in ports:
|
|
184
|
+
ports[name] = {}
|
|
185
|
+
ports[name]["container"] = port_number
|
|
186
|
+
# map in host ports
|
|
187
|
+
for name, port_number in container.host_ports.items():
|
|
188
|
+
if name not in ports:
|
|
189
|
+
ports[name] = {}
|
|
190
|
+
ports[name]["host"] = port_number
|
|
191
|
+
|
|
192
|
+
# combine mappings
|
|
193
|
+
compose_ports = []
|
|
194
|
+
for name, mapping in ports.items():
|
|
195
|
+
has_host = "host" in mapping
|
|
196
|
+
has_cnt = "container" in mapping
|
|
197
|
+
if has_host and has_cnt: # everything as expected
|
|
198
|
+
entry = f'{mapping["host"]}:{mapping["container"]}'
|
|
199
|
+
compose_ports.append(entry)
|
|
200
|
+
elif has_host:
|
|
201
|
+
# no container entry to map to
|
|
202
|
+
raise FatalError(
|
|
203
|
+
f"No corresponding container entry for port {name} of {container.identifier}."
|
|
204
|
+
)
|
|
205
|
+
elif has_cnt:
|
|
206
|
+
# no host entry to map to
|
|
207
|
+
raise FatalError(
|
|
208
|
+
f"No corresponding host entry for port {name} of {container.identifier}."
|
|
209
|
+
)
|
|
210
|
+
if len(compose_ports) > 0:
|
|
211
|
+
service_definition["ports"] = compose_ports
|
|
212
|
+
|
|
213
|
+
module_services[container.identifier] = service_definition
|
|
214
|
+
|
|
215
|
+
return module_services
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
"""
|
|
219
|
+
TO DO List:
|
|
220
|
+
* work out what clean means
|
|
221
|
+
* handle volumes in snippets
|
|
222
|
+
* setup scripts
|
|
223
|
+
|
|
224
|
+
Longer term
|
|
225
|
+
* solution config templates & bootstrapping
|
|
226
|
+
* host side volume specification
|
|
227
|
+
* named volumes - when only has container entry?
|
|
228
|
+
* would need warning if repeated
|
|
229
|
+
* Environment variables
|
|
230
|
+
* coveying port and alias mappings to services
|
|
231
|
+
* external resources
|
|
232
|
+
"""
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"""Console script for shoestring_assembler."""
|
|
2
|
+
|
|
3
|
+
import shoestring_assembler
|
|
4
|
+
from shoestring_assembler.assembler import Assembler
|
|
5
|
+
from shoestring_assembler.models.recipe import Recipe
|
|
6
|
+
from shoestring_assembler.user_config import UserConfig
|
|
7
|
+
from shoestring_assembler.display import Display
|
|
8
|
+
from shoestring_assembler.filesystem import SolutionFilesystem
|
|
9
|
+
from shoestring_assembler.git import SolutionGitVC, GetSolutionUsingGit
|
|
10
|
+
from shoestring_assembler.docker import Docker
|
|
11
|
+
|
|
12
|
+
import typer
|
|
13
|
+
from typing_extensions import Annotated
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
|
|
17
|
+
from rich.prompt import Prompt, Confirm
|
|
18
|
+
|
|
19
|
+
typer_app = typer.Typer(name="Shoestring Assembler", no_args_is_help=True)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
CANCEL_PHRASE = "cancel"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@typer_app.command()
|
|
26
|
+
def update(
|
|
27
|
+
version: Annotated[
|
|
28
|
+
str, typer.Argument(help="Update to this version. (optional)")
|
|
29
|
+
] = "",
|
|
30
|
+
verbose: Annotated[
|
|
31
|
+
bool, typer.Option("--verbose", help="Show extra logs.")
|
|
32
|
+
] = False,
|
|
33
|
+
yes: Annotated[
|
|
34
|
+
bool,
|
|
35
|
+
typer.Option(
|
|
36
|
+
"--yes", "-y", help="Automatically download and assemble the latest version"
|
|
37
|
+
),
|
|
38
|
+
] = False,
|
|
39
|
+
recipe_location: Annotated[
|
|
40
|
+
str, typer.Argument(help="Path to recipe file")
|
|
41
|
+
] = "./recipe.toml",
|
|
42
|
+
):
|
|
43
|
+
"""
|
|
44
|
+
Updates the solution to the specified version. If a version is not specified - it lists the available versions that you can choose from.
|
|
45
|
+
"""
|
|
46
|
+
if verbose:
|
|
47
|
+
Display.log_level = 5
|
|
48
|
+
|
|
49
|
+
Display.print_top_header("Updating Solution")
|
|
50
|
+
|
|
51
|
+
solution_version_control = SolutionGitVC()
|
|
52
|
+
|
|
53
|
+
if not version:
|
|
54
|
+
if not solution_version_control.is_update_available():
|
|
55
|
+
Display.print_notification("Latest version installed.")
|
|
56
|
+
return
|
|
57
|
+
else:
|
|
58
|
+
Display.print_notification("A new version is available.")
|
|
59
|
+
available_versions = solution_version_control.list_updates()
|
|
60
|
+
if yes:
|
|
61
|
+
version = available_versions[0]
|
|
62
|
+
elif Confirm.ask("? Do you want to update now?", default=True):
|
|
63
|
+
selected_version = Prompt.ask(
|
|
64
|
+
"? Select a version?",
|
|
65
|
+
choices=available_versions
|
|
66
|
+
+ [
|
|
67
|
+
CANCEL_PHRASE,
|
|
68
|
+
],
|
|
69
|
+
default=available_versions[0],
|
|
70
|
+
)
|
|
71
|
+
if selected_version != CANCEL_PHRASE:
|
|
72
|
+
version = selected_version
|
|
73
|
+
|
|
74
|
+
if version:
|
|
75
|
+
updated = solution_version_control.do_update(version)
|
|
76
|
+
if updated:
|
|
77
|
+
if yes or Confirm.ask(
|
|
78
|
+
"? Do you want to assemble the solution now?", default=True
|
|
79
|
+
):
|
|
80
|
+
try:
|
|
81
|
+
assemble(recipe_location)
|
|
82
|
+
return
|
|
83
|
+
except SystemExit:
|
|
84
|
+
Display.print_error(
|
|
85
|
+
"Solution assembly failed. If you want to run it again use: [green]shoestring assemble[/green]"
|
|
86
|
+
)
|
|
87
|
+
raise
|
|
88
|
+
else:
|
|
89
|
+
Display.print_log(
|
|
90
|
+
"If you want to update later - run: [green]shoestring update <version>[/green]"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
Display.print_top_header("Finished")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@typer_app.command()
|
|
97
|
+
def check_recipe(
|
|
98
|
+
recipe_location: Annotated[
|
|
99
|
+
str, typer.Argument(help="Path to recipe file")
|
|
100
|
+
] = "./recipe.toml",
|
|
101
|
+
):
|
|
102
|
+
Display.print_top_header("Checking Recipe")
|
|
103
|
+
Recipe.load(recipe_location)
|
|
104
|
+
Display.print_top_header("Finished")
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@typer_app.command(name="test")
|
|
108
|
+
def bootstrap(
|
|
109
|
+
recipe: Annotated[
|
|
110
|
+
str, typer.Argument(help="Path to recipe file")
|
|
111
|
+
] = "./recipe.toml",
|
|
112
|
+
verbose: Annotated[
|
|
113
|
+
bool, typer.Option("--verbose", help="Show extra logs.")
|
|
114
|
+
] = False,
|
|
115
|
+
):
|
|
116
|
+
"""
|
|
117
|
+
Uses templates to bootstrap the solution config for the specified sources
|
|
118
|
+
"""
|
|
119
|
+
if verbose:
|
|
120
|
+
Display.log_level = 5
|
|
121
|
+
from .engine.engine import Engine
|
|
122
|
+
from .views.plain_cli import PlainCLI
|
|
123
|
+
|
|
124
|
+
ui = PlainCLI()
|
|
125
|
+
engine = Engine(update_callback=ui.notify_fn)
|
|
126
|
+
engine.init_download()
|
|
127
|
+
ui.execute(engine)
|
|
128
|
+
# action = engine.start_process(engine.update_solution(False, None))
|
|
129
|
+
# event = ui.handle(action)
|
|
130
|
+
# while event is not None:
|
|
131
|
+
# action = engine.send_event(event)
|
|
132
|
+
# event = ui.handle(action)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@typer_app.command()
|
|
136
|
+
def assemble(
|
|
137
|
+
recipe_location: Annotated[
|
|
138
|
+
str, typer.Argument(help="Path to recipe file")
|
|
139
|
+
] = "./recipe.toml",
|
|
140
|
+
download: bool = True,
|
|
141
|
+
verbose: Annotated[
|
|
142
|
+
bool, typer.Option("--verbose", help="Show extra logs.")
|
|
143
|
+
] = False,
|
|
144
|
+
):
|
|
145
|
+
"""
|
|
146
|
+
Assembles the solution using the provided recipe
|
|
147
|
+
"""
|
|
148
|
+
if verbose:
|
|
149
|
+
Display.log_level = 5
|
|
150
|
+
Display.print_top_header("Assembling Solution")
|
|
151
|
+
|
|
152
|
+
recipe = Recipe.load(recipe_location)
|
|
153
|
+
SolutionFilesystem.clean(clean_sources=download)
|
|
154
|
+
SolutionFilesystem.verify(recipe, check_sources=not download)
|
|
155
|
+
Assembler(recipe).load_sources(do_gather=download)
|
|
156
|
+
Assembler(recipe).generate_compose_file()
|
|
157
|
+
UserConfig.configure(recipe)
|
|
158
|
+
Display.print_top_header("Finished")
|
|
159
|
+
Display.print_next_steps(
|
|
160
|
+
"* Configure the service modules according to your needs (refer to the guide for details) \n\n* Once the solution is ready - run [white]shoestring build[/white] to build the solution"
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
import urllib
|
|
165
|
+
import yaml
|
|
166
|
+
from rich.prompt import Prompt
|
|
167
|
+
import subprocess
|
|
168
|
+
from .solution_picker import SolutionPickerApp
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
# Temporary implementation - refactor once proof-of-concept complete
|
|
172
|
+
@typer_app.command()
|
|
173
|
+
def get(
|
|
174
|
+
verbose: Annotated[
|
|
175
|
+
bool, typer.Option("--verbose", help="Show extra logs.")
|
|
176
|
+
] = False,
|
|
177
|
+
):
|
|
178
|
+
"""
|
|
179
|
+
Downloads the specified solution
|
|
180
|
+
"""
|
|
181
|
+
if verbose:
|
|
182
|
+
Display.log_level = 5
|
|
183
|
+
|
|
184
|
+
Display.print_top_header("Get Solution")
|
|
185
|
+
|
|
186
|
+
Display.print_header(f"Selecting Solution")
|
|
187
|
+
# fetch solution list
|
|
188
|
+
list_branch = os.getenv("SHOESTRING_LIST_BRANCH", "main")
|
|
189
|
+
try:
|
|
190
|
+
with urllib.request.urlopen(
|
|
191
|
+
f"https://github.com/DigitalShoestringSolutions/solution_list/raw/refs/heads/{list_branch}/list.yaml"
|
|
192
|
+
) as web_in:
|
|
193
|
+
content = web_in.read()
|
|
194
|
+
provider_list = yaml.safe_load(content)
|
|
195
|
+
except urllib.error.URLError:
|
|
196
|
+
Display.print_error("Unable to fetch latest solution list")
|
|
197
|
+
return
|
|
198
|
+
|
|
199
|
+
selected = SolutionPickerApp(provider_list).run()
|
|
200
|
+
|
|
201
|
+
if selected == None:
|
|
202
|
+
Display.print_log("Solution selection cancelled")
|
|
203
|
+
else:
|
|
204
|
+
Display.print_log(f"Selected [green]{selected['name']}[/green]")
|
|
205
|
+
|
|
206
|
+
if GetSolutionUsingGit.download(selected):
|
|
207
|
+
Display.print_complete("Done")
|
|
208
|
+
Display.print_next_steps(
|
|
209
|
+
"* Move to the solution folder using [white]cd[/white]\n\n"
|
|
210
|
+
+ "* Once in the folder assemble the solution using [white]shoestring assemble[/white]"
|
|
211
|
+
)
|
|
212
|
+
else:
|
|
213
|
+
Display.print_error("Unable to download solution")
|
|
214
|
+
Display.print_top_header("Finished")
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
@typer_app.command()
|
|
218
|
+
def build():
|
|
219
|
+
Display.print_top_header("Starting solution")
|
|
220
|
+
built = Docker.build()
|
|
221
|
+
if built:
|
|
222
|
+
Display.print_complete("Solution Built")
|
|
223
|
+
Display.print_next_steps(
|
|
224
|
+
"To run the solution use [white]shoestring start[/white]"
|
|
225
|
+
)
|
|
226
|
+
else:
|
|
227
|
+
Display.print_error("Solution Building Failed")
|
|
228
|
+
Display.print_top_header("Finished")
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@typer_app.command()
|
|
232
|
+
def setup():
|
|
233
|
+
Display.print_top_header("Setting up Service Modules")
|
|
234
|
+
|
|
235
|
+
Docker.setup_containers()
|
|
236
|
+
|
|
237
|
+
Display.print_top_header("Finished")
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
@typer_app.command()
|
|
241
|
+
def start():
|
|
242
|
+
Display.print_top_header("Starting solution")
|
|
243
|
+
started = Docker.start()
|
|
244
|
+
if started:
|
|
245
|
+
Display.print_complete("Solution is now running in the background")
|
|
246
|
+
Display.print_top_header("Finished")
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
@typer_app.command()
|
|
250
|
+
def reconfigure(
|
|
251
|
+
recipe_location: Annotated[
|
|
252
|
+
str, typer.Argument(help="Path to recipe file")
|
|
253
|
+
] = "./recipe.toml",
|
|
254
|
+
verbose: Annotated[
|
|
255
|
+
bool, typer.Option("--verbose", help="Show extra logs.")
|
|
256
|
+
] = False,
|
|
257
|
+
):
|
|
258
|
+
if verbose:
|
|
259
|
+
Display.log_level = 5
|
|
260
|
+
Display.print_top_header("Reconfiguring user config")
|
|
261
|
+
recipe = Recipe.load(recipe_location)
|
|
262
|
+
UserConfig.reconfigure(recipe)
|
|
263
|
+
Display.print_top_header("Finished")
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
@typer_app.callback(invoke_without_command=True)
|
|
267
|
+
def main(
|
|
268
|
+
version: Annotated[
|
|
269
|
+
bool, typer.Option("--version", "-v", help="Assembler version")
|
|
270
|
+
] = False,
|
|
271
|
+
):
|
|
272
|
+
if version:
|
|
273
|
+
Display.print_log(
|
|
274
|
+
f"Shoestring Assembler version {shoestring_assembler.__version__}"
|
|
275
|
+
)
|
|
276
|
+
else:
|
|
277
|
+
pass # TODO display menu
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def app():
|
|
281
|
+
try:
|
|
282
|
+
if os.geteuid() == 0:
|
|
283
|
+
Display.print_error(
|
|
284
|
+
"To try prevent you from accidentally breaking things, this program won't run with sudo or as root! \nRun it again without sudo or change to a non-root user."
|
|
285
|
+
)
|
|
286
|
+
sys.exit(255)
|
|
287
|
+
typer_app()
|
|
288
|
+
finally:
|
|
289
|
+
Display.finalise_log()
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
if __name__ == "__main__":
|
|
293
|
+
app()
|
|
294
|
+
"""
|
|
295
|
+
* shoestring
|
|
296
|
+
* bootstrap (maybe for a separate developer focussed tool?)
|
|
297
|
+
"""
|