• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

docs/H28-Jun-2020-136101

example/H28-Jun-2020-1,142835

focker/H28-Jun-2020-1,9881,504

ports/H28-Jun-2020-7851

scripts/H28-Jun-2020-213180

tests/H28-Jun-2020-1,8441,568

.gitignoreH A D28-Jun-2020168 1312

READMEH A D28-Jun-2020148 21

README.mdH A D28-Jun-202014.9 KiB379268

setup.pyH A D28-Jun-2020661 2018

README

1Focker is a FreeBSD image orchestration tool in the vein of Docker. Please visit https://github.com/sadaszewski/focker for exhaustive information.
2

README.md

1# Focker
2
3## Introduction
4
5Focker is a FreeBSD image orchestration tool in the vein of Docker. This
6page contains a detailed reference of Focker's functionality. If it is your
7first time using Focker, please refer to the
8[Basic Usage Guide](docs/Basic_Usage_Guide.md) first.
9
10## Table of Contents
11
12<!-- TOC depthFrom:2 depthTo:4 withLinks:1 updateOnSave:1 orderedList:0 -->
13
14- [Introduction](#introduction)
15- [Table of Contents](#table-of-contents)
16- [Installation](#installation)
17	- [Installing the Python package from PyPi](#installing-the-python-package-from-pypi)
18	- [Installing the Python package from GitHub](#installing-the-python-package-from-github)
19	- [Setting up ZFS](#setting-up-zfs)
20	- [Preparing base image](#preparing-base-image)
21- [Usage](#usage)
22	- [`focker` command syntax](#focker-command-syntax)
23		- [focker image|img|im|i](#focker-imageimgimi)
24		- [focker jail|j](#focker-jailj)
25		- [focker volume|vol|v](#focker-volumevolv)
26		- [focker compose|comp|c](#focker-composecompc)
27	- [`Fockerfile` syntax](#fockerfile-syntax)
28	- [`focker-compose.yml` syntax](#focker-composeyml-syntax)
29		- [Images](#images)
30		- [Jails](#jails)
31		- [Volumes](#volumes)
32		- [Commands](#commands)
33- [Further Reading](#further-reading)
34- [Conclusion](#conclusion)
35- [Links](#links)
36
37<!-- /TOC -->
38
39## Installation
40
41In order to use Focker you need a ZFS pool available in your FreeBSD installation.
42
43### Installing the Python package from PyPi
44
45Run:
46
47```bash
48pip install focker
49```
50
51### Installing the Python package from GitHub
52
53Run:
54
55```bash
56git clone https://github.com/sadaszewski/focker.git
57cd focker/
58python setup.py install
59```
60
61or (if you want an uninstaller):
62
63```bash
64git clone https://github.com/sadaszewski/focker.git
65cd focker/
66python setup.py sdist
67pip install dist/focker-0.9.tgz
68```
69
70### Setting up ZFS
71
72Upon first execution of the `focker` command, Focker will automatically create the necessary directories and ZFS datasets. You just need to exclude the unlikely case that you are already using `/focker` in your filesystem hierarchy. The layout after initialization will look the following:
73
74```
75/focker
76/focker/images
77/focker/jails
78/focker/volumes
79```
80
81`images`, `jails`, and `volumes` have corresponding ZFS datasets with `canmount=off` so that they serve as mountpoint anchors for child entries.
82
83### Preparing base image
84
85To bootstrap the images system you need to install FreeBSD in jail mode to a ZFS dataset placed in `/focker/images` and provide two user-defined properties - `focker:sha256` and `focker:tags`. One way to achieve this would be the following (using Bash shell):
86
87```bash
88TAGS="freebsd-latest freebsd-$(freebsd-version | cut -d'-' -f1)"
89VERSION="FreeBSD $(freebsd-version)"
90SHA256=$(echo -n ${VERSION} | sha256)
91NAME=${SHA256:0:7}
92zfs create -o focker:sha256=${SHA256} -o focker:tags="${TAGS}" zroot/focker/images/${NAME}
93bsdinstall jail /focker/images/${NAME}
94zfs set readonly=on zroot/focker/images/${NAME}
95zfs snapshot zroot/focker/images/${NAME}@1
96```
97
98## Usage
99
100At this point, Focker is ready to use.
101
102### `focker` command syntax
103
104The `focker` command is the single entrypoint to all of the Focker's functionality. The overview of its syntax is presented below as a tree where the `focker` command is the root, the first level of descendants represents the choice of Level 1 mode (`image`, `jail`, `volume` or `compose`), the second level - the Level 2 mode (dependent on L1 mode) and the final third level lists required and optional arguments specific to the given combination of L1/L2 modes.
105
106```
107focker
108|- image|img|im|i
109|  |- build|b
110|  |  |- FOCKER_DIR
111|  |  `- --tags|-t TAG [...TAG]
112|  |- tag|t
113|  |  |- REFERENCE
114|  |  `- TAG [...TAG]
115|  |- untag|u
116|  |  `- TAG [...TAG]
117|  |- list|ls|l
118|  |  `- --full-sha256|-f
119|  |- prune|p
120|  `- remove|r
121|     |- REFERENCE
122|     `- --remove-dependents|-R
123|- jail|j
124|  |- create|c
125|  |  |- IMAGE
126|  |  |- --command|-c COMMAND (default: /bin/sh)
127|  |  |- --env|-e VAR1:VALUE1 [...VARN:VALUEN]
128|  |  |- --mounts|-m FROM1:ON1 [...FROMN:ONN]
129|  |  `- --hostname|-n HOSTNAME
130|  |- start|s
131|  |  `- REFERENCE
132|  |- stop|S
133|  |  `- REFERENCE
134|  |- remove|r
135|  |  `- REFERENCE
136|  |- exec|e
137|  |  |- REFERENCE
138|  |  `- [...COMMAND]
139|  |- oneshot|o
140|  |  `- IMAGE
141|  |  `- --env|-e VAR1:VALUE1 [...VARN:VALUEN]
142|  |  `- --mounts|-m FROM1:ON1 [...FROMN:ONN]
143|  |  `- [...COMMAND]
144|  |- list|ls|l
145|  |  `- --full-sha256|-f
146|  |- tag|t
147|  |  |- REFERENCE
148|  |  `- TAG [...TAG]
149|  |- untag|u
150|  |  `- TAG [...TAG]
151|  `- prune|p
152|     `- --force|-f
153|- volume|vol|v
154|  |- create
155|  |  `- --tags|-t TAG [...TAG]
156|  |- prune
157|  |- list
158|  |  `- --full-sha256|-f
159|  |- tag
160|  |  |- REFERENCE
161|  |  `- TAG [...TAG]
162|  `- untag
163|     `- TAG [...TAG]
164`- compose|comp|c
165   |- build
166   |  `- FILENAME
167   `- run
168      |- FILENAME
169      `- COMMAND
170```
171
172Individual combinations are briefly described below:
173
174#### focker image|img|im|i
175
176The `focker image` mode groups commands related to Focker images.
177
178##### build|b FOCKER_DIR [--tags TAG [...TAG]]
179
180Build a Focker image according to the specification in a Fockerfile present in the specified FOCKER_DIR. Fockerfile syntax is very straightforward and explained below.
181
182##### tag|t REFERENCE TAG [...TAG]
183
184Applies one or more tags to the given image. REFERENCE can be the SHA256 of an image or one of its existing tags. It can be just a few first characters as long as they are unambiguous.
185
186##### untag|u TAG [...TAG]
187
188Removes one or more image tags.
189
190##### list|ls|l [--full-sha256|-f]
191
192Lists existing Focker images, optionally with full SHA256 checksums (instead of the default 7 first characters).
193
194##### prune|p
195
196Greedily removes existing Focker images without tags and without dependents.
197
198##### remove|r REFERENCE
199
200Removes the specified image.
201
202#### focker jail|j
203
204The `focker jail` mode groups commands related to Focker-managed jails.
205
206##### create|c IMAGE [--command|-c COMMAND] [--env|-e VAR1:VALUE1 [...VARN:VALUEN]] [--mounts|-m FROM1:ON1 [...FROMN:ONN]] [--hostname|-n HOSTNAME]
207
208Creates a new Focker-managed jail. A jail consists of a clone of the given `IMAGE` and an entry in `/etc/jail.conf`. The configuration entry uses `exec.prestart` and `exec.start` to specify how the runtime environment (mounts and environmental variables) should be set up. It also calls `COMMAND` as last in `exec.start`. If not specified `COMMAND` defaults to `/bin/sh`. The hostname can be specified using the `HOSTNAME` parameter. Mounts and environment variables are provided as tuples separated by a colon (:). The environmental variable specification consists of variable name followed by variable value. The mount specification consists of the "from path", followed by the "on path". "From path" can be a local system path or a volume name.
209
210##### start|s REFERENCE
211
212Starts the given jail specified by `REFERENCE`. `REFERENCE` can be the SHA256 of an existing jail or one of its existing tags. It can be just a few first characters as long as they are unambiguous. This command is equivalent of calling `jail -c`.
213
214##### stop|S REFERENCE
215
216Stops the given jail specified by `REFERENCE`. This command is equivalent to calling `jail -r`.
217
218##### remove|r REFERENCE
219
220Removes the given jail specified by `REFERENCE`. The jail is stopped if running, any filesystems mounted under its root directory are unmounted, its ZFS dataset and entry in `/etc/jail.conf` are removed.
221
222##### exec|e REFERENCE [...COMMAND]
223
224Executes given `COMMAND` (or `/bin/sh` if not specified) in the given running jail specified by `REFERENCE`. This command is the equivalent of calling `jexec`.
225
226##### oneshot|o IMAGE [--env|-e VAR1:VALUE1 [...VARN:VALUEN]] [--mounts|-m FROM1:ON1 [...FROMN:ONN]] [...COMMAND]
227
228Create a new one-time Focker-managed jail. The syntax and logic is identical to `focker jail create`, the difference being that the hostname cannot be specified and that the jail will be automatically removed when the `COMMAND` exits.
229
230Example: `focker jail oneshot freebsd-latest -e FOO:bar -- ls -al`
231
232##### list|ls|l
233
234Lists Focker-managed jails. For running jails their JIDs will be displayed.
235
236##### tag REFERENCE TAG [...TAG]
237
238Applies one or more tags to the given jail. REFERENCE can be the SHA256 of a jail or one of its existing tags. It can be just a few first characters as long as they are unambiguous.
239
240##### untag TAG [...TAG]
241
242Removes one or more jail tags.
243
244##### prune
245
246Removes existing Focker jails without tags.
247
248#### focker volume|vol|v
249
250The `focker volume` mode groups commands related to Focker volumes.
251
252##### create [--tags|-t TAG [...TAG]]
253
254Create a new Focker volume optionally tagged with the given `TAG`s.
255
256##### prune
257
258Removes existing Focker volumes without tags.
259
260##### list [--full-sha256|-f]
261
262Lists existing Focker volumes. Full SHA256 is displayed if the `-f` switch is used, otherwise only the first 7 characters will be shown.
263
264##### tag REFERENCE TAG [...TAG]
265
266Applies one or more tags to the given volume. REFERENCE can be the SHA256 of a volume or one of its existing tags. It can be just a few first characters as long as they are unambiguous.
267
268##### untag TAG [...TAG]
269
270Removes one or more volume tags.
271
272#### focker compose|comp|c
273
274The `focker compose` mode groups commands related to Focker composition files - `focker-compose.yml`.
275
276##### build FILENAME
277
278Builds images, volumes and jails according to the specification provided in the file pointed to by `FILENAME`.
279
280##### run FILENAME COMMAND
281
282Runs one of the commands (specified by `COMMAND`) from the composition file pointed to by `FILENAME`.
283
284### `Fockerfile` syntax
285
286A sample `Fockerfile` is pasted below.
287
288```yaml
289base: freebsd-latest
290
291steps:
292  - copy:
293    - [ '/tmp/x', '/etc/x' ]
294    - [ 'files/y', '/etc/y' ]
295  - copy: [ files/z, /etc/z ]
296  - run: |
297      pkg install -y python3
298  - run:
299      - pkg install -y py37-pip
300      - pkg install -y py37-yaml
301      - pkg install -y py37-certbot
302  - run: |
303      mkdir -p /persist/etc/ssh && \
304      sed -i '' -e 's/\/etc\/ssh\/ssh_host_/\/persist\/etc\/ssh\/ssh_host_/g' /etc/rc.d/sshd && \
305      sed -i '' -e 's/\/etc\/ssh\/ssh_host_/\/persist\/etc\/ssh\/ssh_host_/g' /etc/ssh/sshd_config && \
306      sed -i '' -e 's/#HostKey/HostKey/g' /etc/ssh/sshd_config
307```
308
309`Fockerfile` currently supports only two entries - `base` and `steps`. `base` specifies the parent image on top of which the operations described by `steps` are executed. Each entry in `steps` results in creation of a new image. Focker determines a checksum for each step and if the corresponding image already exists the step is skipped and work continues on top of the existing image. This is a powerful paradigm for image building experimentation where we can split the task into multiple steps and resume work from the last successful step in case of problems. It is a big time saver. `steps` is a list that can contain `copy` and `run` entries. The `copy` entry specifies a single one or a list of copy operations from local files to the image in form of the `[FROM, TO]` tuples. The `run` entry specifies a chain of commands to be executed within the image. It can be a list of string or a single string.
310
311### `focker-compose.yml` syntax
312
313A sample composition file illustrating all of the principles is pasted below.
314
315```yaml
316images:
317  wordpress-5: /path/to/wordpress_5_focker_dir
318
319jails:
320  wordpress:
321    image: wordpress-5
322    env:
323      SITE_NAME: Test site
324    mounts:
325      wp-volume2: /mnt/volume2
326      wp-volume1: /mnt/volume1
327    ip4.addr: 127.0.1.1
328    interface: lo1
329
330volumes:
331  wp-volume1: {}
332  wp-volume2: {}
333  wp-backup: {}
334
335commands:
336  backup:
337    jail: wordpress
338    command: |
339      mysqldump >/mnt/volume2/backup.sql
340    mounts:
341      wp-backup: /mnt/backup
342
343  restore:
344    jail: wordpress
345    command: |
346      mysql </mnt/volume2/backup.sql
347    mounts:
348      wp-backup: /mnt/backup
349```
350
351#### Images
352
353The `images` entry in Focker composition file specifies a dictionary from image tags to Focker directories (directories containing the `Fockerfile` and any supplementary files needed to build an image). Upon running `focker compose build` Focker will run `focker image build` for all of the specified directories and tag the results with the corresponding tags. This process can be repeated without significant performance penalty since the images will not need to be rebuilt unless their `Fockerfile`s or contexts change.
354
355#### Jails
356
357The `jails` entry in the Focker composition file specifies a dictionary from jail tags to jail specifications. A jail specification is a dictionary that can contain the following fields: `image`, `env`, `mounts`, `exec.start`, `exec.stop`, `hostname`, `ip4.addr`, `interface`. `image`, `env` and `mounts` have the same semantics as in the `focker jail create` command. The syntax for `env` and `mounts` is in the form of dictionaries. `exec.start`, `exec.stop`, `hostname`, `ip4.addr` and `interface` have the same semantics as the corresponding entries in `/etc/jail.conf`. The jails will be recreated each time `focker compose build` is executed. Hence, any persistent data should be stored in volumes.
358
359#### Volumes
360
361The `volumes` entry in the Focker composition file specifies a dictionary from volume tags to volume specifications. Currently a volume specification must be an empty dictionary. Specified volumes will be created by `focker compose build` and tagged with corresponding tags unless volumes with given tags already exist. Volumes are meant to persist data beyond the jail lifecycle.
362
363#### Commands
364
365The `commands` entry in the Focker composition file specifies a dictionary from command names to command specifications. A command specification can contain the following fields: `jail`, `mounts` and `command`. The `jail` field specifies in which jail the given command should be executed (the jail must be already running). The `mounts` entry specifies additional mounts that will be used only during the execution of the command. Finally the `command` entry specifies the command itself using the same syntax as the `run` step in a `Fockerfile`.
366
367## Further Reading
368
369The best way to learn is by practice. Take a look at the [example](example/) and start writing your own Focker specifications.
370
371## Conclusion
372
373Focker provides powerful containerization primitives (images, volumes and containers) first introduced by the Docker platform without taking up the significantly more challenging task of achieving Docker compatibility. This has never been and never will be the goal of Focker which allows it to remain a lightweight tool with minimal dependencies and highly maintainable codebase. At the same time, the image building paradigm based on checksummed steps/layers and flexible composition builder offer significant time savings to pragmatic sysadmins.
374
375## Links
376
377- [PyPi entry for Focker](https://pypi.org/project/focker/)
378- [Focker Announcement on ADARED](https://adared.ch/focker)
379