CentOS / sig-cloud-instance-build

CentOS Cloud Instance SIG: Metadata to build & release instances
362 stars 167 forks source link

Anaconda log files and tmp kickstart files are not removed #129

Closed ghost closed 6 years ago

ghost commented 6 years ago

The kickstart files for the CentOS 7 Docker images contain post commands which should remove "thing we don't need", e.g. the Anaconda log files and temporary kickstart scripts

$ cat docker/centos-7.ks
...
rm -f /tmp/ks-script*
rm -rf /var/log/anaconda
rm -rf /tmp/ks-script*
...

but these files are still part of the CentOS 7 images

$ docker run --rm -it centos:7 find /var/log/anaconda
/var/log/anaconda
/var/log/anaconda/storage.log
/var/log/anaconda/anaconda.log
/var/log/anaconda/packaging.log
/var/log/anaconda/ks-script-sb0l8b.log
/var/log/anaconda/journal.log
/var/log/anaconda/ks-script-2ziUl6.log
/var/log/anaconda/ks-script-hE5IPf.log
/var/log/anaconda/program.log
/var/log/anaconda/ifcfg.log

$ docker run --rm -it centos:7 find /tmp
/tmp
/tmp/.XIM-unix
/tmp/ks-script-hE5IPf
/tmp/yum.log
/tmp/.X11-unix
/tmp/.font-unix
/tmp/.ICE-unix
/tmp/.Test-unix

How to remove these files via the post configuration?

ghost commented 6 years ago

The reason for the logs is the Anaconda post copy logs script

[root@localhost tmp]# cat /usr/share/anaconda/post-scripts/99-copy-logs.ks
# Note, this script log will not be copied to the installed system.
%post --nochroot

NOSAVE_INPUT_KS_FILE=/tmp/NOSAVE_INPUT_KS
NOSAVE_LOGS_FILE=/tmp/NOSAVE_LOGS
PRE_ANA_LOGS=/tmp/pre-anaconda-logs

if [ -e ${NOSAVE_LOGS_FILE} ]; then
    rm -f ${NOSAVE_LOGS_FILE}
else
    mkdir -p $ANA_INSTALL_PATH/var/log/anaconda
    for log in anaconda.log syslog X.log program.log packaging.log storage.log ifcfg.log yum.log; do
        [ -e /tmp/$log ] && cp /tmp/$log $ANA_INSTALL_PATH/var/log/anaconda/
    done
    [ -e /tmp/pre-anaconda-logs ] && cp -r $PRE_ANA_LOGS $ANA_INSTALL_PATH/var/log/anaconda
    cp /tmp/ks-script*.log $ANA_INSTALL_PATH/var/log/anaconda/
    journalctl -b > $ANA_INSTALL_PATH/var/log/anaconda/journal.log
    chmod 0600 $ANA_INSTALL_PATH/var/log/anaconda/*

    # Copy over any rhsm logs
    [ -e /var/log/rhsm/ ] && cp -r /var/log/rhsm $ANA_INSTALL_PATH/var/log/
fi

if [ -e ${NOSAVE_INPUT_KS_FILE} ]; then
    rm -f ${NOSAVE_INPUT_KS_FILE}
else
    [ -e /run/install/ks.cfg ] && cp /run/install/ks.cfg $ANA_INSTALL_PATH/root/original-ks.cfg
fi

%end

Might a touch /tmp/NOSAVE_LOGS in a %pre configuration script prevent the logs in the Docker image? Should that be done? Or should the logs be shipped with the image?