From 0fa8b8505bb2c4b57fab8ad58e9794181a164794 Mon Sep 17 00:00:00 2001 From: Olaf Meeuwissen Date: Thu, 17 Aug 2017 11:13:48 +0900 Subject: [PATCH] Keep "flab" out of the image This integrates a custom script into the APT configuration. That same script is also run during the bootstrap. A second custom script takes care of the integration and removes itself when done. Complements 13f84159. --- bootstrap.sh | 8 ++++++-- scripts/docker-apt-clean | 20 ++++++++++++++++++++ scripts/tweak-apt-config | 24 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100755 scripts/docker-apt-clean create mode 100755 scripts/tweak-apt-config diff --git a/bootstrap.sh b/bootstrap.sh index 05a0211..16b7eec 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -14,5 +14,9 @@ rootfs=/devuan/rootfs debootstrap --variant=minbase jessie $rootfs -find $rootfs/var/cache/apt/ -type f -delete -find $rootfs/var/lib/apt/ -type f -delete +bindir=usr/local/bin +cp -a scripts/* $rootfs/$bindir + +for script in $(ls $rootfs/$bindir); do + chroot $rootfs /$bindir/$script +done diff --git a/scripts/docker-apt-clean b/scripts/docker-apt-clean new file mode 100755 index 0000000..95b970a --- /dev/null +++ b/scripts/docker-apt-clean @@ -0,0 +1,20 @@ +#!/bin/sh +# docker-apt-clean -- to keep Docker image size small +# Copyright (C) 2017 Olaf Meeuwissen +# +# License: GPL-3.0+ + +# Running `apt-get clean` from within apt-get causes deadlock due to +# the locking mechanism used by apt-get. This script has a similar +# effect as running `apt-get clean` but circumvents the deadlock. + +DIR=/ +STATE=var/lib/apt/ +CACHE=var/cache/apt/ + +eval $(apt-config shell DIR Dir) +eval $(apt-config shell STATE Dir::State) +eval $(apt-config shell CACHE Dir::Cache) + +find $DIR$STATE -type f -delete +find $DIR$CACHE -type f -delete diff --git a/scripts/tweak-apt-config b/scripts/tweak-apt-config new file mode 100755 index 0000000..20c8bf0 --- /dev/null +++ b/scripts/tweak-apt-config @@ -0,0 +1,24 @@ +#!/bin/sh -eu +# tweak-apt-config -- for use in a Docker image +# Copyright (C) 2017 Olaf Meeuwissen +# +# License: GPL-3.0+ + +DIR=/ +ETC=etc/apt +PARTS=apt.conf.d + +eval $(apt-config shell DIR Dir) +eval $(apt-config shell ETC Dir::Etc) +eval $(apt-config shell PARTS Dir::Etc::Parts) + +cfg=$DIR$ETC$PARTS + +cmd=$(dirname $0)/docker-apt-clean +cat > $cfg/docker-clean <<- EOF +DPkg::Post-Invoke { "if test -x $cmd; then $cmd; fi"; }; +APT::Update::Post-Invoke { "if test -x $cmd; then $cmd; fi"; }; +EOF +chmod 0644 $cfg/docker-clean + +rm $0