rostainer-package 0.0.3__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.
- rostainer_package-0.0.3/.gitignore +213 -0
- rostainer_package-0.0.3/PKG-INFO +41 -0
- rostainer_package-0.0.3/README.md +28 -0
- rostainer_package-0.0.3/pyproject.toml +32 -0
- rostainer_package-0.0.3/rostainer_package/__init__.py +236 -0
- rostainer_package-0.0.3/rostainer_package/assets/docker-compose.runtime.yml +87 -0
- rostainer_package-0.0.3/rostainer_package/assets/ros1.runtime.Dockerfile +131 -0
- rostainer_package-0.0.3/rostainer_package/assets/ros2.runtime.Dockerfile +137 -0
- rostainer_package-0.0.3/rostainer_package/assets/runtime_cli.py +1327 -0
- rostainer_package-0.0.3/rostainer_package/assets/runtime_entrypoint.py +543 -0
- rostainer_package-0.0.3/rostainer_package/create.py +1168 -0
- rostainer_package-0.0.3/rostainer_package/lockfile.py +106 -0
- rostainer_package-0.0.3/rostainer_package/network.py +181 -0
- rostainer_package-0.0.3/tests/__init__.py +15 -0
- rostainer_package-0.0.3/tests/helpers.py +106 -0
- rostainer_package-0.0.3/tests/test_dependencies.py +109 -0
- rostainer_package-0.0.3/tests/test_gpu.py +105 -0
- rostainer_package-0.0.3/tests/test_layers.py +296 -0
- rostainer_package-0.0.3/tests/test_manage.py +216 -0
- rostainer_package-0.0.3/tests/test_mounts.py +76 -0
- rostainer_package-0.0.3/tests/test_network.py +295 -0
- rostainer_package-0.0.3/tests/test_package_create.py +228 -0
- rostainer_package-0.0.3/tests/test_plugin.py +391 -0
- rostainer_package-0.0.3/tests/test_reproducible_packages.py +241 -0
- rostainer_package-0.0.3/tests/test_runtime_cli.py +261 -0
- rostainer_package-0.0.3/tests/test_runtime_scripts.py +285 -0
- rostainer_package-0.0.3/tests/test_update.py +287 -0
- rostainer_package-0.0.3/tests/test_user_ids.py +120 -0
- rostainer_package-0.0.3/tests/test_watchdog.py +77 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,python,emacs
|
|
2
|
+
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,python,emacs
|
|
3
|
+
|
|
4
|
+
# Docker ROS Tools - This is a tool repository, not a workspace
|
|
5
|
+
# Ignore any test workspaces or temporary files created during development
|
|
6
|
+
.compose_starter_info
|
|
7
|
+
.docker-compose.override.yml
|
|
8
|
+
.direnv/
|
|
9
|
+
builds/
|
|
10
|
+
# Generated from git tags by hatch-vcs at build/install time
|
|
11
|
+
scripts/cli/rostainer_cli/_version.py
|
|
12
|
+
### Emacs ###
|
|
13
|
+
# -*- mode: gitignore; -*-
|
|
14
|
+
*~
|
|
15
|
+
\#*\#
|
|
16
|
+
/.emacs.desktop
|
|
17
|
+
/.emacs.desktop.lock
|
|
18
|
+
*.elc
|
|
19
|
+
auto-save-list
|
|
20
|
+
tramp
|
|
21
|
+
.\#*
|
|
22
|
+
|
|
23
|
+
# Org-mode
|
|
24
|
+
.org-id-locations
|
|
25
|
+
*_archive
|
|
26
|
+
|
|
27
|
+
# flymake-mode
|
|
28
|
+
*_flymake.*
|
|
29
|
+
|
|
30
|
+
# eshell files
|
|
31
|
+
/eshell/history
|
|
32
|
+
/eshell/lastdir
|
|
33
|
+
|
|
34
|
+
# elpa packages
|
|
35
|
+
/elpa/
|
|
36
|
+
|
|
37
|
+
# reftex files
|
|
38
|
+
*.rel
|
|
39
|
+
|
|
40
|
+
# AUCTeX auto folder
|
|
41
|
+
/auto/
|
|
42
|
+
|
|
43
|
+
# cask packages
|
|
44
|
+
.cask/
|
|
45
|
+
dist/
|
|
46
|
+
|
|
47
|
+
# Flycheck
|
|
48
|
+
flycheck_*.el
|
|
49
|
+
|
|
50
|
+
# server auth directory
|
|
51
|
+
/server/
|
|
52
|
+
|
|
53
|
+
# projectiles files
|
|
54
|
+
.projectile
|
|
55
|
+
|
|
56
|
+
# directory configuration
|
|
57
|
+
.dir-locals.el
|
|
58
|
+
|
|
59
|
+
# network security
|
|
60
|
+
/network-security.data
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Python ###
|
|
64
|
+
# Byte-compiled / optimized / DLL files
|
|
65
|
+
__pycache__/
|
|
66
|
+
*.py[cod]
|
|
67
|
+
*$py.class
|
|
68
|
+
|
|
69
|
+
# C extensions
|
|
70
|
+
*.so
|
|
71
|
+
|
|
72
|
+
# Distribution / packaging
|
|
73
|
+
.Python
|
|
74
|
+
build/
|
|
75
|
+
develop-eggs/
|
|
76
|
+
downloads/
|
|
77
|
+
eggs/
|
|
78
|
+
.eggs/
|
|
79
|
+
lib/
|
|
80
|
+
lib64/
|
|
81
|
+
parts/
|
|
82
|
+
sdist/
|
|
83
|
+
var/
|
|
84
|
+
wheels/
|
|
85
|
+
share/python-wheels/
|
|
86
|
+
*.egg-info/
|
|
87
|
+
.installed.cfg
|
|
88
|
+
*.egg
|
|
89
|
+
MANIFEST
|
|
90
|
+
|
|
91
|
+
# PyInstaller
|
|
92
|
+
# Usually these files are written by a python script from a template
|
|
93
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
94
|
+
*.manifest
|
|
95
|
+
*.spec
|
|
96
|
+
|
|
97
|
+
# Installer logs
|
|
98
|
+
pip-log.txt
|
|
99
|
+
pip-delete-this-directory.txt
|
|
100
|
+
|
|
101
|
+
# Unit test / coverage reports
|
|
102
|
+
htmlcov/
|
|
103
|
+
.tox/
|
|
104
|
+
.nox/
|
|
105
|
+
.coverage
|
|
106
|
+
.coverage.*
|
|
107
|
+
.cache
|
|
108
|
+
nosetests.xml
|
|
109
|
+
coverage.xml
|
|
110
|
+
*.cover
|
|
111
|
+
*.py,cover
|
|
112
|
+
.hypothesis/
|
|
113
|
+
.pytest_cache/
|
|
114
|
+
cover/
|
|
115
|
+
|
|
116
|
+
# Translations
|
|
117
|
+
*.mo
|
|
118
|
+
*.pot
|
|
119
|
+
|
|
120
|
+
# Django stuff:
|
|
121
|
+
*.log
|
|
122
|
+
local_settings.py
|
|
123
|
+
db.sqlite3
|
|
124
|
+
db.sqlite3-journal
|
|
125
|
+
|
|
126
|
+
# Flask stuff:
|
|
127
|
+
instance/
|
|
128
|
+
.webassets-cache
|
|
129
|
+
|
|
130
|
+
# Scrapy stuff:
|
|
131
|
+
.scrapy
|
|
132
|
+
|
|
133
|
+
# Sphinx documentation
|
|
134
|
+
docs/_build/
|
|
135
|
+
|
|
136
|
+
# PyBuilder
|
|
137
|
+
.pybuilder/
|
|
138
|
+
target/
|
|
139
|
+
|
|
140
|
+
# Jupyter Notebook
|
|
141
|
+
.ipynb_checkpoints
|
|
142
|
+
|
|
143
|
+
# IPython
|
|
144
|
+
profile_default/
|
|
145
|
+
ipython_config.py
|
|
146
|
+
|
|
147
|
+
# pyenv
|
|
148
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
149
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
150
|
+
# .python-version
|
|
151
|
+
|
|
152
|
+
# pipenv
|
|
153
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
154
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
155
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
156
|
+
# install all needed dependencies.
|
|
157
|
+
#Pipfile.lock
|
|
158
|
+
|
|
159
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
160
|
+
__pypackages__/
|
|
161
|
+
|
|
162
|
+
# Celery stuff
|
|
163
|
+
celerybeat-schedule
|
|
164
|
+
celerybeat.pid
|
|
165
|
+
|
|
166
|
+
# SageMath parsed files
|
|
167
|
+
*.sage.py
|
|
168
|
+
|
|
169
|
+
# Environments
|
|
170
|
+
.env
|
|
171
|
+
.venv
|
|
172
|
+
env/
|
|
173
|
+
venv/
|
|
174
|
+
ENV/
|
|
175
|
+
env.bak/
|
|
176
|
+
venv.bak/
|
|
177
|
+
|
|
178
|
+
# Spyder project settings
|
|
179
|
+
.spyderproject
|
|
180
|
+
.spyproject
|
|
181
|
+
|
|
182
|
+
# Rope project settings
|
|
183
|
+
.ropeproject
|
|
184
|
+
|
|
185
|
+
# mkdocs documentation
|
|
186
|
+
/site
|
|
187
|
+
|
|
188
|
+
# mypy
|
|
189
|
+
.mypy_cache/
|
|
190
|
+
.dmypy.json
|
|
191
|
+
dmypy.json
|
|
192
|
+
|
|
193
|
+
# Pyre type checker
|
|
194
|
+
.pyre/
|
|
195
|
+
|
|
196
|
+
# pytype static type analyzer
|
|
197
|
+
.pytype/
|
|
198
|
+
|
|
199
|
+
# Cython debug symbols
|
|
200
|
+
cython_debug/
|
|
201
|
+
|
|
202
|
+
### VisualStudioCode ###
|
|
203
|
+
.vscode/
|
|
204
|
+
|
|
205
|
+
# Local History for Visual Studio Code
|
|
206
|
+
.history/
|
|
207
|
+
|
|
208
|
+
### VisualStudioCode Patch ###
|
|
209
|
+
# Ignore all local history of files
|
|
210
|
+
.history
|
|
211
|
+
.ionide
|
|
212
|
+
|
|
213
|
+
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,python,emacs
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: rostainer-package
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: rostainer plugin: build deployable images of a ROS workspace, for robots
|
|
5
|
+
Project-URL: Homepage, https://git.whoi.edu/bmillerklugman/rostainer
|
|
6
|
+
Project-URL: Documentation, https://bmillerklugman.pages.whoi.edu/rostainer/
|
|
7
|
+
Author: rostainer contributors
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Keywords: deployment,docker,ros,ros2,rostainer
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Requires-Dist: rostainer
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# rostainer-package
|
|
15
|
+
|
|
16
|
+
A [rostainer](https://bmillerklugman.pages.whoi.edu/rostainer/) plugin that builds
|
|
17
|
+
deployable images of a ROS workspace, for robots: the workspace baked in and built,
|
|
18
|
+
in a bundle that needs only Docker on the target.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pipx inject rostainer rostainer-package # or: pip install 'rostainer[package]'
|
|
22
|
+
rostainer init --with package # adds [plugins.package] to .rostainer.toml
|
|
23
|
+
rostainer package create # build a bundle in builds/package/<version>/
|
|
24
|
+
rostainer package install builds/package/<version> --start # try it here
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
On the target, the bundle brings its own `rostainer`, which needs only
|
|
28
|
+
Docker and Python: `./rostainer install --start` (or `--enable systemd`), then
|
|
29
|
+
`./rostainer status | logs | shell | stop | start | restart | rollback`, and
|
|
30
|
+
the plugins' commands (`./rostainer archive rotate`).
|
|
31
|
+
|
|
32
|
+
```toml
|
|
33
|
+
[plugins.package]
|
|
34
|
+
build_type = "Release" # CMAKE_BUILD_TYPE
|
|
35
|
+
sudo = false # keep sudo rights for the container user
|
|
36
|
+
healthcheck = "" # e.g. "ros2 node list | grep -q /my_driver"
|
|
37
|
+
host_pre_script = "" # runs on the host before the source is copied in
|
|
38
|
+
keep = 3 # package images/bundles 'rostainer prune' keeps
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
See the [Packaging guide](https://bmillerklugman.pages.whoi.edu/rostainer/plugins/package.html).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# rostainer-package
|
|
2
|
+
|
|
3
|
+
A [rostainer](https://bmillerklugman.pages.whoi.edu/rostainer/) plugin that builds
|
|
4
|
+
deployable images of a ROS workspace, for robots: the workspace baked in and built,
|
|
5
|
+
in a bundle that needs only Docker on the target.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pipx inject rostainer rostainer-package # or: pip install 'rostainer[package]'
|
|
9
|
+
rostainer init --with package # adds [plugins.package] to .rostainer.toml
|
|
10
|
+
rostainer package create # build a bundle in builds/package/<version>/
|
|
11
|
+
rostainer package install builds/package/<version> --start # try it here
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
On the target, the bundle brings its own `rostainer`, which needs only
|
|
15
|
+
Docker and Python: `./rostainer install --start` (or `--enable systemd`), then
|
|
16
|
+
`./rostainer status | logs | shell | stop | start | restart | rollback`, and
|
|
17
|
+
the plugins' commands (`./rostainer archive rotate`).
|
|
18
|
+
|
|
19
|
+
```toml
|
|
20
|
+
[plugins.package]
|
|
21
|
+
build_type = "Release" # CMAKE_BUILD_TYPE
|
|
22
|
+
sudo = false # keep sudo rights for the container user
|
|
23
|
+
healthcheck = "" # e.g. "ros2 node list | grep -q /my_driver"
|
|
24
|
+
host_pre_script = "" # runs on the host before the source is copied in
|
|
25
|
+
keep = 3 # package images/bundles 'rostainer prune' keeps
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
See the [Packaging guide](https://bmillerklugman.pages.whoi.edu/rostainer/plugins/package.html).
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rostainer-package"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "rostainer plugin: build deployable images of a ROS workspace, for robots"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.7"
|
|
12
|
+
authors = [{ name = "rostainer contributors" }]
|
|
13
|
+
keywords = ["ros", "ros2", "docker", "rostainer", "deployment"]
|
|
14
|
+
# Compatibility with rostainer itself is the plugin API version
|
|
15
|
+
# (PackagePlugin.api_version), which rostainer checks when it loads it.
|
|
16
|
+
dependencies = ["rostainer"]
|
|
17
|
+
|
|
18
|
+
[project.entry-points."rostainer.plugins"]
|
|
19
|
+
package = "rostainer_package:PackagePlugin"
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://git.whoi.edu/bmillerklugman/rostainer"
|
|
23
|
+
Documentation = "https://bmillerklugman.pages.whoi.edu/rostainer/"
|
|
24
|
+
|
|
25
|
+
# Versioned with rostainer, from the same repository's tags.
|
|
26
|
+
[tool.hatch.version]
|
|
27
|
+
source = "vcs"
|
|
28
|
+
fallback-version = "0.0.0.dev0"
|
|
29
|
+
raw-options = { root = "../.." }
|
|
30
|
+
|
|
31
|
+
[tool.hatch.build.targets.wheel]
|
|
32
|
+
packages = ["rostainer_package"]
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"""Packages: deployable images of a workspace, for robots.
|
|
2
|
+
|
|
3
|
+
``rostainer package create`` builds a runtime image with the workspace
|
|
4
|
+
baked in and built, saves it, and assembles a bundle that needs only
|
|
5
|
+
Docker (and Python) on the target: the image, a runtime Compose file, its
|
|
6
|
+
settings, and ``./rostainer``, which installs and runs the package there
|
|
7
|
+
without rostainer (``assets/runtime_cli.py``; :func:`runtime_cli` loads it
|
|
8
|
+
here). ``rostainer package install DIR`` runs a bundle's ``./rostainer
|
|
9
|
+
install``. See :mod:`rostainer_package.create`.
|
|
10
|
+
|
|
11
|
+
Its settings are the ``[plugins.package]`` table (:class:`PackageConfig`);
|
|
12
|
+
the image is also built from the workspace's own ones that dev containers
|
|
13
|
+
use (``command``, ``extra_dirs``, ``environment``, devices, ...).
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import functools
|
|
20
|
+
import importlib.util
|
|
21
|
+
import subprocess
|
|
22
|
+
import sys
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
from types import ModuleType
|
|
25
|
+
from typing import List, Optional, Sequence
|
|
26
|
+
|
|
27
|
+
from pydantic import Field, field_validator
|
|
28
|
+
from typing_extensions import Literal
|
|
29
|
+
|
|
30
|
+
from rostainer_cli.plugin_api import (
|
|
31
|
+
Command,
|
|
32
|
+
Context,
|
|
33
|
+
HostScript,
|
|
34
|
+
Plugin,
|
|
35
|
+
PluginConfig,
|
|
36
|
+
host_script,
|
|
37
|
+
log,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
#: Values of ``build_type`` (CMake's ``CMAKE_BUILD_TYPE``).
|
|
41
|
+
CMAKE_BUILD_TYPES = ("Release", "RelWithDebInfo", "Debug", "MinSizeRel")
|
|
42
|
+
|
|
43
|
+
#: Where the plugin's own files (Dockerfile stages, runtime_cli.py, ...) are.
|
|
44
|
+
ASSETS_DIR = Path(__file__).resolve().parent / "assets"
|
|
45
|
+
|
|
46
|
+
#: A package's own ``rostainer``: :data:`RUNTIME_CLI_PATH`, as it's named
|
|
47
|
+
#: in a bundle.
|
|
48
|
+
RUNTIME_CLI_NAME = "rostainer"
|
|
49
|
+
RUNTIME_CLI_PATH = ASSETS_DIR / "runtime_cli.py"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@functools.lru_cache(maxsize=None)
|
|
53
|
+
def runtime_cli() -> ModuleType:
|
|
54
|
+
"""The module a bundle ships as ``./rostainer``, loaded from its file:
|
|
55
|
+
it's standalone on the target, so it isn't part of this package."""
|
|
56
|
+
spec = importlib.util.spec_from_file_location("rostainer_package_runtime_cli", RUNTIME_CLI_PATH)
|
|
57
|
+
assert spec is not None and spec.loader is not None
|
|
58
|
+
module = importlib.util.module_from_spec(spec)
|
|
59
|
+
spec.loader.exec_module(module)
|
|
60
|
+
return module
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class PackageConfig(PluginConfig):
|
|
64
|
+
"""The ``[plugins.package]`` table."""
|
|
65
|
+
|
|
66
|
+
build_type: Literal[CMAKE_BUILD_TYPES] = Field( # type: ignore[valid-type]
|
|
67
|
+
"Release",
|
|
68
|
+
description="CMAKE_BUILD_TYPE of the packaged build: Release, RelWithDebInfo, Debug, MinSizeRel.",
|
|
69
|
+
)
|
|
70
|
+
sudo: bool = Field(
|
|
71
|
+
False,
|
|
72
|
+
description=(
|
|
73
|
+
"Packages' container user has no sudo rights (only the build does); set to\n"
|
|
74
|
+
"true if something in the running container needs sudo."
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
healthcheck: str = Field(
|
|
78
|
+
"",
|
|
79
|
+
description=(
|
|
80
|
+
"Health check for the runtime command: a shell command run in the container's\n"
|
|
81
|
+
"ROS environment, e.g. \"ros2 node list | grep -q /my_driver\". While it keeps\n"
|
|
82
|
+
"failing, the container is restarted. Empty: none."
|
|
83
|
+
),
|
|
84
|
+
)
|
|
85
|
+
healthcheck_interval: int = Field(30, ge=1, description="Seconds between checks.")
|
|
86
|
+
healthcheck_retries: int = Field(
|
|
87
|
+
3, ge=1, description="Failures in a row before restarting."
|
|
88
|
+
)
|
|
89
|
+
healthcheck_start_period: int = Field(
|
|
90
|
+
60, ge=0, description="Seconds after start before checking."
|
|
91
|
+
)
|
|
92
|
+
host_pre_script: HostScript = Field(
|
|
93
|
+
"",
|
|
94
|
+
description=(
|
|
95
|
+
"Runs on the HOST before 'package create' copies the source into the image,\n"
|
|
96
|
+
"like host_pre_start_script (often the same script). A path, or one per\n"
|
|
97
|
+
"host platform: { default = \"pre.sh\", windows = \"pre.ps1\" }. Empty: none."
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
dependencies_first: bool = Field(
|
|
101
|
+
True,
|
|
102
|
+
description=(
|
|
103
|
+
"Install dependencies (rosdep, pip) from the package.xml and requirements.txt\n"
|
|
104
|
+
"files before the rest of the source is copied in, so a change to the source\n"
|
|
105
|
+
"alone rebuilds - and ships - only the workspace's own layers. Set to false if\n"
|
|
106
|
+
"the pre-build script needs the whole source."
|
|
107
|
+
),
|
|
108
|
+
)
|
|
109
|
+
keep: int = Field(
|
|
110
|
+
3,
|
|
111
|
+
ge=0,
|
|
112
|
+
description="How many of the newest package images and bundles 'rostainer prune' keeps.",
|
|
113
|
+
)
|
|
114
|
+
offline: Literal["auto", "true", "false"] = Field(
|
|
115
|
+
"true",
|
|
116
|
+
description=(
|
|
117
|
+
"Whether the package's starts are offline on its targets (ROSTAINER_OFFLINE),\n"
|
|
118
|
+
"apart from this machine's ('offline' above is for dev containers here):\n"
|
|
119
|
+
"true/false: always/never, with nothing checked on start (the package\n"
|
|
120
|
+
'installs nothing there); "auto" checks offline_check_url on each start.'
|
|
121
|
+
),
|
|
122
|
+
)
|
|
123
|
+
offline_check_url: str = Field(
|
|
124
|
+
"",
|
|
125
|
+
description=(
|
|
126
|
+
'What "auto" checks, from the targets, e.g. a server on their network\n'
|
|
127
|
+
"(empty: PyPI, i.e. the internet)."
|
|
128
|
+
),
|
|
129
|
+
)
|
|
130
|
+
offline_check_timeout: int = Field(
|
|
131
|
+
3, ge=1, description='How many seconds "auto" waits before calling a start offline.'
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
@field_validator("offline", mode="before")
|
|
135
|
+
@classmethod
|
|
136
|
+
def _offline_bool(cls, value: object) -> object:
|
|
137
|
+
# As the workspace's 'offline': TOML booleans too.
|
|
138
|
+
if isinstance(value, bool):
|
|
139
|
+
return "true" if value else "false"
|
|
140
|
+
return value
|
|
141
|
+
|
|
142
|
+
@field_validator("offline_check_url")
|
|
143
|
+
@classmethod
|
|
144
|
+
def _check_url(cls, value: str) -> str:
|
|
145
|
+
if value and not value.startswith(("http://", "https://")):
|
|
146
|
+
raise ValueError(f"must be an http:// or https:// URL, got {value!r}")
|
|
147
|
+
return value
|
|
148
|
+
|
|
149
|
+
@field_validator("host_pre_script", mode="before")
|
|
150
|
+
@classmethod
|
|
151
|
+
def _host_script(cls, value: object) -> object:
|
|
152
|
+
return host_script(value)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def restart_policy(ctx: Context) -> str:
|
|
156
|
+
"""A package's restart policy: the workspace's ``restart_policy``, else
|
|
157
|
+
``"always"``: packages start at boot and restart when their command
|
|
158
|
+
exits ('./rostainer install --enable docker' and the health check rely on it)."""
|
|
159
|
+
return ctx.cfg.restart_policy or "always"
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class PackageCommand(Command):
|
|
163
|
+
"""``rostainer package <create|install>``."""
|
|
164
|
+
|
|
165
|
+
name = "package"
|
|
166
|
+
summary = "Build a deployable runtime image ('package create') and install it ('package install')"
|
|
167
|
+
|
|
168
|
+
def add_arguments(self, parser: argparse.ArgumentParser) -> None:
|
|
169
|
+
actions = parser.add_subparsers(dest="action", metavar="ACTION")
|
|
170
|
+
actions.required = True
|
|
171
|
+
from rostainer_package import create
|
|
172
|
+
|
|
173
|
+
create.add_arguments(
|
|
174
|
+
actions.add_parser(
|
|
175
|
+
"create",
|
|
176
|
+
help="Build a deployable runtime image with the workspace baked in",
|
|
177
|
+
description="Build a deployable runtime image with the workspace baked in.",
|
|
178
|
+
)
|
|
179
|
+
)
|
|
180
|
+
install = actions.add_parser(
|
|
181
|
+
"install",
|
|
182
|
+
help="Install a package bundle here: its './rostainer install' (on a target, "
|
|
183
|
+
"run that directly: it needs no rostainer)",
|
|
184
|
+
description="Run PACKAGE_DIR/rostainer install with the given options. It "
|
|
185
|
+
"needs only Docker and Python: on a target machine, run "
|
|
186
|
+
"'PACKAGE_DIR/rostainer install' directly.",
|
|
187
|
+
)
|
|
188
|
+
install.add_argument("package_dir", metavar="PACKAGE_DIR")
|
|
189
|
+
install.add_argument(
|
|
190
|
+
"install_args",
|
|
191
|
+
nargs=argparse.REMAINDER,
|
|
192
|
+
help="Its options, e.g. --start, --enable systemd, --install-dir DIR",
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
def run(self, args: argparse.Namespace, ctx: Optional[Context]) -> int:
|
|
196
|
+
assert ctx is not None
|
|
197
|
+
if args.action == "create":
|
|
198
|
+
from rostainer_package import create
|
|
199
|
+
|
|
200
|
+
return create.run(args, ctx)
|
|
201
|
+
return install(Path(args.package_dir), args.install_args)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def install(package_dir: Path, install_args: Sequence[str]) -> int:
|
|
205
|
+
"""Run ``package_dir``'s ``./rostainer install`` with ``install_args``."""
|
|
206
|
+
script = package_dir / RUNTIME_CLI_NAME
|
|
207
|
+
if not script.is_file():
|
|
208
|
+
log.error(f"'{package_dir}' isn't a package bundle: no {RUNTIME_CLI_NAME} in it.")
|
|
209
|
+
return 1
|
|
210
|
+
# Through sys.executable, not the script's own shebang: Windows has no
|
|
211
|
+
# shebang support at all.
|
|
212
|
+
return subprocess.run([sys.executable, str(script), "install", *install_args]).returncode
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
class PackagePlugin(Plugin):
|
|
216
|
+
"""Deployable images of the workspace, for robots."""
|
|
217
|
+
|
|
218
|
+
name = "package"
|
|
219
|
+
api_version = 1
|
|
220
|
+
summary = "Deployable images of the workspace, for robots"
|
|
221
|
+
config_model = PackageConfig
|
|
222
|
+
|
|
223
|
+
def commands(self) -> Sequence[Command]:
|
|
224
|
+
return [PackageCommand()]
|
|
225
|
+
|
|
226
|
+
def prunable_images(self, ctx: Context, removed: Sequence[str]) -> List[str]:
|
|
227
|
+
"""This workspace's package images, except the ``keep`` newest."""
|
|
228
|
+
from rostainer_package import create
|
|
229
|
+
|
|
230
|
+
return create.package_images(ctx)[ctx.config.keep :]
|
|
231
|
+
|
|
232
|
+
def prunable_paths(self, ctx: Context) -> List[Path]:
|
|
233
|
+
"""This workspace's bundles in ``builds/package/``, except the ``keep`` newest."""
|
|
234
|
+
from rostainer_package import create
|
|
235
|
+
|
|
236
|
+
return create.package_bundles(ctx)[ctx.config.keep :]
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Runtime Docker Compose file for packaged deployments.
|
|
2
|
+
#
|
|
3
|
+
# Unlike docker-compose.yml, this has no 'build:' section - it only ever
|
|
4
|
+
# runs an image that was already built by 'rostainer package create' and
|
|
5
|
+
# loaded with 'docker load'. It must never try to pull or build
|
|
6
|
+
# 'ros:${ROS_DISTRO}-ros-base'.
|
|
7
|
+
x-shared-environment: &shared-environment
|
|
8
|
+
RUNTIME_COMMAND: ${RUNTIME_COMMAND:-}
|
|
9
|
+
USER_UID: ${USER_UID:-1000}
|
|
10
|
+
USER_GID: ${USER_GID:-1000}
|
|
11
|
+
USERNAME: ${USERNAME:-rosuser}
|
|
12
|
+
ROS_LOG_MAX_SIZE_MB: ${ROS_LOG_MAX_SIZE_MB:-1024}
|
|
13
|
+
ROS_LOG_MAX_AGE_DAYS: ${ROS_LOG_MAX_AGE_DAYS:-30}
|
|
14
|
+
# Optional watchdog (see runtime_entrypoint.supervise).
|
|
15
|
+
RUNTIME_HEALTHCHECK: ${RUNTIME_HEALTHCHECK:-}
|
|
16
|
+
RUNTIME_HEALTHCHECK_INTERVAL: ${RUNTIME_HEALTHCHECK_INTERVAL:-30}
|
|
17
|
+
RUNTIME_HEALTHCHECK_RETRIES: ${RUNTIME_HEALTHCHECK_RETRIES:-3}
|
|
18
|
+
RUNTIME_HEALTHCHECK_START_PERIOD: ${RUNTIME_HEALTHCHECK_START_PERIOD:-60}
|
|
19
|
+
# Whether a start is offline ('offline' in .rostainer.toml), for
|
|
20
|
+
# ROSTAINER_OFFLINE (see runtime_entrypoint.detect_offline).
|
|
21
|
+
ROSTAINER_OFFLINE_SETTING: ${ROSTAINER_OFFLINE_SETTING:-true}
|
|
22
|
+
ROSTAINER_OFFLINE_CHECK_URL: ${ROSTAINER_OFFLINE_CHECK_URL:-}
|
|
23
|
+
ROSTAINER_OFFLINE_CHECK_TIMEOUT: ${ROSTAINER_OFFLINE_CHECK_TIMEOUT:-}
|
|
24
|
+
# ROS 2 discovery (see 'ros_discovery_range' in .rostainer.toml).
|
|
25
|
+
ROS_AUTOMATIC_DISCOVERY_RANGE: ${ROS_AUTOMATIC_DISCOVERY_RANGE:-SUBNET}
|
|
26
|
+
ROS_STATIC_PEERS: ${ROS_STATIC_PEERS:-}
|
|
27
|
+
ROS_DOMAIN_ID: ${ROS_DOMAIN_ID:-0}
|
|
28
|
+
# Humble's equivalent of ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST.
|
|
29
|
+
ROS_LOCALHOST_ONLY: ${ROS_LOCALHOST_ONLY:-}
|
|
30
|
+
# Docker keeps a container's stdout/stderr (everything 'docker logs' shows)
|
|
31
|
+
# without any limit by default, which on a long-running deployment
|
|
32
|
+
# eventually fills the disk.
|
|
33
|
+
x-shared-logging: &shared-logging
|
|
34
|
+
driver: json-file
|
|
35
|
+
options:
|
|
36
|
+
max-size: ${DOCKER_LOG_MAX_SIZE:-10m}
|
|
37
|
+
max-file: "${DOCKER_LOG_MAX_FILES:-5}"
|
|
38
|
+
# Shows the watchdog's state in 'docker ps'. Restarting is the
|
|
39
|
+
# entrypoint's job: Docker never restarts an unhealthy container itself.
|
|
40
|
+
x-shared-healthcheck: &shared-healthcheck
|
|
41
|
+
test: ["CMD-SHELL", "[ ! -f /tmp/.runtime_unhealthy ]"]
|
|
42
|
+
interval: 10s
|
|
43
|
+
timeout: 5s
|
|
44
|
+
retries: 1
|
|
45
|
+
|
|
46
|
+
services:
|
|
47
|
+
ros1_runtime:
|
|
48
|
+
image: ${ROS_DOCKER_IMAGE_TAG}
|
|
49
|
+
container_name: ${ROS1_CONTAINER_NAME:-ros1_container}
|
|
50
|
+
profiles:
|
|
51
|
+
- ros1
|
|
52
|
+
tty: true
|
|
53
|
+
stdin_open: true
|
|
54
|
+
# Root at first: the entrypoint gives the image's user USER_UID/USER_GID
|
|
55
|
+
# (this machine's user's, from './rostainer install'), then runs as it.
|
|
56
|
+
user: "0:0"
|
|
57
|
+
environment:
|
|
58
|
+
<<: *shared-environment
|
|
59
|
+
network_mode: ${NETWORK_MODE:-host}
|
|
60
|
+
# 'restart_policy' in .rostainer.toml; packages restart by default.
|
|
61
|
+
restart: ${RESTART_POLICY:-always}
|
|
62
|
+
healthcheck: *shared-healthcheck
|
|
63
|
+
logging: *shared-logging
|
|
64
|
+
# A real PID 1 that forwards SIGTERM (the runtime command, or 'tail -f
|
|
65
|
+
# /dev/null', may ignore it as PID 1) and reaps the background pruner.
|
|
66
|
+
init: true
|
|
67
|
+
|
|
68
|
+
ros2_runtime:
|
|
69
|
+
image: ${ROS_DOCKER_IMAGE_TAG}
|
|
70
|
+
container_name: ${ROS2_CONTAINER_NAME:-ros2_container}
|
|
71
|
+
profiles:
|
|
72
|
+
- ros2
|
|
73
|
+
tty: true
|
|
74
|
+
stdin_open: true
|
|
75
|
+
# Root at first: the entrypoint gives the image's user USER_UID/USER_GID
|
|
76
|
+
# (this machine's user's, from './rostainer install'), then runs as it.
|
|
77
|
+
user: "0:0"
|
|
78
|
+
environment:
|
|
79
|
+
<<: *shared-environment
|
|
80
|
+
network_mode: ${NETWORK_MODE:-host}
|
|
81
|
+
# 'restart_policy' in .rostainer.toml; packages restart by default.
|
|
82
|
+
restart: ${RESTART_POLICY:-always}
|
|
83
|
+
healthcheck: *shared-healthcheck
|
|
84
|
+
logging: *shared-logging
|
|
85
|
+
# A real PID 1 that forwards SIGTERM (the runtime command, or 'tail -f
|
|
86
|
+
# /dev/null', may ignore it as PID 1) and reaps the background pruner.
|
|
87
|
+
init: true
|