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