diff --git a/create-changelog-to-go-from-old-to-new.sh b/create-changelog-to-go-from-old-to-new.sh index 6e5a891..3a90597 100755 --- a/create-changelog-to-go-from-old-to-new.sh +++ b/create-changelog-to-go-from-old-to-new.sh @@ -5,11 +5,14 @@ echo "List of changes necessary to go from old image contents to new: " rsync -a -x --human-readable --delete-after --checksum --dry-run --itemize-changes --exclude .docker-image-diff "$RESTRICT_DIFF_TO_PATH/" "rsync://rsync@old/root$RESTRICT_DIFF_TO_PATH/" | tee $OUT/changes.rsync.log # Add files to add to a tar archive -cat $OUT/changes.rsync.log | grep '^ $OUT/files-to-add.list -tar -cf $OUT/files-to-add.tar -T $OUT/files-to-add.list 2>&1 | grep -v "Removing leading" +cat $OUT/changes.rsync.log | grep -E '^ $OUT/files-to-add_2.list + +# soft links (^cL in the grep above) have -> in the list which must be removed. Hard links ^hf have => +cat $OUT/files-to-add_2.list | grep -oP '^\K.*?(?= ->| =>|$)' > $OUT/files-to-add.list +tar -C / -cf $OUT/files-to-add.tar -T $OUT/files-to-add.list 2>&1 # Add files to remove to a list -cat $OUT/changes.rsync.log | grep '^*deleting' | while read -a cols; do echo "$RESTRICT_DIFF_TO_PATH/"${cols[@]:1}; done > $OUT/files-to-remove.list +cat $OUT/changes.rsync.log | grep '^*deleting' | grep -v 'tmp\/\.rsyncd\.conf' | while read -a cols; do echo "$RESTRICT_DIFF_TO_PATH/"${cols[@]:1}; done > $OUT/files-to-remove.list # Informational output echo @@ -20,6 +23,6 @@ echo "Number of files to remove: " wc $OUT/files-to-remove.list echo echo "Changes not accounted for: " -cat $OUT/changes.rsync.log | grep -v '^ /tmp/.rsyncd.conf; echo "path = /" >> /tmp/.rsyncd.conf; echo "read only = false" >> /tmp/.rsyncd.conf; +echo "uid = 0" >> /tmp/.rsyncd.conf; +echo "gid = 0" >> /tmp/.rsyncd.conf; + rsync --daemon --port 873 --no-detach -vv --config /tmp/.rsyncd.conf diff --git a/shrink_images.sh b/shrink_images.sh new file mode 100755 index 0000000..efcf2b8 --- /dev/null +++ b/shrink_images.sh @@ -0,0 +1,7 @@ +echo "Usage shrink_images.sh [RESTRICT_DIFF_TO_PATH]" +export RESTRICT_DIFF_TO_PATH=$4 +export OLD_IMAGE=$1 +export NEW_IMAGE=$2 +docker-compose -f rsync-image-diff.docker-compose.yml up +docker-compose -f shell.docker-compose.yml -f process-image-diff.docker-compose.yml run --rm shell ./generate-dockerfile.sh +cd output; docker build -t $3 .; cd .. diff --git a/template.Dockerfile b/template.Dockerfile index 801e2d8..57bcd03 100644 --- a/template.Dockerfile +++ b/template.Dockerfile @@ -1,4 +1,4 @@ FROM ${OLD_IMAGE} ADD files-to-add.tar / ADD files-to-remove.list /.files-to-remove.list -RUN if [ -s /.files-to-remove.list ]; then xargs -d '\n' -a /.files-to-remove.list rm && rm /.files-to-remove.list; fi +RUN if [ -s /.files-to-remove.list ]; then xargs -d '\n' -a /.files-to-remove.list rm; fi; rm /.files-to-remove.list;