dockerTools.streamLayeredImage: add fakeRootCommands option

This commit is contained in:
vroad 2021-03-19 10:25:26 +09:00
parent 3ee1fb4f09
commit b4d92811be

View File

@ -7,6 +7,7 @@
coreutils, coreutils,
docker, docker,
e2fsprogs, e2fsprogs,
fakeroot,
findutils, findutils,
go, go,
jq, jq,
@ -738,6 +739,9 @@ rec {
created ? "1970-01-01T00:00:01Z", created ? "1970-01-01T00:00:01Z",
# Optional bash script to run on the files prior to fixturizing the layer. # Optional bash script to run on the files prior to fixturizing the layer.
extraCommands ? "", extraCommands ? "",
# Optional bash script to run inside fakeroot environment.
# Could be used for changing ownership of files in customisation layer.
fakeRootCommands ? "",
# We pick 100 to ensure there is plenty of room for extension. I # We pick 100 to ensure there is plenty of room for extension. I
# believe the actual maximum is 128. # believe the actual maximum is 128.
maxLayers ? 100 maxLayers ? 100
@ -764,18 +768,24 @@ rec {
name = "${baseName}-customisation-layer"; name = "${baseName}-customisation-layer";
paths = contentsList; paths = contentsList;
inherit extraCommands; inherit extraCommands;
inherit fakeRootCommands;
nativeBuildInputs = [ fakeroot ];
postBuild = '' postBuild = ''
mv $out old_out mv $out old_out
(cd old_out; eval "$extraCommands" ) (cd old_out; eval "$extraCommands" )
mkdir $out mkdir $out
tar \ fakeroot bash -c '
--sort name \ set -e
--owner 0 --group 0 --mtime "@$SOURCE_DATE_EPOCH" \ cd old_out
--hard-dereference \ eval "$fakeRootCommands"
-C old_out \ tar \
-cf $out/layer.tar . --sort name \
--numeric-owner --mtime "@$SOURCE_DATE_EPOCH" \
--hard-dereference \
-cf $out/layer.tar .
'
sha256sum $out/layer.tar \ sha256sum $out/layer.tar \
| cut -f 1 -d ' ' \ | cut -f 1 -d ' ' \