dindbox 1.0.0__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.
- dindbox-1.0.0/LICENSE +21 -0
- dindbox-1.0.0/PKG-INFO +223 -0
- dindbox-1.0.0/README.md +199 -0
- dindbox-1.0.0/dindbox/__init__.py +5 -0
- dindbox-1.0.0/dindbox/__main__.py +6 -0
- dindbox-1.0.0/dindbox/box.py +1626 -0
- dindbox-1.0.0/dindbox/cli.py +473 -0
- dindbox-1.0.0/dindbox/errors.py +81 -0
- dindbox-1.0.0/dindbox/status_screen.py +440 -0
- dindbox-1.0.0/pyproject.toml +37 -0
dindbox-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Jonas Hanschke
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
dindbox-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dindbox
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Lightweight, docker-capable virtual testing environment based on docker-in-docker (dind)
|
|
5
|
+
Home-page: https://gitlab.com/orbelico/dindbox
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: docker,docker-in-docker,dind,gitlab CI,gitlab runner,github actions
|
|
8
|
+
Author: Orbelico
|
|
9
|
+
Author-email: orbelico@posteo.de
|
|
10
|
+
Requires-Python: >=3.10,<4.0
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Requires-Dist: blessed (>=1.20.0,<2.0.0)
|
|
18
|
+
Requires-Dist: configargparse (>=1.7,<2.0)
|
|
19
|
+
Requires-Dist: docker (>=6.0.1,<7.0.0)
|
|
20
|
+
Requires-Dist: toml (>=0.10.2,<0.11.0)
|
|
21
|
+
Project-URL: Repository, https://gitlab.com/orbelico/dindbox
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
dindbox
|
|
25
|
+
=======
|
|
26
|
+
|
|
27
|
+
Lightweight, docker-capable virtual testing environment.
|
|
28
|
+
|
|
29
|
+
DindBox creates virtual testing environments, each comprising two docker containers. These function like lightweight
|
|
30
|
+
virtual machines, allowing for the creation and operation of docker containers within them without affecting
|
|
31
|
+
the host system's main docker daemon. This "docker-in-docker" principle, used by CI platforms like GitLab CI or GitHub
|
|
32
|
+
Actions, enables docker capability within a containerized runner. DindBox offers this setup for local testing and
|
|
33
|
+
prototyping, and can also be used in a CI context with a dedicated runner.
|
|
34
|
+
|
|
35
|
+
Installation
|
|
36
|
+
-----------
|
|
37
|
+
|
|
38
|
+
Dindbox only runs on Linux-based systems. It requires a Python version >= 3.10, a running docker server, and an
|
|
39
|
+
installation of the Docker CLI.
|
|
40
|
+
|
|
41
|
+
Dindbox is mostly intended to be used as a command-line tool. For this use case, it is recommended to install it via
|
|
42
|
+
pipx in order to make it available globally but keep its dependencies within a separated environment:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
python3 -m pip install --user pipx
|
|
46
|
+
python3 -m pipx ensurepath
|
|
47
|
+
pipx install dindbox
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
If you however do plan to use dindbox as a python library (see below), simply run `pip install dindbox` within the
|
|
51
|
+
virtual environment of your project.
|
|
52
|
+
|
|
53
|
+
Usage
|
|
54
|
+
----
|
|
55
|
+
|
|
56
|
+
All commands and options are documented in detail in the command-line help. Run `dindbox -h` for a list of available
|
|
57
|
+
commands, and `dindbox COMMAND -h` for help on each command.
|
|
58
|
+
|
|
59
|
+
The most basic use case is to directly start an interactive session:
|
|
60
|
+
`dindbox my_box run`
|
|
61
|
+
Where `my_box` is the name of your dindbox which you can re-use in further commands to interact with it. The `run`
|
|
62
|
+
command without further parameters will give you an Alpine Linux based environment, with a fully functional docker
|
|
63
|
+
client & daemon - encapsulated within docker containers themselves (docker-in-docker). The container containing the
|
|
64
|
+
docker daemon is referred to as *service container*. The container with which you're interacting, which contains the
|
|
65
|
+
docker client is referred to as *build container*.
|
|
66
|
+
|
|
67
|
+
If you are on an ubuntu-based system, `run` will also open a status screen in a separate console window. You may close
|
|
68
|
+
this status screen at any time, it is only for monitoring purposes. Also, you can reopen it at any time running
|
|
69
|
+
`dindbox my_box status` from a separate shell window.
|
|
70
|
+
|
|
71
|
+
If you'd rather use an ubuntu image, do something like the following to change the default build container image:
|
|
72
|
+
`dindbox my_box run -i ubuntu:focal`
|
|
73
|
+
Note that in this case you will need to manually install the docker **client**, since it is not part of the ubuntu
|
|
74
|
+
image. The docker daemon however, will already be available, since it runs inside the service container.
|
|
75
|
+
|
|
76
|
+
Note that you may also replace the service container's image (using `-I`). Normally, it should always be a `dind`
|
|
77
|
+
tag of the official docker image, but you can use this to test with different versions of docker, for example.
|
|
78
|
+
Nevertheless, other use cases are possible, too, like running a SQL server is in the service image, and the client in
|
|
79
|
+
the build image.
|
|
80
|
+
|
|
81
|
+
When you're done, you should always clean up boxes which you do not need anymore. In order to remove all docker entities
|
|
82
|
+
associated with your dindbox, run:
|
|
83
|
+
`dindbox my_box remove`
|
|
84
|
+
Or, if you know it is a throw-away box, directly append `--rm` to the `run` command for automatic cleanup after exiting.
|
|
85
|
+
|
|
86
|
+
For further commands, check out the command-line help. Note that `run` is a shortcut for `create` + `start` + `attach`.
|
|
87
|
+
Only in special cases it makes sense to use these commands individually, for the most part you should be fine with
|
|
88
|
+
`run`.
|
|
89
|
+
|
|
90
|
+
Config file
|
|
91
|
+
----------
|
|
92
|
+
|
|
93
|
+
All command-line parameters can also be set through a config file, so you do not have to re-type them every time. Note
|
|
94
|
+
that config file settings only affect CLI usage. They have **no** effect at all when using dindbox as a Python library.
|
|
95
|
+
|
|
96
|
+
### Config file locations
|
|
97
|
+
|
|
98
|
+
Dindbox will look for a config file in three locations:
|
|
99
|
+
|
|
100
|
+
* First, it will traverse the directory structure upwards, starting with the current directory and looking for a
|
|
101
|
+
`pyproject.toml` file, as is usually present within a poetry environment. Any sections within that file of the format
|
|
102
|
+
`[tool.dindbox.*]` will be considered (see below for exact format).
|
|
103
|
+
* Next, any file in the *current directory* of name `dindbox.conf` will be parsed.
|
|
104
|
+
* Lastly, a config file specified with the `--config-file` or `-c` command-line argument will be parsed.
|
|
105
|
+
|
|
106
|
+
Config files will be parsed in the order specified above. Duplicate options provided in a later config file will
|
|
107
|
+
override values from previous config files. Additionally, a command-line parameter will always override a value set in
|
|
108
|
+
any of the config files.
|
|
109
|
+
|
|
110
|
+
### Config file format
|
|
111
|
+
|
|
112
|
+
Config files need to be in the TOML format. Arguments to each `dindbox` command are specified in a section named
|
|
113
|
+
`[dindbox.COMMAND]`, where `COMMAND` is the name of the command, e.g. `run`. The section name is case-sensitive.
|
|
114
|
+
Additionally, global arguments (the ones provided before a command and listed when running `dindbox --help`) can be
|
|
115
|
+
specified in a section named `[dindbox.global]`.
|
|
116
|
+
|
|
117
|
+
Argument names must be provided in their long form, without the leading `--`. Here's an example:
|
|
118
|
+
|
|
119
|
+
```toml title="dindbox.conf"
|
|
120
|
+
[dindbox.global]
|
|
121
|
+
log-level = "DEBUG"
|
|
122
|
+
|
|
123
|
+
[dindbox.run]
|
|
124
|
+
no-status-screen = true
|
|
125
|
+
rm = true
|
|
126
|
+
|
|
127
|
+
[dindbox.remove]
|
|
128
|
+
force = true
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Note:** When setting options in poetry's `pyproject.toml`, the section name needs to be prefixed with `tool.`:
|
|
132
|
+
|
|
133
|
+
```toml
|
|
134
|
+
[tool.dindbox.run]
|
|
135
|
+
rm = true
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Usage as a Python Library
|
|
139
|
+
------------------------
|
|
140
|
+
|
|
141
|
+
Althogh `dindbox` is primarily intended to be used as a command-line tool, it can also be used as a Python library and
|
|
142
|
+
you can create your own custom scripts and applications based on it. The main entry point is the `DindBox` class. Here's
|
|
143
|
+
a minimal example of how to use it:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from dindbox import DindBox
|
|
147
|
+
|
|
148
|
+
box = DindBox("my_box", build_image="ubuntu:focal")
|
|
149
|
+
box.run()
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
For further usage details, rely on the docstrings and type annotations of the `DindBox` class and its methods.
|
|
153
|
+
|
|
154
|
+
Use Cases
|
|
155
|
+
--------
|
|
156
|
+
|
|
157
|
+
Although there are probably more, DindBox was created with a particular set of use cases in mind. Most of these are
|
|
158
|
+
aimed at local testing on your development machine, but there are some rare cases, where it may even make sense to run
|
|
159
|
+
DindBox on your CI server. (In that case however, you're gonna need a dedicated runner, since DindBox itself should not
|
|
160
|
+
be run within a container.)
|
|
161
|
+
|
|
162
|
+
* **Test installation and execution of dockerized apps in a safe environment and on different Linux distributions**
|
|
163
|
+
You've created an application which is nicely bundled into microservices. Maybe there's also a nice little install
|
|
164
|
+
script to set it all up on a machine. But how do you test it? Hopefully not by running an untested script with root
|
|
165
|
+
permissions directly on your development machine. You'll either need a VM, or a tedious manually cobbled-together
|
|
166
|
+
docker setup - or you just type `dindbox run` and give it a go! And by switching out the image for the build container,
|
|
167
|
+
you can even easily test if your script runs fine on different Linux distros (and different releases of these).
|
|
168
|
+
|
|
169
|
+
* **Test a dockerized application against different versions of docker**
|
|
170
|
+
Switching the docker version locally means uninstalling and re-installing for each version switch. With DindBox, you
|
|
171
|
+
can just swap out the images and re-run your application (or re-build your images) based on a different release of
|
|
172
|
+
docker.
|
|
173
|
+
|
|
174
|
+
* **Reproduce and debug errors which occur in continuous integration (CI) jobs**
|
|
175
|
+
CI pipelines can be difficult to debug. And sometimes, the problem is not in the pipeline code alone, but also has to
|
|
176
|
+
do with the fact that the job is executed within a containerized runner. This can be particularly tricky, when
|
|
177
|
+
running docker commands as part of the pipeline, e.g. to test a self-built image. DindBox allows to easily reproduce
|
|
178
|
+
the containerized setup locally, with one simple command-line.
|
|
179
|
+
|
|
180
|
+
* **Build docker images locally within a well-defined environment**
|
|
181
|
+
In CI, your docker images are built in a containerized environment with a fixed docker version etc. DindBox makes it
|
|
182
|
+
easy to reproduce the exact same conditions locally.
|
|
183
|
+
|
|
184
|
+
* **Anything else you would otherwise use a virtual machine for**, because you need it to be isolated, and it requires
|
|
185
|
+
docker.
|
|
186
|
+
|
|
187
|
+
Note: the service running in the second container does not *have* to be dockerd. Since the image is freely configurable,
|
|
188
|
+
you could also switch it our for a database image like MySQL, and test your DB-dependent, non-dockerized application
|
|
189
|
+
in a DindBox. That's totally possible, but it is not what I had in mind when I created it.
|
|
190
|
+
|
|
191
|
+
How is it different from docker-compose?
|
|
192
|
+
---------------------------------------
|
|
193
|
+
|
|
194
|
+
Good question. For many use cases, docker-compose may be a good solution. But specifically for the testing use cases
|
|
195
|
+
listed above, DindBox offers some advantages, and also some specific features, which are not easily reproduced with
|
|
196
|
+
docker-compose:
|
|
197
|
+
|
|
198
|
+
* Ease of use: no need to create a config file, just type a short command-line with a few options, and you're up and
|
|
199
|
+
running. DindBox allows for some helpful configuration options, but the defaults will work fine, usually.
|
|
200
|
+
* Easy management of multiple boxes: each box has a specific name. By referencing that name you can easily manage,
|
|
201
|
+
re-use, and clean up your various test environments. All docker entities (containers, networks, volumes) that make
|
|
202
|
+
up a single box, will be set up or removed automatically, with a one-line command.
|
|
203
|
+
* Nice status screen: allows you to monitor what is going on inside a box, even if you're not interacting with it
|
|
204
|
+
directly.
|
|
205
|
+
* Bind volumes: In addition to attaching docker volumes to your containers, or bind-mounting existing host directories,
|
|
206
|
+
DindBox also offers to configure so-called "bind volumes". These are basically host directories which behave like
|
|
207
|
+
docker volumes: they are created on-demand in a temporary folder, mounted to both DindBox containers, and cleaned up
|
|
208
|
+
on removal of the DindBox. They can be used for specific cases, which are not supported by standard docker volumes.
|
|
209
|
+
One example for this is running a user-space file system within on of your docker-ind-docker containers, and have it
|
|
210
|
+
access the volume.
|
|
211
|
+
|
|
212
|
+
Development
|
|
213
|
+
----------
|
|
214
|
+
|
|
215
|
+
DindBox uses [poetry](https://python-poetry.org) for dependency management, isolation and packaging.
|
|
216
|
+
|
|
217
|
+
* If you do not have it already, install poetry on your machine as described in
|
|
218
|
+
[its documentation](https://python-poetry.org/docs/#installation). Make sure to install in an isolated environment
|
|
219
|
+
(the official installer does that), do not simply `pip install` it.
|
|
220
|
+
* Optional: enable poetry bash completion, as described in the docs
|
|
221
|
+
* Clone this repository and enter the directory
|
|
222
|
+
* Run `poetry install`
|
|
223
|
+
|
dindbox-1.0.0/README.md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
dindbox
|
|
2
|
+
=======
|
|
3
|
+
|
|
4
|
+
Lightweight, docker-capable virtual testing environment.
|
|
5
|
+
|
|
6
|
+
DindBox creates virtual testing environments, each comprising two docker containers. These function like lightweight
|
|
7
|
+
virtual machines, allowing for the creation and operation of docker containers within them without affecting
|
|
8
|
+
the host system's main docker daemon. This "docker-in-docker" principle, used by CI platforms like GitLab CI or GitHub
|
|
9
|
+
Actions, enables docker capability within a containerized runner. DindBox offers this setup for local testing and
|
|
10
|
+
prototyping, and can also be used in a CI context with a dedicated runner.
|
|
11
|
+
|
|
12
|
+
Installation
|
|
13
|
+
-----------
|
|
14
|
+
|
|
15
|
+
Dindbox only runs on Linux-based systems. It requires a Python version >= 3.10, a running docker server, and an
|
|
16
|
+
installation of the Docker CLI.
|
|
17
|
+
|
|
18
|
+
Dindbox is mostly intended to be used as a command-line tool. For this use case, it is recommended to install it via
|
|
19
|
+
pipx in order to make it available globally but keep its dependencies within a separated environment:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
python3 -m pip install --user pipx
|
|
23
|
+
python3 -m pipx ensurepath
|
|
24
|
+
pipx install dindbox
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
If you however do plan to use dindbox as a python library (see below), simply run `pip install dindbox` within the
|
|
28
|
+
virtual environment of your project.
|
|
29
|
+
|
|
30
|
+
Usage
|
|
31
|
+
----
|
|
32
|
+
|
|
33
|
+
All commands and options are documented in detail in the command-line help. Run `dindbox -h` for a list of available
|
|
34
|
+
commands, and `dindbox COMMAND -h` for help on each command.
|
|
35
|
+
|
|
36
|
+
The most basic use case is to directly start an interactive session:
|
|
37
|
+
`dindbox my_box run`
|
|
38
|
+
Where `my_box` is the name of your dindbox which you can re-use in further commands to interact with it. The `run`
|
|
39
|
+
command without further parameters will give you an Alpine Linux based environment, with a fully functional docker
|
|
40
|
+
client & daemon - encapsulated within docker containers themselves (docker-in-docker). The container containing the
|
|
41
|
+
docker daemon is referred to as *service container*. The container with which you're interacting, which contains the
|
|
42
|
+
docker client is referred to as *build container*.
|
|
43
|
+
|
|
44
|
+
If you are on an ubuntu-based system, `run` will also open a status screen in a separate console window. You may close
|
|
45
|
+
this status screen at any time, it is only for monitoring purposes. Also, you can reopen it at any time running
|
|
46
|
+
`dindbox my_box status` from a separate shell window.
|
|
47
|
+
|
|
48
|
+
If you'd rather use an ubuntu image, do something like the following to change the default build container image:
|
|
49
|
+
`dindbox my_box run -i ubuntu:focal`
|
|
50
|
+
Note that in this case you will need to manually install the docker **client**, since it is not part of the ubuntu
|
|
51
|
+
image. The docker daemon however, will already be available, since it runs inside the service container.
|
|
52
|
+
|
|
53
|
+
Note that you may also replace the service container's image (using `-I`). Normally, it should always be a `dind`
|
|
54
|
+
tag of the official docker image, but you can use this to test with different versions of docker, for example.
|
|
55
|
+
Nevertheless, other use cases are possible, too, like running a SQL server is in the service image, and the client in
|
|
56
|
+
the build image.
|
|
57
|
+
|
|
58
|
+
When you're done, you should always clean up boxes which you do not need anymore. In order to remove all docker entities
|
|
59
|
+
associated with your dindbox, run:
|
|
60
|
+
`dindbox my_box remove`
|
|
61
|
+
Or, if you know it is a throw-away box, directly append `--rm` to the `run` command for automatic cleanup after exiting.
|
|
62
|
+
|
|
63
|
+
For further commands, check out the command-line help. Note that `run` is a shortcut for `create` + `start` + `attach`.
|
|
64
|
+
Only in special cases it makes sense to use these commands individually, for the most part you should be fine with
|
|
65
|
+
`run`.
|
|
66
|
+
|
|
67
|
+
Config file
|
|
68
|
+
----------
|
|
69
|
+
|
|
70
|
+
All command-line parameters can also be set through a config file, so you do not have to re-type them every time. Note
|
|
71
|
+
that config file settings only affect CLI usage. They have **no** effect at all when using dindbox as a Python library.
|
|
72
|
+
|
|
73
|
+
### Config file locations
|
|
74
|
+
|
|
75
|
+
Dindbox will look for a config file in three locations:
|
|
76
|
+
|
|
77
|
+
* First, it will traverse the directory structure upwards, starting with the current directory and looking for a
|
|
78
|
+
`pyproject.toml` file, as is usually present within a poetry environment. Any sections within that file of the format
|
|
79
|
+
`[tool.dindbox.*]` will be considered (see below for exact format).
|
|
80
|
+
* Next, any file in the *current directory* of name `dindbox.conf` will be parsed.
|
|
81
|
+
* Lastly, a config file specified with the `--config-file` or `-c` command-line argument will be parsed.
|
|
82
|
+
|
|
83
|
+
Config files will be parsed in the order specified above. Duplicate options provided in a later config file will
|
|
84
|
+
override values from previous config files. Additionally, a command-line parameter will always override a value set in
|
|
85
|
+
any of the config files.
|
|
86
|
+
|
|
87
|
+
### Config file format
|
|
88
|
+
|
|
89
|
+
Config files need to be in the TOML format. Arguments to each `dindbox` command are specified in a section named
|
|
90
|
+
`[dindbox.COMMAND]`, where `COMMAND` is the name of the command, e.g. `run`. The section name is case-sensitive.
|
|
91
|
+
Additionally, global arguments (the ones provided before a command and listed when running `dindbox --help`) can be
|
|
92
|
+
specified in a section named `[dindbox.global]`.
|
|
93
|
+
|
|
94
|
+
Argument names must be provided in their long form, without the leading `--`. Here's an example:
|
|
95
|
+
|
|
96
|
+
```toml title="dindbox.conf"
|
|
97
|
+
[dindbox.global]
|
|
98
|
+
log-level = "DEBUG"
|
|
99
|
+
|
|
100
|
+
[dindbox.run]
|
|
101
|
+
no-status-screen = true
|
|
102
|
+
rm = true
|
|
103
|
+
|
|
104
|
+
[dindbox.remove]
|
|
105
|
+
force = true
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Note:** When setting options in poetry's `pyproject.toml`, the section name needs to be prefixed with `tool.`:
|
|
109
|
+
|
|
110
|
+
```toml
|
|
111
|
+
[tool.dindbox.run]
|
|
112
|
+
rm = true
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Usage as a Python Library
|
|
116
|
+
------------------------
|
|
117
|
+
|
|
118
|
+
Althogh `dindbox` is primarily intended to be used as a command-line tool, it can also be used as a Python library and
|
|
119
|
+
you can create your own custom scripts and applications based on it. The main entry point is the `DindBox` class. Here's
|
|
120
|
+
a minimal example of how to use it:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from dindbox import DindBox
|
|
124
|
+
|
|
125
|
+
box = DindBox("my_box", build_image="ubuntu:focal")
|
|
126
|
+
box.run()
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
For further usage details, rely on the docstrings and type annotations of the `DindBox` class and its methods.
|
|
130
|
+
|
|
131
|
+
Use Cases
|
|
132
|
+
--------
|
|
133
|
+
|
|
134
|
+
Although there are probably more, DindBox was created with a particular set of use cases in mind. Most of these are
|
|
135
|
+
aimed at local testing on your development machine, but there are some rare cases, where it may even make sense to run
|
|
136
|
+
DindBox on your CI server. (In that case however, you're gonna need a dedicated runner, since DindBox itself should not
|
|
137
|
+
be run within a container.)
|
|
138
|
+
|
|
139
|
+
* **Test installation and execution of dockerized apps in a safe environment and on different Linux distributions**
|
|
140
|
+
You've created an application which is nicely bundled into microservices. Maybe there's also a nice little install
|
|
141
|
+
script to set it all up on a machine. But how do you test it? Hopefully not by running an untested script with root
|
|
142
|
+
permissions directly on your development machine. You'll either need a VM, or a tedious manually cobbled-together
|
|
143
|
+
docker setup - or you just type `dindbox run` and give it a go! And by switching out the image for the build container,
|
|
144
|
+
you can even easily test if your script runs fine on different Linux distros (and different releases of these).
|
|
145
|
+
|
|
146
|
+
* **Test a dockerized application against different versions of docker**
|
|
147
|
+
Switching the docker version locally means uninstalling and re-installing for each version switch. With DindBox, you
|
|
148
|
+
can just swap out the images and re-run your application (or re-build your images) based on a different release of
|
|
149
|
+
docker.
|
|
150
|
+
|
|
151
|
+
* **Reproduce and debug errors which occur in continuous integration (CI) jobs**
|
|
152
|
+
CI pipelines can be difficult to debug. And sometimes, the problem is not in the pipeline code alone, but also has to
|
|
153
|
+
do with the fact that the job is executed within a containerized runner. This can be particularly tricky, when
|
|
154
|
+
running docker commands as part of the pipeline, e.g. to test a self-built image. DindBox allows to easily reproduce
|
|
155
|
+
the containerized setup locally, with one simple command-line.
|
|
156
|
+
|
|
157
|
+
* **Build docker images locally within a well-defined environment**
|
|
158
|
+
In CI, your docker images are built in a containerized environment with a fixed docker version etc. DindBox makes it
|
|
159
|
+
easy to reproduce the exact same conditions locally.
|
|
160
|
+
|
|
161
|
+
* **Anything else you would otherwise use a virtual machine for**, because you need it to be isolated, and it requires
|
|
162
|
+
docker.
|
|
163
|
+
|
|
164
|
+
Note: the service running in the second container does not *have* to be dockerd. Since the image is freely configurable,
|
|
165
|
+
you could also switch it our for a database image like MySQL, and test your DB-dependent, non-dockerized application
|
|
166
|
+
in a DindBox. That's totally possible, but it is not what I had in mind when I created it.
|
|
167
|
+
|
|
168
|
+
How is it different from docker-compose?
|
|
169
|
+
---------------------------------------
|
|
170
|
+
|
|
171
|
+
Good question. For many use cases, docker-compose may be a good solution. But specifically for the testing use cases
|
|
172
|
+
listed above, DindBox offers some advantages, and also some specific features, which are not easily reproduced with
|
|
173
|
+
docker-compose:
|
|
174
|
+
|
|
175
|
+
* Ease of use: no need to create a config file, just type a short command-line with a few options, and you're up and
|
|
176
|
+
running. DindBox allows for some helpful configuration options, but the defaults will work fine, usually.
|
|
177
|
+
* Easy management of multiple boxes: each box has a specific name. By referencing that name you can easily manage,
|
|
178
|
+
re-use, and clean up your various test environments. All docker entities (containers, networks, volumes) that make
|
|
179
|
+
up a single box, will be set up or removed automatically, with a one-line command.
|
|
180
|
+
* Nice status screen: allows you to monitor what is going on inside a box, even if you're not interacting with it
|
|
181
|
+
directly.
|
|
182
|
+
* Bind volumes: In addition to attaching docker volumes to your containers, or bind-mounting existing host directories,
|
|
183
|
+
DindBox also offers to configure so-called "bind volumes". These are basically host directories which behave like
|
|
184
|
+
docker volumes: they are created on-demand in a temporary folder, mounted to both DindBox containers, and cleaned up
|
|
185
|
+
on removal of the DindBox. They can be used for specific cases, which are not supported by standard docker volumes.
|
|
186
|
+
One example for this is running a user-space file system within on of your docker-ind-docker containers, and have it
|
|
187
|
+
access the volume.
|
|
188
|
+
|
|
189
|
+
Development
|
|
190
|
+
----------
|
|
191
|
+
|
|
192
|
+
DindBox uses [poetry](https://python-poetry.org) for dependency management, isolation and packaging.
|
|
193
|
+
|
|
194
|
+
* If you do not have it already, install poetry on your machine as described in
|
|
195
|
+
[its documentation](https://python-poetry.org/docs/#installation). Make sure to install in an isolated environment
|
|
196
|
+
(the official installer does that), do not simply `pip install` it.
|
|
197
|
+
* Optional: enable poetry bash completion, as described in the docs
|
|
198
|
+
* Clone this repository and enter the directory
|
|
199
|
+
* Run `poetry install`
|