cookbook/container: example of building+running docker containers.
This got... long... and complicated. But I think it's a really good demonstration of getting redo to do complicated things elegantly. At least, I hope it is.
This commit is contained in:
parent
01497f55e9
commit
3923a7d3f8
38 changed files with 1375 additions and 7 deletions
34
docs/cookbook/container/default.image.do
Normal file
34
docs/cookbook/container/default.image.do
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
redo-ifchange template.json "$1.layers"
|
||||
layers=$(cat "$1.layers")
|
||||
|
||||
dir=$3.tmp
|
||||
rm -rf "$dir"
|
||||
mkdir -p "$dir"
|
||||
|
||||
# Build all layers in parallel
|
||||
for layer in $layers; do
|
||||
echo "$layer.list.sha256"
|
||||
echo "$layer.layer"
|
||||
done | xargs redo-ifchange
|
||||
|
||||
ids=
|
||||
parent=
|
||||
for layer in $layers; do
|
||||
read cid <$layer.list.sha256
|
||||
echo "layer: $cid $layer" >&2
|
||||
|
||||
# docker seems to order its image tarballs latest-first,
|
||||
# so the base layer is last. We'll create in order from
|
||||
# base layer to final layer, but create a tarball in the
|
||||
# opposite order.
|
||||
ids="$cid $ids" # prepend
|
||||
|
||||
mkdir "$dir/$cid"
|
||||
echo "1.0" >$dir/$cid/VERSION
|
||||
./dockjson.py "$layer" "$parent" >$dir/$cid/json
|
||||
ln "$layer.layer" "$dir/$cid/layer.tar"
|
||||
parent=$layer
|
||||
done <$1.layers
|
||||
|
||||
tar -C "$dir" -cf - $ids >$3
|
||||
rm -rf "$dir"
|
||||
Loading…
Add table
Add a link
Reference in a new issue