cs-image-system-tf-docker-plugin 0.1.6__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.
- cs_image_system/tf_docker_plugin/__init__.py +3 -0
- cs_image_system/tf_docker_plugin/main.py +30 -0
- cs_image_system/tf_docker_plugin/tf_docker_instance_builder.py +297 -0
- cs_image_system/tf_docker_plugin/tf_docker_models.py +57 -0
- cs_image_system/tf_docker_plugin/tf_docker_storage_builder.py +177 -0
- cs_image_system_tf_docker_plugin-0.1.6.dist-info/METADATA +320 -0
- cs_image_system_tf_docker_plugin-0.1.6.dist-info/RECORD +10 -0
- cs_image_system_tf_docker_plugin-0.1.6.dist-info/WHEEL +4 -0
- cs_image_system_tf_docker_plugin-0.1.6.dist-info/entry_points.txt +2 -0
- cs_image_system_tf_docker_plugin-0.1.6.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Mykel Alvis <mykelalvis@infrastructurebuilder.org>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
|
|
7
|
+
from cs_image_system.base.basic.abstract_plugin_metadata import AbstractPluginMetadata
|
|
8
|
+
|
|
9
|
+
from .tf_docker_instance_builder import TofuDockerInstanceBuilder
|
|
10
|
+
from .tf_docker_models import TF_DOCKER_VOLUME, TOFU_DOCKER, TofuDockerInstanceBuilderModel, TofuDockerVolumeStorageBuilderModel
|
|
11
|
+
from .tf_docker_storage_builder import TofuDockerVolumeStorageBuilder
|
|
12
|
+
|
|
13
|
+
log = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TFDockerTypes(AbstractPluginMetadata):
|
|
17
|
+
"""The container instance builder AND the volume storage builder (stage
|
|
18
|
+
103 branch 2), in one registration as the clouds' tofu plugins are."""
|
|
19
|
+
|
|
20
|
+
def __init__(self) -> None:
|
|
21
|
+
super().__init__("1", "3.13",
|
|
22
|
+
{TOFU_DOCKER: [TofuDockerInstanceBuilderModel, TofuDockerInstanceBuilder],
|
|
23
|
+
TF_DOCKER_VOLUME: [TofuDockerVolumeStorageBuilderModel, TofuDockerVolumeStorageBuilder]},
|
|
24
|
+
{TofuDockerInstanceBuilderModel: TofuDockerInstanceBuilder,
|
|
25
|
+
TofuDockerVolumeStorageBuilderModel: TofuDockerVolumeStorageBuilder})
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def initialize():
|
|
29
|
+
log.debug("Initializing the TF docker tofu provider (containers + volumes)")
|
|
30
|
+
return TFDockerTypes()
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Mykel Alvis <mykelalvis@infrastructurebuilder.org>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""The container instance builder (stage 103 branch 2).
|
|
6
|
+
|
|
7
|
+
One ``module`` call per instance against tfmodules/docker_container, on
|
|
8
|
+
OpenTofu's ``kreuzwerker/docker`` provider. The image is the instance's
|
|
9
|
+
pinned build (an image id), else the resolved provider-specific image, else
|
|
10
|
+
the per-instance variable finalization fills from the packer manifest with
|
|
11
|
+
the series' floating tag as the fallback (the daemon has no "newest image
|
|
12
|
+
matching a pattern" query, so the tag the bake moves IS that query). Each
|
|
13
|
+
container gets the canonical hostname ``<name>-NNN``, labels for the
|
|
14
|
+
configuration id, the instance and the generation (the module adds the
|
|
15
|
+
build), its network by name, the limits of its machine type, its volumes at
|
|
16
|
+
their mount points and the restart policy ``unless-stopped``; it is declared
|
|
17
|
+
so the next apply leaves a stopped container alone (``must_run = false``).
|
|
18
|
+
|
|
19
|
+
Launching without user data: the same launch script the clouds feed through
|
|
20
|
+
user data is rendered by ``templatefile`` and UPLOADED into the container at
|
|
21
|
+
creation; the launch-delivery hook runs it through ``docker exec`` after the
|
|
22
|
+
apply (the runtime's ``launch_delivery`` is ``session``). The daemon mounts
|
|
23
|
+
each volume, so the script only makes the group's subtree; the hostname
|
|
24
|
+
comes from the container.
|
|
25
|
+
|
|
26
|
+
The daemon's address never enters the root: every tofu process the root
|
|
27
|
+
runs carries the runtime's ``DOCKER_HOST`` or ``DOCKER_CONTEXT`` in its
|
|
28
|
+
environment (an ENC host stays a marker in the runner script and opens
|
|
29
|
+
where the line runs), and the provider block is empty.
|
|
30
|
+
"""
|
|
31
|
+
from __future__ import annotations
|
|
32
|
+
|
|
33
|
+
import logging
|
|
34
|
+
import re
|
|
35
|
+
from decimal import Decimal, InvalidOperation
|
|
36
|
+
from typing import Any, TypeVar, cast
|
|
37
|
+
|
|
38
|
+
from cs_image_system.base import utils
|
|
39
|
+
from cs_image_system.base.launch_params import ENROLLMENT_TOKEN_VARIABLE, compute_launch_params, user_data_template
|
|
40
|
+
from cs_image_system.base.models.executable import ExecutableModel
|
|
41
|
+
from cs_image_system.base.models.instance import Instance
|
|
42
|
+
from cs_image_system.contract.assets import AssetSet
|
|
43
|
+
from cs_image_system.contract.hcl import HclRaw, hcl_expr, render_module_call
|
|
44
|
+
from cs_image_system.contract.lifecycle import ExecutionLifecyclePhase
|
|
45
|
+
from cs_image_system.hashicorp_utils.collector import TerraformCollector, TerraformVariable
|
|
46
|
+
from cs_image_system.tf_ebs_instance_plugin.tf_instance_builder import TofuInstanceBuilder
|
|
47
|
+
|
|
48
|
+
from .tf_docker_models import TOFU_DOCKER, TofuDockerInstanceBuilderModel
|
|
49
|
+
|
|
50
|
+
log = logging.getLogger(__name__)
|
|
51
|
+
|
|
52
|
+
Q = TypeVar("Q", bound=TofuDockerInstanceBuilderModel)
|
|
53
|
+
|
|
54
|
+
DOCKER_PROVIDER_SOURCE = "kreuzwerker/docker"
|
|
55
|
+
_MEMORY = re.compile(r"^\s*(\d+(?:\.\d+)?)\s*([kKmMgGtT]?)[bB]?\s*$")
|
|
56
|
+
_UNIT_MB = {"": 1, "k": 1 / 1024, "m": 1, "g": 1024, "t": 1024 * 1024}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def memory_mb(value: Any) -> int:
|
|
60
|
+
"""A machine type's memory in the provider's unit (MB) from docker's own
|
|
61
|
+
spelling (``512m``, ``4g``, ``2048``; a bare number is MB). 0 = none."""
|
|
62
|
+
if value is None or str(value).strip() == "":
|
|
63
|
+
return 0
|
|
64
|
+
m = _MEMORY.match(str(value))
|
|
65
|
+
if not m:
|
|
66
|
+
raise ValueError(f"memory {value!r} is not a size docker understands (512m, 4g, 2048)")
|
|
67
|
+
number, unit = m.group(1), m.group(2).lower()
|
|
68
|
+
mb = float(number) * _UNIT_MB[unit]
|
|
69
|
+
return int(round(mb))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def cpus_as_read_back(value: Any) -> str:
|
|
73
|
+
"""The provider reads ``cpus`` back with a decimal point (``1`` becomes
|
|
74
|
+
``1.0`` and would plan a replacement forever; found while proving the
|
|
75
|
+
module): render every value with one. Empty when none."""
|
|
76
|
+
if value is None or str(value).strip() == "":
|
|
77
|
+
return ""
|
|
78
|
+
try:
|
|
79
|
+
text = format(Decimal(str(value)).normalize(), "f")
|
|
80
|
+
except InvalidOperation as e:
|
|
81
|
+
raise ValueError(f"cpus {value!r} is not a number") from e
|
|
82
|
+
return text if "." in text else text + ".0"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def generation_of(hostname: str, name: str) -> str:
|
|
86
|
+
"""The generation a canonical hostname carries (``coops-model-003`` is
|
|
87
|
+
3); a machine grandfathered without a suffix is the record's first."""
|
|
88
|
+
tail = hostname[len(name) + 1:] if hostname.startswith(name + "-") else ""
|
|
89
|
+
return str(int(tail)) if tail.isdigit() else "1"
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class TofuDockerInstanceBuilder(TofuInstanceBuilder[Q]):
|
|
93
|
+
@classmethod
|
|
94
|
+
def csis_name(cls) -> str:
|
|
95
|
+
return TOFU_DOCKER
|
|
96
|
+
|
|
97
|
+
@staticmethod
|
|
98
|
+
def _image_var(label: str) -> str:
|
|
99
|
+
return f"{label}_image"
|
|
100
|
+
|
|
101
|
+
@staticmethod
|
|
102
|
+
def _ami_var(label: str) -> str:
|
|
103
|
+
"""The variable the inherited ``pre_finalize_phase`` writes into
|
|
104
|
+
``instances.auto.tfvars`` for a build this run baked (the GCE
|
|
105
|
+
builder's lesson, stage 63 item 7)."""
|
|
106
|
+
return TofuDockerInstanceBuilder._image_var(label)
|
|
107
|
+
|
|
108
|
+
def get_executable_copy(self) -> ExecutableModel:
|
|
109
|
+
"""Every tofu process of this root reaches the runtime's daemon: the
|
|
110
|
+
runtime's tool environment rides on the executable (the runner
|
|
111
|
+
script carries it as an assignment prefix)."""
|
|
112
|
+
e = super().get_executable_copy()
|
|
113
|
+
rtb = self._runtime_builder()
|
|
114
|
+
env_of = getattr(rtb, "tool_environment", None)
|
|
115
|
+
if callable(env_of):
|
|
116
|
+
extra = cast(dict[str, str], env_of())
|
|
117
|
+
e.environment = {**dict(e.environment or {}), **extra}
|
|
118
|
+
return e
|
|
119
|
+
|
|
120
|
+
@staticmethod
|
|
121
|
+
def _launch_script_template_name(label: str) -> str:
|
|
122
|
+
return f"launch-{label}.sh.tftpl"
|
|
123
|
+
|
|
124
|
+
def generate_items_before(self, phase: ExecutionLifecyclePhase) -> AssetSet:
|
|
125
|
+
items = AssetSet()
|
|
126
|
+
if phase != ExecutionLifecyclePhase.INSTANCE_GENERATION or not self._root_has_work():
|
|
127
|
+
return items
|
|
128
|
+
rpath = self.get_path_for_phase(phase, suffix=".tf")
|
|
129
|
+
items = items.with_default_path(rpath)
|
|
130
|
+
items.add(f"# Terraform configuration for containers generated by "
|
|
131
|
+
f"{self.__class__.__name__} ({self.name})")
|
|
132
|
+
items.add("# The daemon's address is not here: every tofu process of this root carries the")
|
|
133
|
+
items.add("# runtime's DOCKER_HOST or DOCKER_CONTEXT in its environment (stage 103 branch 2).")
|
|
134
|
+
col = TerraformCollector()
|
|
135
|
+
ws = self.name
|
|
136
|
+
self._declare_ephemeral_variable(col, ws)
|
|
137
|
+
if self.model.required_plugins:
|
|
138
|
+
for plugin in self.model.required_plugins:
|
|
139
|
+
col.require_provider(ws, plugin.name, source=getattr(plugin, "source", None),
|
|
140
|
+
version=getattr(plugin, "version", None))
|
|
141
|
+
else:
|
|
142
|
+
col.require_provider(ws, "docker", source=DOCKER_PROVIDER_SOURCE)
|
|
143
|
+
col.configure_provider(ws, "docker", {}) # the address rides in the environment
|
|
144
|
+
for instance in self._instances:
|
|
145
|
+
label = utils.super_safe_name(instance.get_name())
|
|
146
|
+
col.declare_variable(ws, TerraformVariable(name=self._image_var(label), type="string", default=""))
|
|
147
|
+
col.declare_variable(ws, TerraformVariable(
|
|
148
|
+
name=ENROLLMENT_TOKEN_VARIABLE, type="string", default="", sensitive=True,
|
|
149
|
+
description="Identity enrollment token handed to instances at launch (TF_VAR_...); empty = no enrollment"))
|
|
150
|
+
col.bind_workspace(ws, self.model.state_configuration, self.runtime_state_configuration()) # stage 46: own, runtime's, default
|
|
151
|
+
ctx = self._get_context()
|
|
152
|
+
for sb_name, sb in ctx.storage_builders.items():
|
|
153
|
+
if getattr(sb.model, "_storages", None):
|
|
154
|
+
col.reference_remote_state(ws, producer_workspace=sb_name)
|
|
155
|
+
identity_ws: set[str] = set()
|
|
156
|
+
for instance in self._instances:
|
|
157
|
+
image = ctx.images_map.get(str(instance.image)) if instance.image else None
|
|
158
|
+
iws = self._identity_workspace_for(getattr(image, "group", None))
|
|
159
|
+
if iws:
|
|
160
|
+
identity_ws.add(iws)
|
|
161
|
+
for iws in sorted(identity_ws):
|
|
162
|
+
col.reference_remote_state(ws, producer_workspace=iws)
|
|
163
|
+
items.add_list(col.generate_terraform_block(ws))
|
|
164
|
+
items.add_list(col.generate_provider_blocks(ws))
|
|
165
|
+
variable_lines = col.generate_variable_blocks(ws)
|
|
166
|
+
if variable_lines:
|
|
167
|
+
items.add_list(variable_lines)
|
|
168
|
+
remote_lines = col.generate_remote_state_datasources(ws)
|
|
169
|
+
if remote_lines:
|
|
170
|
+
items.add_list(remote_lines)
|
|
171
|
+
backend_lines = col.generate_backend_config(ws)
|
|
172
|
+
if backend_lines:
|
|
173
|
+
items.add_list(self._backend_config_path(phase), backend_lines)
|
|
174
|
+
return items
|
|
175
|
+
|
|
176
|
+
def generate_items_during(self, phase: ExecutionLifecyclePhase) -> AssetSet:
|
|
177
|
+
items = AssetSet()
|
|
178
|
+
if phase != ExecutionLifecyclePhase.INSTANCE_GENERATION or not self._root_has_work():
|
|
179
|
+
return items # ledger 70: outside --only-runtime, nothing
|
|
180
|
+
ctx = self._get_context()
|
|
181
|
+
rtb = self._runtime_builder()
|
|
182
|
+
src = utils.module_source("docker_container", self.get_path_for_phase(phase, suffix=".tf").parent)
|
|
183
|
+
bindings = TerraformCollector().provider_bindings(self.name)
|
|
184
|
+
for instance in self._instances:
|
|
185
|
+
label = utils.super_safe_name(instance.get_name())
|
|
186
|
+
rpath = self.get_path_for_phase(phase, f"instance-{label}", suffix=".tf")
|
|
187
|
+
params = compute_launch_params(ctx, instance)
|
|
188
|
+
items.add(rpath, f"# Terraform module call for container {instance.get_name()} "
|
|
189
|
+
f"generated by {self.__class__.__name__} ({self.name})")
|
|
190
|
+
if params.get("group"):
|
|
191
|
+
items.add(rpath, f"# owning group: {params['group']} (via image {instance.image}); "
|
|
192
|
+
f"launch parameters recorded in meta-state/launch-params.yaml (N26)")
|
|
193
|
+
items.add_list(rpath, render_module_call(
|
|
194
|
+
f"instance_{label}", src, self._with_ephemeral_count(instance, self._module_args(ctx, rtb, instance, params)),
|
|
195
|
+
providers=bindings))
|
|
196
|
+
# the launch script beside the root: uploaded into the container at
|
|
197
|
+
# creation, run through the session after the apply
|
|
198
|
+
tpath = rpath.parent / self._launch_script_template_name(label)
|
|
199
|
+
items.add(tpath, user_data_template(params))
|
|
200
|
+
return items
|
|
201
|
+
|
|
202
|
+
def _module_args(self, ctx, rtb, instance: Instance, params: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
203
|
+
from cs_image_system.base.lineage import config_tags, pinned_instance_build
|
|
204
|
+
label = utils.super_safe_name(instance.get_name())
|
|
205
|
+
name = str(instance.get_name())
|
|
206
|
+
hostname = str((params or {}).get("hostname") or name)
|
|
207
|
+
args: dict[str, Any] = {"name": name, "hostname": hostname}
|
|
208
|
+
pinned = pinned_instance_build(ctx, instance) if hasattr(ctx, "meta_state") else None
|
|
209
|
+
psi = (ctx.get_provider_specific_image(instance.image, rtb.get_name()) if rtb and instance.image else None)
|
|
210
|
+
if pinned:
|
|
211
|
+
args["image"] = pinned
|
|
212
|
+
elif psi is not None and psi.is_resolved():
|
|
213
|
+
args["image"] = psi.identifier
|
|
214
|
+
elif psi is not None:
|
|
215
|
+
# built later: the per-instance variable (filled by finalization
|
|
216
|
+
# from the packer manifest); the series' floating tag is the fallback
|
|
217
|
+
args["image"] = f"var.{self._image_var(label)}"
|
|
218
|
+
floating = getattr(psi, "floating_tag", None)
|
|
219
|
+
tag = floating() if callable(floating) else None
|
|
220
|
+
if tag:
|
|
221
|
+
args["image_tag"] = tag
|
|
222
|
+
else:
|
|
223
|
+
log.warning(f"No provider-specific image for image {instance.image!r} of instance "
|
|
224
|
+
f"{instance.get_name()}; the module call will not resolve an image")
|
|
225
|
+
if rtb:
|
|
226
|
+
mt_name = str(getattr(instance, "machine_type", "") or "") or str(rtb.get_default_machine_type() or "")
|
|
227
|
+
get_types = getattr(rtb.model, "get_machine_types", None)
|
|
228
|
+
types: dict[str, Any] = cast(dict[str, Any], get_types()) if callable(get_types) else {}
|
|
229
|
+
mt = types.get(mt_name) if mt_name else None
|
|
230
|
+
if mt_name and types and mt is None:
|
|
231
|
+
raise ValueError(f"instance {name}: machine_type {mt_name!r} is not one of runtime "
|
|
232
|
+
f"{rtb.get_name()}'s machine_types ({', '.join(sorted(types))})")
|
|
233
|
+
if mt is not None:
|
|
234
|
+
cpus = cpus_as_read_back(mt.get_cpus())
|
|
235
|
+
if cpus:
|
|
236
|
+
args["cpus"] = cpus
|
|
237
|
+
memory = memory_mb(mt.get_memory())
|
|
238
|
+
if memory:
|
|
239
|
+
args["memory"] = memory
|
|
240
|
+
networking = getattr(rtb.model, "networking", None)
|
|
241
|
+
network = getattr(networking, "network", None) if networking else None
|
|
242
|
+
if network:
|
|
243
|
+
args["network"] = str(network)
|
|
244
|
+
labels = {str(k): str(v) for k, v in {**(instance.get_tags() or {}), **config_tags(ctx)}.items()} # stage 93
|
|
245
|
+
labels["csis_instance"] = name
|
|
246
|
+
labels["csis_generation"] = generation_of(hostname, name)
|
|
247
|
+
args["labels"] = labels
|
|
248
|
+
if params is not None:
|
|
249
|
+
args.update(self._launch_args(ctx, label, params))
|
|
250
|
+
return args
|
|
251
|
+
|
|
252
|
+
def _launch_args(self, ctx, label: str, params: dict[str, Any]) -> dict[str, Any]:
|
|
253
|
+
"""The launch script (templatefile over the recorded launch parameters,
|
|
254
|
+
the gid by the group builder's expression) and the volume mounts, each
|
|
255
|
+
by remote-state reference to the storage root's outputs."""
|
|
256
|
+
out: dict[str, Any] = {}
|
|
257
|
+
group = params.get("group")
|
|
258
|
+
gid = self._gid_expression_for(group) # stage 75 step 3: the group builder writes it
|
|
259
|
+
template_vars: dict[str, Any] = {}
|
|
260
|
+
if gid is not None:
|
|
261
|
+
template_vars["group_gid"] = HclRaw(gid)
|
|
262
|
+
volumes: dict[str, Any] = {}
|
|
263
|
+
for m in params.get("mounts", []):
|
|
264
|
+
sb = m.get("builder") or self._storage_builder_name(m["storage"])
|
|
265
|
+
if not sb:
|
|
266
|
+
continue
|
|
267
|
+
ref = (f"data.terraform_remote_state.{utils.super_safe_name(sb)}"
|
|
268
|
+
f".outputs.storage_{utils.super_safe_name(m['storage'])}")
|
|
269
|
+
if m.get("platform_mounted"):
|
|
270
|
+
volumes[m["storage"]] = {"volume_name": HclRaw(f"{ref}.volume_name"),
|
|
271
|
+
"container_path": str(m["mount_point"])}
|
|
272
|
+
template_vars["efs"] = {}
|
|
273
|
+
template_vars["filestore"] = {}
|
|
274
|
+
template_vars["ebs"] = {}
|
|
275
|
+
# an OPA group on a container runtime is refused at validation (decision
|
|
276
|
+
# 3), so no enrollment reaches here; the variable keeps the template whole
|
|
277
|
+
template_vars[ENROLLMENT_TOKEN_VARIABLE] = ""
|
|
278
|
+
tpl = self._launch_script_template_name(label)
|
|
279
|
+
out["launch_script"] = HclRaw(f'templatefile("${{path.module}}/{tpl}", {hcl_expr(template_vars, 2)})')
|
|
280
|
+
if volumes:
|
|
281
|
+
out["volumes"] = volumes
|
|
282
|
+
return out
|
|
283
|
+
|
|
284
|
+
def _attachment_address(self, instance_name: str, storage: str) -> str | None:
|
|
285
|
+
return None # a volume mount is an attribute of docker_container; changing it re-creates
|
|
286
|
+
|
|
287
|
+
def _module_address(self, instance_name: str) -> str:
|
|
288
|
+
return f"module.instance_{utils.super_safe_name(instance_name)}"
|
|
289
|
+
|
|
290
|
+
def _replacements(self) -> list[str]:
|
|
291
|
+
ctx = self._get_context()
|
|
292
|
+
from cs_image_system.base.lineage import pending_instance_replacements
|
|
293
|
+
names = pending_instance_replacements(ctx, self._instances) # upgrades + follow (stage 9)
|
|
294
|
+
return [f"{self._module_address(n)}.docker_container.this" for n in sorted(names)]
|
|
295
|
+
|
|
296
|
+
def _own_resources_to_let_go(self) -> list[str]:
|
|
297
|
+
return [] # the root makes nothing of its own beside the containers
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Mykel Alvis <mykelalvis@infrastructurebuilder.org>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""The container instance and volume builder models (stage 103 branch 2).
|
|
6
|
+
|
|
7
|
+
The same shape as the clouds' tofu models: one terraform root per builder,
|
|
8
|
+
a state manager by reference (the runtime's, else the default), and the
|
|
9
|
+
runtime builder supplies the daemon's address through the environment of
|
|
10
|
+
every tofu process the root runs.
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from dataclasses import field
|
|
15
|
+
|
|
16
|
+
from cs_image_system.contract.model_config import CSIS_MODEL_CONFIG
|
|
17
|
+
from pydantic.dataclasses import dataclass # stage 23: validation at construction
|
|
18
|
+
|
|
19
|
+
from cs_image_system.base.models.module_variables import ModuleVariables
|
|
20
|
+
from cs_image_system.tf_ebs_instance_plugin.tf_instance_models import TofuInstanceBuilderModel
|
|
21
|
+
from cs_image_system.tf_ebs_instance_plugin.tf_storage_models import TofuStorageBuilderModel
|
|
22
|
+
|
|
23
|
+
TOFU_DOCKER: str = "tofu-docker"
|
|
24
|
+
TF_DOCKER_VOLUME: str = "tf-docker-volume"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(kw_only=True, config=CSIS_MODEL_CONFIG)
|
|
28
|
+
class TofuDockerInstanceBuilderModel(TofuInstanceBuilderModel):
|
|
29
|
+
"""An instance root on a docker runtime: one ``docker_container`` per
|
|
30
|
+
instance through tfmodules/docker_container."""
|
|
31
|
+
type = TOFU_DOCKER
|
|
32
|
+
|
|
33
|
+
@classmethod
|
|
34
|
+
def csis_name(cls) -> str:
|
|
35
|
+
return TOFU_DOCKER
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(kw_only=True, config=CSIS_MODEL_CONFIG)
|
|
39
|
+
class DockerVolumeVariables(ModuleVariables):
|
|
40
|
+
"""tfmodules/docker_volume: the volume driver and its options, when not
|
|
41
|
+
the daemon's ``local`` default; ``tags`` are emitted as labels."""
|
|
42
|
+
driver: str | None = None
|
|
43
|
+
driver_opts: dict[str, str] | None = None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(kw_only=True, config=CSIS_MODEL_CONFIG)
|
|
47
|
+
class TofuDockerVolumeStorageBuilderModel(TofuStorageBuilderModel):
|
|
48
|
+
"""A storage root on a docker runtime: one named volume per storage
|
|
49
|
+
through tfmodules/docker_volume. Capability type ``volume``: many
|
|
50
|
+
containers may mount one, it is POSIX, it lives in no zone, and the
|
|
51
|
+
daemon mounts it at the declared path before the first command."""
|
|
52
|
+
type = TF_DOCKER_VOLUME
|
|
53
|
+
variables: DockerVolumeVariables = field(default_factory=DockerVolumeVariables)
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
def csis_name(cls) -> str:
|
|
57
|
+
return TF_DOCKER_VOLUME
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Mykel Alvis <mykelalvis@infrastructurebuilder.org>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""The volume storage builder (stage 103 branch 2).
|
|
6
|
+
|
|
7
|
+
One ``docker_volume`` per storage through tfmodules/docker_volume, on the
|
|
8
|
+
``kreuzwerker/docker`` provider, reusing the clouds' tofu storage machinery
|
|
9
|
+
(one terraform root per builder, a module call per storage, the storage
|
|
10
|
+
state machine, the apply gate). Capability type ``volume``: many containers
|
|
11
|
+
may mount one, it is POSIX (the per-group subtree is made and chgrp'ed at
|
|
12
|
+
first launch by the launch script), it lives in no zone, and the daemon
|
|
13
|
+
mounts it at the declared path before the container's first command
|
|
14
|
+
(``platform_mounts``). Archive is a later item: a volume has no snapshot.
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import json
|
|
19
|
+
import logging
|
|
20
|
+
import subprocess
|
|
21
|
+
from typing import Any, TypeVar, cast
|
|
22
|
+
|
|
23
|
+
from cs_image_system.base.basic.builder_base_storage import CARDINALITY_MANY
|
|
24
|
+
from cs_image_system.base.models.executable import ExecutableModel
|
|
25
|
+
from cs_image_system.base.models.storage import Storage
|
|
26
|
+
from cs_image_system.contract.assets import AssetSet
|
|
27
|
+
from cs_image_system.contract.lifecycle import ExecutionLifecyclePhase
|
|
28
|
+
from cs_image_system.docker_runtime.docker_names import tag_name
|
|
29
|
+
from cs_image_system.hashicorp_utils.collector import TerraformCollector
|
|
30
|
+
from cs_image_system.tf_ebs_instance_plugin.tf_storage_builder import TofuStorageBuilder, storage_groups
|
|
31
|
+
|
|
32
|
+
from .tf_docker_models import TF_DOCKER_VOLUME, TofuDockerVolumeStorageBuilderModel
|
|
33
|
+
|
|
34
|
+
log = logging.getLogger(__name__)
|
|
35
|
+
|
|
36
|
+
Q = TypeVar("Q", bound=TofuDockerVolumeStorageBuilderModel)
|
|
37
|
+
DOCKER_PROVIDER_SOURCE = "kreuzwerker/docker"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def volume_name(storage_name: str) -> str:
|
|
41
|
+
"""A docker volume name from a storage's name (letters, digits, ``_``,
|
|
42
|
+
``.`` and ``-``; the same rule as a tag)."""
|
|
43
|
+
return tag_name(storage_name)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class TofuDockerVolumeStorageBuilder(TofuStorageBuilder[Q]):
|
|
47
|
+
@classmethod
|
|
48
|
+
def csis_name(cls) -> str:
|
|
49
|
+
return TF_DOCKER_VOLUME
|
|
50
|
+
|
|
51
|
+
@classmethod
|
|
52
|
+
def capability_type(cls) -> str:
|
|
53
|
+
return "volume"
|
|
54
|
+
|
|
55
|
+
def attachment_cardinality(self) -> str:
|
|
56
|
+
return CARDINALITY_MANY
|
|
57
|
+
|
|
58
|
+
def is_zonal(self) -> bool:
|
|
59
|
+
return False # a daemon has no zones
|
|
60
|
+
|
|
61
|
+
def platform_mounts(self) -> bool:
|
|
62
|
+
return True # the daemon mounts it at the declared path before the first command
|
|
63
|
+
|
|
64
|
+
def base_image_prerequisites(self, os_family: str | None = None) -> list[str]:
|
|
65
|
+
return [f"# storage type 'volume' declared: no prerequisites to bake ({self.get_name()})"]
|
|
66
|
+
|
|
67
|
+
def module_dirname(self) -> str:
|
|
68
|
+
return "docker_volume"
|
|
69
|
+
|
|
70
|
+
# ------------------------------------------------------------ the daemon
|
|
71
|
+
def _runtime(self):
|
|
72
|
+
return self._get_context().runtime_builders.get(self.model.get_runtime_provider(), None)
|
|
73
|
+
|
|
74
|
+
def get_executable_copy(self) -> ExecutableModel:
|
|
75
|
+
"""Every tofu process of this root reaches the runtime's daemon (the
|
|
76
|
+
instance builder's rule)."""
|
|
77
|
+
e = super().get_executable_copy()
|
|
78
|
+
env_of = getattr(self._runtime(), "tool_environment", None)
|
|
79
|
+
if callable(env_of):
|
|
80
|
+
extra = cast(dict[str, str], env_of())
|
|
81
|
+
e.environment = {**dict(e.environment or {}), **extra}
|
|
82
|
+
return e
|
|
83
|
+
|
|
84
|
+
def _docker(self, *args: str) -> subprocess.CompletedProcess[str]:
|
|
85
|
+
"""The runtime's own docker call when it has one (its binary, its
|
|
86
|
+
daemon), else ``docker`` from PATH (a stand-in runtime in a test)."""
|
|
87
|
+
rtb = self._runtime()
|
|
88
|
+
call = getattr(rtb, "_docker", None)
|
|
89
|
+
if callable(call):
|
|
90
|
+
return cast(subprocess.CompletedProcess[str], call(*args, check=False))
|
|
91
|
+
return subprocess.run(["docker", *args], capture_output=True, text=True, check=False)
|
|
92
|
+
|
|
93
|
+
def generate_items_before(self, phase: ExecutionLifecyclePhase) -> AssetSet:
|
|
94
|
+
items = AssetSet()
|
|
95
|
+
if phase != ExecutionLifecyclePhase.STORAGE_GENERATION or not self._has_work():
|
|
96
|
+
return items
|
|
97
|
+
rpath = self.get_path_for_phase(phase, suffix=".tf")
|
|
98
|
+
items = items.with_default_path(rpath)
|
|
99
|
+
items.add(f"# Terraform configuration for container volumes generated by "
|
|
100
|
+
f"{self.__class__.__name__} ({self.name})")
|
|
101
|
+
items.add("# The daemon's address is not here: every tofu process of this root carries the")
|
|
102
|
+
items.add("# runtime's DOCKER_HOST or DOCKER_CONTEXT in its environment (stage 103 branch 2).")
|
|
103
|
+
col = TerraformCollector()
|
|
104
|
+
ws = self.name
|
|
105
|
+
if self.model.required_plugins:
|
|
106
|
+
for plugin in self.model.required_plugins:
|
|
107
|
+
col.require_provider(ws, plugin.name, source=getattr(plugin, "source", None),
|
|
108
|
+
version=getattr(plugin, "version", None))
|
|
109
|
+
else:
|
|
110
|
+
col.require_provider(ws, "docker", source=DOCKER_PROVIDER_SOURCE)
|
|
111
|
+
col.configure_provider(ws, "docker", {})
|
|
112
|
+
col.bind_workspace(ws, self.model.state_configuration, self.runtime_state_configuration()) # stage 46: own, runtime's, default
|
|
113
|
+
for identity_ws in sorted(self.identity_workspaces()):
|
|
114
|
+
col.reference_remote_state(ws, producer_workspace=identity_ws)
|
|
115
|
+
items.add_list(col.generate_terraform_block(ws))
|
|
116
|
+
items.add_list(col.generate_provider_blocks(ws))
|
|
117
|
+
remote_lines = col.generate_remote_state_datasources(ws)
|
|
118
|
+
if remote_lines:
|
|
119
|
+
items.add_list(remote_lines)
|
|
120
|
+
backend_lines = col.generate_backend_config(ws)
|
|
121
|
+
if backend_lines:
|
|
122
|
+
items.add_list(self._backend_config_path(phase), backend_lines)
|
|
123
|
+
return items
|
|
124
|
+
|
|
125
|
+
def _labels(self, storage: Storage) -> dict[str, str]:
|
|
126
|
+
from cs_image_system.base.lineage import config_tags
|
|
127
|
+
merged = getattr(self.model, "variables", None)
|
|
128
|
+
base = merged.merged_tags(storage.tags) if merged is not None else dict(storage.tags or {})
|
|
129
|
+
labels = {str(k): str(v) for k, v in base.items()}
|
|
130
|
+
labels["csis_storage"] = storage.get_name()
|
|
131
|
+
get_ctx: Any = getattr(self, "_get_context", None) # a stand-in without a context gets no id
|
|
132
|
+
if callable(get_ctx):
|
|
133
|
+
labels.update(config_tags(cast(Any, get_ctx()))) # stage 93: the volume carries the id
|
|
134
|
+
for g in sorted(storage_groups(storage)):
|
|
135
|
+
labels[f"csis_group_{g}"] = "true"
|
|
136
|
+
return labels
|
|
137
|
+
|
|
138
|
+
def module_args(self, storage: Storage) -> dict[str, Any]:
|
|
139
|
+
args: dict[str, Any] = dict(self.model.variables.as_module_args()) # driver, driver_opts when declared
|
|
140
|
+
args["name"] = volume_name(storage.get_name())
|
|
141
|
+
args["labels"] = self._labels(storage)
|
|
142
|
+
return args
|
|
143
|
+
|
|
144
|
+
# ------------------------------------------------------- state query
|
|
145
|
+
def _lookup(self, storage: Storage) -> dict[str, Any] | None:
|
|
146
|
+
"""``docker volume inspect``: present with its driver, mountpoint and
|
|
147
|
+
labels; absent when the daemon has no such volume; another
|
|
148
|
+
configuration's volume of our name reads as elsewhere (stage 93)."""
|
|
149
|
+
name = volume_name(storage.get_name())
|
|
150
|
+
res = self._docker("volume", "inspect", name)
|
|
151
|
+
if res.returncode != 0:
|
|
152
|
+
err = (res.stderr or "").lower()
|
|
153
|
+
if "no such volume" in err or "not found" in err:
|
|
154
|
+
return None
|
|
155
|
+
raise RuntimeError(f"docker volume inspect {name}: {(res.stderr or '').strip()[-300:]}")
|
|
156
|
+
data = json.loads(res.stdout or "[]")
|
|
157
|
+
if not data:
|
|
158
|
+
return None
|
|
159
|
+
info = dict(data[0])
|
|
160
|
+
labels = {str(k): str(v) for k, v in dict(info.get("Labels") or {}).items()}
|
|
161
|
+
from cs_image_system.base.lineage import belongs_to_another_configuration, owner_of
|
|
162
|
+
if belongs_to_another_configuration(self._get_context(), labels):
|
|
163
|
+
return {"present": False, "elsewhere": owner_of(labels), "what": "a volume"}
|
|
164
|
+
return {"id": str(info.get("Name") or name), "state": "active", "driver": str(info.get("Driver") or ""),
|
|
165
|
+
"mountpoint": str(info.get("Mountpoint") or ""), "tags": labels}
|
|
166
|
+
|
|
167
|
+
def retag_storage(self, storage: Storage, tags: dict[str, str]) -> bool:
|
|
168
|
+
"""A volume's labels are fixed when it is created and a change would
|
|
169
|
+
replace it WITH ITS DATA: relabel reports and nothing re-creates."""
|
|
170
|
+
raise NotImplementedError(
|
|
171
|
+
f"volume {volume_name(storage.get_name())}: a volume's labels are fixed when it is created; "
|
|
172
|
+
f"it would carry {', '.join(f'{k}={v}' for k, v in sorted(tags.items()))} only as a new volume")
|
|
173
|
+
|
|
174
|
+
def transition_actions(self, storage: Storage, from_state: str | None, to_state: str) -> list[ExecutableModel]:
|
|
175
|
+
"""``destroyed``: terraform removes the volume, and its data goes with
|
|
176
|
+
it (N19: wiped clean). Archive is a later item."""
|
|
177
|
+
return []
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: cs-image-system-tf-docker-plugin
|
|
3
|
+
Version: 0.1.6
|
|
4
|
+
Summary: The OpenTofu plugin for a container runtime: containers and volumes on a Docker Engine API daemon as module calls
|
|
5
|
+
Project-URL: Repository, https://github.com/infrastructurebuilder/cs-image-system-3
|
|
6
|
+
Project-URL: Documentation, https://github.com/infrastructurebuilder/cs-image-system-3/blob/develop/docs/OPERATIONS.md
|
|
7
|
+
Project-URL: Package README, https://github.com/infrastructurebuilder/cs-image-system-3/blob/develop/packages/tf-docker-plugin/README.md
|
|
8
|
+
Author-email: Mykel Alvis <mykelalvis@infrastructurebuilder.org>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Python: >=3.13
|
|
12
|
+
Requires-Dist: cs-image-system-base==0.1.6
|
|
13
|
+
Requires-Dist: cs-image-system-contract==0.1.6
|
|
14
|
+
Requires-Dist: cs-image-system-docker-runtime-plugin==0.1.6
|
|
15
|
+
Requires-Dist: cs-image-system-hashicorp-utils==0.1.6
|
|
16
|
+
Requires-Dist: cs-image-system-tf-ebs-instance-plugin==0.1.6
|
|
17
|
+
Requires-Dist: pydantic>=2.13
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
<!--
|
|
21
|
+
SPDX-FileCopyrightText: 2026 Mykel Alvis <mykelalvis@infrastructurebuilder.org>
|
|
22
|
+
|
|
23
|
+
SPDX-License-Identifier: Apache-2.0
|
|
24
|
+
-->
|
|
25
|
+
|
|
26
|
+
# cs-image-system-tf-docker-plugin
|
|
27
|
+
|
|
28
|
+
The OpenTofu plugin for a container runtime (stage 103, branch 2): the
|
|
29
|
+
instance builder `tofu-docker` and the storage builder `tf-docker-volume`.
|
|
30
|
+
Each emits one terraform root on the `kreuzwerker/docker` provider against a
|
|
31
|
+
release-owned module (`tfmodules/docker_container`, `tfmodules/docker_volume`,
|
|
32
|
+
which every starter carries), exactly as the clouds' tofu plugins do against
|
|
33
|
+
theirs. The runtime is the `docker` runtime of
|
|
34
|
+
[cs-image-system-docker-runtime-plugin](../docker-runtime-plugin/README.md):
|
|
35
|
+
a durable host running a daemon that speaks the Docker Engine API.
|
|
36
|
+
|
|
37
|
+
Three things are different from a cloud, and each is a decision recorded in
|
|
38
|
+
the stage:
|
|
39
|
+
|
|
40
|
+
- **The power state is the operator's.** A container is declared with
|
|
41
|
+
`must_run = false`, so the next apply leaves a stopped container stopped
|
|
42
|
+
(proved against the provider before anything else in the branch), and
|
|
43
|
+
with the restart policy `unless-stopped`, so a daemon restart brings back
|
|
44
|
+
what was running and nothing else.
|
|
45
|
+
- **No first boot.** A cloud runs the launch script from user data. A
|
|
46
|
+
container has no user data: the root uploads the same rendered script
|
|
47
|
+
into the container when it is created (`/var/lib/csis/launch.sh`), and
|
|
48
|
+
the system runs it through `docker exec` after the apply, once, the way
|
|
49
|
+
it runs the accounts script. Its last act writes
|
|
50
|
+
`/var/lib/csis/launch-applied`, which the verification reads.
|
|
51
|
+
- **Labels are fixed at creation.** A container's and a volume's labels
|
|
52
|
+
cannot change in place; `lineage relabel` reports what a re-create would
|
|
53
|
+
set and re-creates nothing.
|
|
54
|
+
|
|
55
|
+
## What it registers
|
|
56
|
+
|
|
57
|
+
One entry point under `cs_image_system.plugins.instance`
|
|
58
|
+
(`tf-docker-plugin`), registering two `type:` keys:
|
|
59
|
+
|
|
60
|
+
| `type:` | Model | Builder | Classified as |
|
|
61
|
+
|---|---|---|---|
|
|
62
|
+
| `tofu-docker` | `TofuDockerInstanceBuilderModel` | `TofuDockerInstanceBuilder` | an instance builder |
|
|
63
|
+
| `tf-docker-volume` | `TofuDockerVolumeStorageBuilderModel` | `TofuDockerVolumeStorageBuilder` | a storage builder |
|
|
64
|
+
|
|
65
|
+
Both subclass the AWS plugin's tofu bases (`TofuInstanceBuilder`,
|
|
66
|
+
`TofuStorageBuilder`), so the apply gate, the decommission whitelist, the
|
|
67
|
+
ephemeral sequence, the storage state machine and the state query are the
|
|
68
|
+
shared machinery.
|
|
69
|
+
|
|
70
|
+
## Models
|
|
71
|
+
|
|
72
|
+
### `TofuDockerInstanceBuilderModel` (`tofu-docker`)
|
|
73
|
+
|
|
74
|
+
The fields of every tofu instance builder: `runtime` (a `docker` runtime),
|
|
75
|
+
`executable` (the `cfg/executables.yml` entry for tofu), `state_configuration`
|
|
76
|
+
(the root's state manager; `default` inherits the runtime's, else the
|
|
77
|
+
default), `required_plugins` (the terraform providers; with none declared the
|
|
78
|
+
root requires `kreuzwerker/docker` unpinned). Nothing docker-specific is
|
|
79
|
+
declared on the builder: the daemon's address and the machine types live on
|
|
80
|
+
the runtime.
|
|
81
|
+
|
|
82
|
+
### `TofuDockerVolumeStorageBuilderModel` (`tf-docker-volume`)
|
|
83
|
+
|
|
84
|
+
The same universal fields, plus `variables` (a `DockerVolumeVariables`):
|
|
85
|
+
`driver` (the volume driver; the daemon's `local` when unset), `driver_opts`
|
|
86
|
+
(its options) and `tags`, emitted as labels under the storage item's own.
|
|
87
|
+
|
|
88
|
+
### The runtime builder the plugin reads
|
|
89
|
+
|
|
90
|
+
`host` or `context` (the daemon's address, which rides in the environment of
|
|
91
|
+
every tofu process the roots run, never in a `.tf` file), `networking.network`
|
|
92
|
+
(the network every container joins, by name), `machine_types` (a name to
|
|
93
|
+
`{cpus, memory}`; an instance's `machine_type` picks one, the runtime's
|
|
94
|
+
`default_machine_type` otherwise) and `repository` (where the floating tag
|
|
95
|
+
of a deferred image lives).
|
|
96
|
+
|
|
97
|
+
## The builder
|
|
98
|
+
|
|
99
|
+
### `TofuDockerInstanceBuilder` (phase `instance-generation`)
|
|
100
|
+
|
|
101
|
+
One `module "instance_<label>"` call per instance against
|
|
102
|
+
`tfmodules/docker_container`:
|
|
103
|
+
|
|
104
|
+
- `name` is the instance's declared name (a container's name is unique on a
|
|
105
|
+
daemon, and every instance hook finds the container by it); `hostname` is
|
|
106
|
+
the canonical name `<name>-NNN` the launch parameters decide;
|
|
107
|
+
- `image` is the pinned build (an image id, `sha256:...`), else the resolved
|
|
108
|
+
provider-specific image, else the per-instance variable `<label>_image`
|
|
109
|
+
that finalization fills from the packer manifest, with `image_tag` (the
|
|
110
|
+
series' floating tag) as the module's fallback through a `docker_image`
|
|
111
|
+
data source;
|
|
112
|
+
- `cpus` and `memory` are the machine type's limits (`cpus` rendered with a
|
|
113
|
+
decimal point, `1.0`, because that is how the provider reads it back;
|
|
114
|
+
memory in MB from docker's own spelling, `4g`);
|
|
115
|
+
- `labels` carry the configuration id (`csis_config`), the instance
|
|
116
|
+
(`csis_instance`) and its generation (`csis_generation`); the module adds
|
|
117
|
+
`csis_build` from the image it resolved;
|
|
118
|
+
- `volumes` map each attached storage to `{volume_name, container_path}`,
|
|
119
|
+
the name by remote-state reference to the storage root's outputs;
|
|
120
|
+
- `launch_script` is `templatefile` over `launch-<label>.sh.tftpl`, the same
|
|
121
|
+
script `launch_params.user_data_template` renders for the clouds, with the
|
|
122
|
+
group's gid by the group builder's expression (a posix group's gid is a
|
|
123
|
+
number of the configuration). On this runtime the script sets no hostname
|
|
124
|
+
(the container was created with it) and, for a volume, formats and mounts
|
|
125
|
+
nothing: the daemon mounted it, and the script makes the group's subtree
|
|
126
|
+
and sets its ownership and mode.
|
|
127
|
+
|
|
128
|
+
The module declares `must_run = false`, `start = true`, `init = true`, the
|
|
129
|
+
restart policy `unless-stopped`, and ignores later changes to `image`,
|
|
130
|
+
`labels`, `upload` and `memory_swap` (the daemon computes the last from
|
|
131
|
+
`memory`). An upgrade is a `-replace` of `module.instance_<label>.docker_container.this`
|
|
132
|
+
through the gate, as on the clouds; a decommission destroys the module.
|
|
133
|
+
|
|
134
|
+
Every tofu process the root runs (`fmt`, `init`, `validate`, `plan`, `apply`)
|
|
135
|
+
carries the runtime's `DOCKER_HOST` or `DOCKER_CONTEXT` (and the TLS pair)
|
|
136
|
+
in its environment; the runner script renders them as an assignment prefix
|
|
137
|
+
on the line, an ENC `host` as a `cs-image-system decrypt` call. The
|
|
138
|
+
`provider "docker"` block is empty.
|
|
139
|
+
|
|
140
|
+
### `TofuDockerVolumeStorageBuilder` (phase `storage-generation`)
|
|
141
|
+
|
|
142
|
+
One `module "storage_<label>"` call per live storage against
|
|
143
|
+
`tfmodules/docker_volume`: the volume's name (the storage's name as the
|
|
144
|
+
daemon allows it), the driver and its options when declared, and labels
|
|
145
|
+
(`csis_storage`, `csis_config`, one `csis_group_<group>` per allowed group,
|
|
146
|
+
the builder's and the item's tags). Capability type `volume`: many
|
|
147
|
+
containers may attach one, it is POSIX, it is not zonal (the zone comparison
|
|
148
|
+
has nothing to compare), and `platform_mounts` is true. A `destroyed` storage
|
|
149
|
+
is removed with its data (N19); the volume is not archivable yet (a volume
|
|
150
|
+
has no snapshot; a `tar` from a throwaway container is the obvious later
|
|
151
|
+
shape).
|
|
152
|
+
|
|
153
|
+
### The instance hooks, on the runtime
|
|
154
|
+
|
|
155
|
+
The hooks the core calls after the apply are the docker runtime's
|
|
156
|
+
(`docker_runtime_builders.py`): the power state (`running`; `exited` and
|
|
157
|
+
`created` as stopped; `paused` as suspended; `restarting` as starting;
|
|
158
|
+
absent), `start_instance` and `stop_instance`, the identity (the container
|
|
159
|
+
id is the provider id, so a re-create is a new generation), the booted image
|
|
160
|
+
(`.Image`, the build id itself), `verify_instance` by exec (the launch
|
|
161
|
+
marker, each declared mount point in `/proc/mounts`, the booted image),
|
|
162
|
+
`run_session_command` (`docker exec -i -u root <name> bash -s`), no
|
|
163
|
+
`ssh_proxy_command` (login is by exec), `inventory` by the configuration's
|
|
164
|
+
label, and `instance_tags`/`retag_instance` (read; refuse to change).
|
|
165
|
+
|
|
166
|
+
## Emission
|
|
167
|
+
|
|
168
|
+
For an instance `docker-test` on builder `tofu-docker-local`, the root
|
|
169
|
+
`generated/instance-image/tofu-docker-local/instance-generation/` holds
|
|
170
|
+
`instance-generation.tf` (the `terraform` block requiring `kreuzwerker/docker`,
|
|
171
|
+
an empty aliased provider, the variables, the remote-state data sources, the
|
|
172
|
+
backend file beside it), `instance-docker-test.tf` (the module call) and
|
|
173
|
+
`launch-docker_test.sh.tftpl` (the script). The storage root
|
|
174
|
+
`generated/storage/<builder>/storage-generation/` holds the volume module
|
|
175
|
+
calls and one `output "storage_<label>"` per volume for the instance root
|
|
176
|
+
to read.
|
|
177
|
+
|
|
178
|
+
## Example configuration
|
|
179
|
+
|
|
180
|
+
```yaml
|
|
181
|
+
# cfg/instance-builders.yml
|
|
182
|
+
instance_builders:
|
|
183
|
+
- name: tofu-docker
|
|
184
|
+
type: tofu-docker
|
|
185
|
+
runtime: docker-host
|
|
186
|
+
executable: open-tofu-1
|
|
187
|
+
state_configuration: local-dev
|
|
188
|
+
required_plugins:
|
|
189
|
+
- name: docker
|
|
190
|
+
source: kreuzwerker/docker
|
|
191
|
+
version: ">= 3.0.0"
|
|
192
|
+
|
|
193
|
+
# cfg/storage-builders.yml
|
|
194
|
+
storage_builders:
|
|
195
|
+
- name: docker-volumes
|
|
196
|
+
type: tf-docker-volume
|
|
197
|
+
executable: open-tofu-1
|
|
198
|
+
runtime: docker-host
|
|
199
|
+
state_configuration: local-dev
|
|
200
|
+
variables:
|
|
201
|
+
tags:
|
|
202
|
+
project: example
|
|
203
|
+
|
|
204
|
+
# storages/volumes.yaml
|
|
205
|
+
storages:
|
|
206
|
+
- name: scratch
|
|
207
|
+
type: docker-volumes
|
|
208
|
+
runtime: docker-host
|
|
209
|
+
mount_point: /mnt/scratch
|
|
210
|
+
groups: [pxgroup]
|
|
211
|
+
|
|
212
|
+
# instances/containers.yaml
|
|
213
|
+
instances:
|
|
214
|
+
- name: docker-test
|
|
215
|
+
image: imgfile-docker # a posix-owned image baked on docker-host
|
|
216
|
+
runtime: docker-host
|
|
217
|
+
type: tofu-docker
|
|
218
|
+
machine_type: small # one of the runtime's machine_types
|
|
219
|
+
storages:
|
|
220
|
+
- name: scratch
|
|
221
|
+
mount_point: /mnt/scratch
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
The base image the instance image descends from declares `storage_types:
|
|
225
|
+
[volume]` (N4: a type must be declared to be attached), and the image's
|
|
226
|
+
group is a posix group (an OPA group on a docker runtime is refused at
|
|
227
|
+
validation).
|
|
228
|
+
|
|
229
|
+
## Prerequisites and integration
|
|
230
|
+
|
|
231
|
+
- A `docker` runtime (the docker runtime plugin) whose daemon the operator's
|
|
232
|
+
shell can reach, and the `docker` CLI it names in `cfg/executables.yml`.
|
|
233
|
+
- `tofu` in `cfg/executables.yml`, and the `kreuzwerker/docker` provider,
|
|
234
|
+
which `tofu init` downloads (version 3.0.0 or later; 4.6.0 proved it).
|
|
235
|
+
- A state manager for the roots: the runtime's `state_configuration`, often
|
|
236
|
+
`local` for a tree with no cloud.
|
|
237
|
+
- The modules `tfmodules/docker_container` and `tfmodules/docker_volume`
|
|
238
|
+
beside the configuration root (`module_source_base`); every starter carries
|
|
239
|
+
them.
|
|
240
|
+
- `bash` on the baked image (the session runs `bash -s`), which the docker
|
|
241
|
+
runtime's settle step installs with `sudo` and `python3` where a vendor
|
|
242
|
+
container lacks them.
|
|
243
|
+
|
|
244
|
+
The plugin depends on `cs-image-system-tf-ebs-instance-plugin` (the tofu
|
|
245
|
+
bases) and `cs-image-system-docker-runtime-plugin` (the names and the
|
|
246
|
+
runtime's hooks).
|
|
247
|
+
|
|
248
|
+
## Configuration reference
|
|
249
|
+
|
|
250
|
+
Builder entries (`cfg/instance-builders.yml`, `cfg/storage-builders.yml`):
|
|
251
|
+
`name`, `type` (`tofu-docker` | `tf-docker-volume`), `runtime` (a `docker`
|
|
252
|
+
runtime), `executable`, `state_configuration`, `required_plugins[]`
|
|
253
|
+
(`{name, source, version}`), `is_default`, `description`, `tags`; the volume
|
|
254
|
+
builder's `variables: {driver, driver_opts, tags}`.
|
|
255
|
+
|
|
256
|
+
The instance item (`instances/*.yaml`, `type:` a `tofu-docker` builder):
|
|
257
|
+
`name` (the container's name and the hostname label), `image`, `runtime`,
|
|
258
|
+
`machine_type` (one of the runtime's `machine_types`; empty = its default),
|
|
259
|
+
`storages[]` (`{name, mount_point}`), `image_policy`, `ephemeral`,
|
|
260
|
+
`on_failure`, `teardown_after`, `userdata` (lines appended to the launch
|
|
261
|
+
script), `tags` (labels, fixed at creation). `availability_zone` is accepted
|
|
262
|
+
and compares with nothing (a daemon has no zones).
|
|
263
|
+
|
|
264
|
+
The storage item (`storages/*.yaml`, `type:` a `tf-docker-volume` builder):
|
|
265
|
+
`name`, `runtime`, `mount_point`, `groups[]`, `share_mode`, `public_read`,
|
|
266
|
+
`state` (`active` | `destroyed`; `archived` is refused: not supported yet),
|
|
267
|
+
`tags`. `lifecycle` is refused (no data lifecycle on a volume).
|
|
268
|
+
|
|
269
|
+
Execution knobs read through the base: `config.apply_instances` and
|
|
270
|
+
`config.apply_storage` (a bool, or the roots that may apply, by builder name
|
|
271
|
+
or runtime), `config.use_state_backends`, `config.module_source_base`.
|
|
272
|
+
|
|
273
|
+
## What it tests and verifies
|
|
274
|
+
|
|
275
|
+
- `packages/tf-docker-plugin/tests/`: the module arguments from a resolved,
|
|
276
|
+
a pinned and a deferred provider-specific image; the machine type's
|
|
277
|
+
limits; the memory and cpus spellings; the volume's module arguments and
|
|
278
|
+
labels; the launch-script template on a volume mount.
|
|
279
|
+
- `tests/test_v2_stage_103_instances.py`: a dry run over an overlay of the
|
|
280
|
+
frozen fixture emits both roots, the module calls, the uploaded launch
|
|
281
|
+
script, the environment prefix on every tofu line and the gated apply
|
|
282
|
+
sequence; the hooks' answers over a stubbed daemon; the fixture and the
|
|
283
|
+
golden do not change.
|
|
284
|
+
- `tests/test_v2_docker_cycle_live.py` (`just test-docker-cycle`, a leg of
|
|
285
|
+
`just full-test`): the cycle on the local daemon from nothing to nothing:
|
|
286
|
+
bake, launch two containers on one volume, verify, reconcile accounts,
|
|
287
|
+
stop one and show the next apply leaves it stopped, start it, upgrade one
|
|
288
|
+
to a new build (a new generation), decommission, destroy the volume,
|
|
289
|
+
dispose the images.
|
|
290
|
+
- The verification of a launched container (`verify instance`): the launch
|
|
291
|
+
marker, each declared mount point, the booted image, and the image's
|
|
292
|
+
declared post-bake tests over the session.
|
|
293
|
+
|
|
294
|
+
## When it fails
|
|
295
|
+
|
|
296
|
+
- `the daemon at ... cannot be reached`: the runtime's `host` or `context`
|
|
297
|
+
does not answer; preflight says the same in one line.
|
|
298
|
+
- `machine_type 'x' is not one of runtime ...'s machine_types`: the instance
|
|
299
|
+
names a type the runtime does not declare.
|
|
300
|
+
- `memory '...' is not a size docker understands`: a machine type's memory
|
|
301
|
+
is not `512m`, `4g` or a number of MB.
|
|
302
|
+
- A plan that wants to replace a container the operator did not upgrade:
|
|
303
|
+
a volume attachment changed (a detach on a container is a re-create, not
|
|
304
|
+
an in-place detach as on the clouds), or `cpus`/`memory` of its machine
|
|
305
|
+
type changed. The gate refuses the unwhitelisted destroy; an `upgrade
|
|
306
|
+
instance` sanctions the replacement.
|
|
307
|
+
- `relabel: could not retag instance ...: a container's labels are fixed`:
|
|
308
|
+
expected; the labels arrive with the next re-create.
|
|
309
|
+
- `verify ...: launch script: no completion marker`: the launch script did
|
|
310
|
+
not run or failed; the next applying run delivers it again
|
|
311
|
+
(`csis launch:` lines in the log say why).
|
|
312
|
+
|
|
313
|
+
## Related
|
|
314
|
+
|
|
315
|
+
- [cs-image-system-docker-runtime-plugin](../docker-runtime-plugin/README.md):
|
|
316
|
+
the runtime, the bake and the instance hooks.
|
|
317
|
+
- [cs-image-system-tf-ebs-instance-plugin](../tf-ebs-instance-plugin/README.md):
|
|
318
|
+
the tofu bases this plugin subclasses.
|
|
319
|
+
- `tfmodules/docker_container`, `tfmodules/docker_volume`: the modules.
|
|
320
|
+
- `docs/OPERATIONS.md`: the cycle, power states and generations.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
cs_image_system/tf_docker_plugin/__init__.py,sha256=GAFRNaGWQxXquHOlCzxan4LkPZ9_NsiyswknxdPcX0c,122
|
|
2
|
+
cs_image_system/tf_docker_plugin/main.py,sha256=PxjV2OPyTkcshiSTz0ds_DeRcJ-sULy7BWRNBppa7zs,1321
|
|
3
|
+
cs_image_system/tf_docker_plugin/tf_docker_instance_builder.py,sha256=VaLeZnZGU1PFIzlcTqSVkHGJJqMJxSE7dxg4hmnAm-U,15645
|
|
4
|
+
cs_image_system/tf_docker_plugin/tf_docker_models.py,sha256=SGmjSLQdTPr9KxOY-gixU_A4W5TmMfkf9rJqesTl3mA,2276
|
|
5
|
+
cs_image_system/tf_docker_plugin/tf_docker_storage_builder.py,sha256=tNAbmMqUBEVUTadRyCyaDz2CFn9_XQcHeFl0H8gjzLY,8830
|
|
6
|
+
cs_image_system_tf_docker_plugin-0.1.6.dist-info/METADATA,sha256=VH9mXC9Eq-jb7bC-pwli9qb4ZiDQwzb4DW-mfbFPGDU,15424
|
|
7
|
+
cs_image_system_tf_docker_plugin-0.1.6.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
8
|
+
cs_image_system_tf_docker_plugin-0.1.6.dist-info/entry_points.txt,sha256=5VOpK8tYEyQQ_JSiQ5-sWvvkTnEOvwuXElOGxZibS8A,103
|
|
9
|
+
cs_image_system_tf_docker_plugin-0.1.6.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
10
|
+
cs_image_system_tf_docker_plugin-0.1.6.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|