mirror of
https://github.com/AlmaLinux/ks2rootfs.git
synced 2024-11-25 02:23:08 +00:00
Signed-off-by: Bala Raman <srbala@gmail.com>
This commit is contained in:
parent
18d0fdad4c
commit
5587ba7a77
@ -1,7 +1,11 @@
|
|||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Multi stage build, using Micro version AlmaLinux as foundation for end image
|
||||||
|
# Final image designed for specific purposes, don't have dnf, microdnf or yum
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
FROM almalinux:8 as builder
|
FROM almalinux:8 as builder
|
||||||
|
|
||||||
RUN mkdir -p /mnt/system-root /mnt/system-root/build; \
|
RUN mkdir -p /mnt/system-root /mnt/system-root/build; \
|
||||||
dnf install --installroot /mnt/system-root --releasever 8 --setopt=install_weak_deps=false --setopt=tsflags=nodocs -y coreutils-single \
|
dnf install --installroot /mnt/system-root --releasever 8 --setopt=install_weak_deps=False --setopt=tsflags=nodocs -y coreutils-single \
|
||||||
bash \
|
bash \
|
||||||
glibc-minimal-langpack \
|
glibc-minimal-langpack \
|
||||||
anaconda-tui \
|
anaconda-tui \
|
||||||
@ -9,6 +13,7 @@ RUN mkdir -p /mnt/system-root /mnt/system-root/build; \
|
|||||||
jq \
|
jq \
|
||||||
tar \
|
tar \
|
||||||
policycoreutils \
|
policycoreutils \
|
||||||
|
# Optional include to avoid runtime warning -- starts
|
||||||
libblockdev-mdraid \
|
libblockdev-mdraid \
|
||||||
libblockdev-crypto \
|
libblockdev-crypto \
|
||||||
libblockdev-lvm \
|
libblockdev-lvm \
|
||||||
@ -17,11 +22,13 @@ RUN mkdir -p /mnt/system-root /mnt/system-root/build; \
|
|||||||
libblockdev-loop \
|
libblockdev-loop \
|
||||||
libblockdev-nvdimm \
|
libblockdev-nvdimm \
|
||||||
libblockdev-mpath \
|
libblockdev-mpath \
|
||||||
|
# Optional include to avoid runtime warning -- ends
|
||||||
rootfiles; \
|
rootfiles; \
|
||||||
rm -rf /mnt/system-root/var/cache/* ; \
|
rm -rf /mnt/system-root/var/cache/* ; \
|
||||||
dnf clean all; \
|
dnf clean all; \
|
||||||
cp /etc/yum.repos.d/* /mnt/system-root/etc/yum.repos.d/ ; \
|
cp /etc/yum.repos.d/* /mnt/system-root/etc/yum.repos.d/ ; \
|
||||||
rm -rf /var/cache/yum; \
|
rm -rf /var/cache/yum; \
|
||||||
|
# TODO: commands below move to side script or remove?
|
||||||
# generate build time file for compatibility with CentOS
|
# generate build time file for compatibility with CentOS
|
||||||
/bin/date +%Y%m%d_%H%M > /mnt/system-root/etc/BUILDTIME ;\
|
/bin/date +%Y%m%d_%H%M > /mnt/system-root/etc/BUILDTIME ;\
|
||||||
# set DNF infra variable to container for compatibility with CentOS
|
# set DNF infra variable to container for compatibility with CentOS
|
||||||
|
30
README.md
30
README.md
@ -5,8 +5,10 @@ This project provides the ability build `rootfs` file from `kickstart` input fil
|
|||||||
## HOW-TO
|
## HOW-TO
|
||||||
|
|
||||||
Image yet ot published in `hub.docker.com`, until then use local build.
|
Image yet ot published in `hub.docker.com`, until then use local build.
|
||||||
|
|
||||||
### Building local
|
### Building local
|
||||||
```
|
|
||||||
|
```sh
|
||||||
docker build -t srbala/ks2rootfs .
|
docker build -t srbala/ks2rootfs .
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -14,9 +16,33 @@ docker build -t srbala/ks2rootfs .
|
|||||||
|
|
||||||
Following command uses the `kickstarts/almalinux-8-default.x86_64.ks` file to build.
|
Following command uses the `kickstarts/almalinux-8-default.x86_64.ks` file to build.
|
||||||
|
|
||||||
```
|
```sh
|
||||||
docker run --rm --privileged -v "$PWD:/build:z" \
|
docker run --rm --privileged -v "$PWD:/build:z" \
|
||||||
-e BUILD_KICKSTART=kickstarts/almalinux-8-default.x86_64.ks \
|
-e BUILD_KICKSTART=kickstarts/almalinux-8-default.x86_64.ks \
|
||||||
-e BUILD_ROOTFS=almalinux-8-default-docker.x86_64.tar.gz \
|
-e BUILD_ROOTFS=almalinux-8-default-docker.x86_64.tar.gz \
|
||||||
srbala/ks2rootfs
|
srbala/ks2rootfs
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Environment variables
|
||||||
|
|
||||||
|
Container startup script `ks2rootfs` supports multiple environment varible to customize the output. The environment variables and their use as follows
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ENVIRONMENT VARIABLES:
|
||||||
|
======================
|
||||||
|
|
||||||
|
BUILD_KICKSTART : Input kickstart source file (.ks) - Required
|
||||||
|
BUILD_ROOTFS : Rootfs output file name - Required
|
||||||
|
|
||||||
|
BUILD_WORK_DIR : Working dir for kickstart source and image destination (default current directory) - Optional
|
||||||
|
BUILD_OUTDIR : Output directory name in working dir - Optional
|
||||||
|
BUILD_FLAG_OUTOUT_IN_PWD : Set this flag to true to write output files in current working directory. Default value is 'false'. When value is set to 'true', any value passed to 'BUILD_OUTDIR' will be ignored.
|
||||||
|
BUILD_FLAG_WRITE_META : Generate meta data about the kickstart build system - Optional
|
||||||
|
BUILD_FLAG_RETAIN_LOG : Retain generated output log files under 'logs' output directory - Optional
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
ks2rootfs KICKSTART_FILE_NAME ROOTFS_FILE_NAME
|
||||||
|
|
||||||
|
EXAMPLES:
|
||||||
|
ks2rootfs os-minimal.ks os-minimal.tar.xz
|
||||||
|
```
|
||||||
|
@ -5,28 +5,83 @@
|
|||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat 1>&2 <<EOF
|
cat 1>&2 <<EOF
|
||||||
Script to create roofs from kickstart file using livemedia-creator
|
Script to create roofs file from a kickstart file using livemedia-creator
|
||||||
|
|
||||||
ENVIRONMENT VARS:
|
ENVIRONMENT VARIABLES:
|
||||||
BUILD_WORK_DIR Working dir for kickstart source and image destination (default current directory)
|
======================
|
||||||
BUILD_KICKSTART Input kickstart source file (.ks)
|
|
||||||
BUILD_ROOTFS Rootfs output file name
|
BUILD_KICKSTART : Input kickstart source file (.ks) - Required
|
||||||
|
BUILD_ROOTFS : Rootfs output file name - Required
|
||||||
|
|
||||||
|
BUILD_WORK_DIR : Working dir for kickstart source and image destination (default current directory) - Optional
|
||||||
|
BUILD_OUTDIR : Output directory name in working dir - Optional
|
||||||
|
BUILD_FLAG_OUTOUT_IN_PWD : Set this flag to true to write output files in current working directory. Default value is false. When value is set to `true`, any value passed to `BUILD_OUTDIR` will be ignored.
|
||||||
|
BUILD_FLAG_WRITE_META : Generate meta data about the kickstart build system - Optional
|
||||||
|
BUILD_FLAG_RETAIN_LOG : Retain generated output log files under 'logs' output directory - Optional
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
ks2rootfs KICKSTART_FILE_NAME ROOTFS_FILE_NAME
|
ks2rootfs KICKSTART_FILE_NAME ROOTFS_FILE_NAME
|
||||||
|
|
||||||
EXAMPLES:
|
EXAMPLES:
|
||||||
ks2rootfs centos8-minimal.ks centos8-minimal.tar.xz
|
ks2rootfs os-minimal.ks os-minimal.tar.xz
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
run-summary() {
|
||||||
|
cat 1>&2 <<EOF
|
||||||
|
|
||||||
|
ks2rootfs - Script input summary:
|
||||||
|
|
||||||
|
FLAGS
|
||||||
|
-----
|
||||||
|
FLAG_OUTOUT_PWD : ${BUILD_FLAG_OUTOUT_IN_PWD}
|
||||||
|
FLAG_WRITE_META : ${BUILD_FLAG_WRITE_META}
|
||||||
|
FLAG_RETAIN_LOG : ${BUILD_FLAG_RETAIN_LOG}
|
||||||
|
|
||||||
|
VARIABLES
|
||||||
|
---------
|
||||||
|
BUILD_WORK_DIR : ${BUILD_WORK_DIR}
|
||||||
|
BUILD_OUTDIR : ${BUILD_OUTDIR}
|
||||||
|
BUILD_LOGDIR : ${BUILD_LOGDIR}
|
||||||
|
INPUT_KICKSTART : ${BUILD_WORK_DIR}${BUILD_KICKSTART}
|
||||||
|
OUTPUT_ROOTFS : ${BUILD_OUTDIR}/${BUILD_ROOTFS}
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
BUILD_WORK_DIR=${BUILD_WORK_DIR:-./}
|
BUILD_WORK_DIR=${BUILD_WORK_DIR:-./}
|
||||||
BUILD_KICKSTART=${BUILD_KICKSTART:-$1}
|
BUILD_KICKSTART=${BUILD_KICKSTART:-$1}
|
||||||
BUILD_ROOTFS=${BUILD_ROOTFS:-$2}
|
BUILD_ROOTFS=${BUILD_ROOTFS:-$2}
|
||||||
BUILD_OUTDIR=${BUILD_OUTDIR:-./result}
|
BUILD_FLAG_WRITE_META=${BUILD_FLAG_WRITE_META:-true}
|
||||||
BUILD_WRITE_META=${BUILD_WRITE_META:-true}
|
BUILD_FLAG_RETAIN_LOG=${BUILD_FLAG_RETAIN_LOG:-false}
|
||||||
BUILD_RETAIN_LOG=${BUILD_RETAIN_LOG:-false}
|
BUILD_FLAG_OUTOUT_IN_PWD=${BUILD_FLAG_OUTOUT_IN_PWD:-false}
|
||||||
|
|
||||||
|
USE_PWD_OUTPUT=${USE_PWD_OUTPUT:-false}
|
||||||
|
|
||||||
|
BUILD_OUTDIR=${BUILD_OUTDIR:-result}
|
||||||
|
BUILD_LOGDIR=${BUILD_OUTDIR}/logs
|
||||||
|
|
||||||
|
if [ ${BUILD_FLAG_OUTOUT_IN_PWD} == 'true' ]; then
|
||||||
|
echo 'Build output files will be in current working folder ... '
|
||||||
|
BUILD_OUTDIR=${BUILD_WORK_DIR}
|
||||||
|
else
|
||||||
|
BUILD_OUTDIR=${BUILD_WORK_DIR}${BUILD_OUTDIR:-result}
|
||||||
|
echo "Build output files will be in '${BUILD_OUTDIR}' folder ... "
|
||||||
|
if [[ -d "${BUILD_OUTDIR}" ]]; then
|
||||||
|
echo "Output directory ${BUILD_OUTDIR} already exists, please remove it"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
mkdir -p ${BUILD_OUTDIR}
|
||||||
|
if [[ -d "${BUILD_OUTDIR}" ]]; then
|
||||||
|
echo "Output directory ${BUILD_OUTDIR} created successfully"
|
||||||
|
else
|
||||||
|
echo "Error in creating output directory: ${BUILD_OUTDIR}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
BUILD_LOGDIR=${BUILD_OUTDIR}/logs
|
||||||
|
|
||||||
if [ -z ${BUILD_KICKSTART} ] || [ -z ${BUILD_ROOTFS} ]
|
if [ -z ${BUILD_KICKSTART} ] || [ -z ${BUILD_ROOTFS} ]
|
||||||
then
|
then
|
||||||
@ -35,6 +90,9 @@ then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Write run summary to console
|
||||||
|
run-summary
|
||||||
|
|
||||||
# set anaconda base product
|
# set anaconda base product
|
||||||
cat << _EOF > /etc/anaconda/product.d/ks2rootfs.conf
|
cat << _EOF > /etc/anaconda/product.d/ks2rootfs.conf
|
||||||
# Anaconda configuration file for Kickstart to Rootfs.
|
# Anaconda configuration file for Kickstart to Rootfs.
|
||||||
@ -53,25 +111,38 @@ eula =
|
|||||||
_EOF
|
_EOF
|
||||||
|
|
||||||
# create rootfs
|
# create rootfs
|
||||||
livemedia-creator --logfile="/tmp/rootfs-creator.log" \
|
livemedia-creator --logfile="/tmp/ks2rootfs.log" \
|
||||||
--make-tar --ks="${BUILD_WORK_DIR}/${BUILD_KICKSTART}" --no-virt \
|
--make-tar --ks="${BUILD_WORK_DIR}/${BUILD_KICKSTART}" --no-virt \
|
||||||
--image-only --image-name="${BUILD_ROOTFS}" \
|
--image-only --image-name="${BUILD_ROOTFS}" \
|
||||||
--anaconda-arg "--product Kickstart to Rootfs"
|
--anaconda-arg "--product Kickstart to Rootfs"
|
||||||
|
|
||||||
# move rootfs to working dir
|
# copy rootfs to working dir
|
||||||
cp -rp /var/tmp/${BUILD_ROOTFS} ${BUILD_WORK_DIR}/${BUILD_ROOTFS}
|
cp -rp /var/tmp/${BUILD_ROOTFS} ${BUILD_OUTDIR}/${BUILD_ROOTFS}
|
||||||
|
|
||||||
# extract os-release info
|
if [ ${BUILD_FLAG_WRITE_META} == 'true' ]; then
|
||||||
tar -xvf /var/tmp/${BUILD_ROOTFS} -C /tmp/ --strip-components=3 ./usr/lib/os-release
|
# extract os-release info
|
||||||
os_release_id=$(awk -F= '$1=="ID" { print $2 ;}' /tmp/os-release | tr -d '"')
|
tar -xvf /var/tmp/${BUILD_ROOTFS} -C /tmp/ --strip-components=3 ./usr/lib/os-release
|
||||||
distro_release=$(grep "${os_release_id}.*-release-" /tmp/anaconda/packaging.log | grep -o "Verifying:.*" | sed -n 's/Verifying: //p')
|
os_release_id=$(awk -F= '$1=="ID" { print $2 ;}' /tmp/os-release | tr -d '"')
|
||||||
|
distro_release=$(grep "${os_release_id}.*-release-" /tmp/anaconda/packaging.log | grep -o "Verifying:.*" | sed -n 's/Verifying: //p')
|
||||||
if [ -z ${distro_release+x} ]; then
|
if [ -z ${distro_release+x} ]; then
|
||||||
exit 1
|
exit 1
|
||||||
|
else
|
||||||
|
echo 'Writting meta data ... '
|
||||||
|
# save distro release info
|
||||||
|
echo "$distro_release" > ${BUILD_OUTDIR}/distro-release
|
||||||
|
fi
|
||||||
|
# save list of packages installed
|
||||||
|
jq .[] -r /tmp/dnf.cache/tempfiles.json | awk -F '/' '{print $5}' | sort > ${BUILD_OUTDIR}/pkgs-list
|
||||||
else
|
else
|
||||||
# save distro release info
|
echo 'Skip writing meta data based on configuration.'
|
||||||
echo "$distro_release" > ${BUILD_WORK_DIR}/distro-release
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# save list of packages installed
|
if [ ${BUILD_FLAG_RETAIN_LOG} == 'true' ]; then
|
||||||
jq .[] -r /tmp/dnf.cache/tempfiles.json | awk -F '/' '{print $5}' | sort > ${BUILD_WORK_DIR}/pkgs-list
|
rm -rf ${BUILD_LOGDIR}
|
||||||
|
mkdir -p ${BUILD_LOGDIR} ${BUILD_LOGDIR}/anaconda
|
||||||
|
echo "Copying logs to '${BUILD_LOGDIR}'"
|
||||||
|
cp /tmp/ks2rootfs.log rm -rf ${BUILD_LOGDIR}/ks2rootfs.log
|
||||||
|
cp -rp /tmp/anaconda/* ${BUILD_LOGDIR}/anaconda
|
||||||
|
else
|
||||||
|
echo 'Skip writing logs data based on configuration (default). '
|
||||||
|
fi
|
||||||
|
99
tests/kickstarts/almalinux-8-default.x86_64.ks
Normal file
99
tests/kickstarts/almalinux-8-default.x86_64.ks
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
# AlmaLinux 8 kickstart file for x86_64 base Docker image
|
||||||
|
|
||||||
|
# install
|
||||||
|
url --url https://repo.almalinux.org/almalinux/8/BaseOS/x86_64/os/
|
||||||
|
|
||||||
|
lang en_US.UTF-8
|
||||||
|
keyboard us
|
||||||
|
timezone --nontp --utc UTC
|
||||||
|
|
||||||
|
network --activate --bootproto=dhcp --device=link --onboot=on
|
||||||
|
firewall --disabled
|
||||||
|
selinux --disabled
|
||||||
|
|
||||||
|
bootloader --disable
|
||||||
|
zerombr
|
||||||
|
clearpart --all --initlabel
|
||||||
|
autopart --fstype=ext4 --type=plain --nohome --noboot --noswap
|
||||||
|
|
||||||
|
rootpw --iscrypted --lock almalinux
|
||||||
|
|
||||||
|
shutdown
|
||||||
|
|
||||||
|
%packages --ignoremissing --excludedocs --instLangs=en --nocore --excludeWeakdeps
|
||||||
|
almalinux-release
|
||||||
|
bash
|
||||||
|
binutils
|
||||||
|
coreutils-single
|
||||||
|
dnf
|
||||||
|
findutils
|
||||||
|
glibc-minimal-langpack
|
||||||
|
hostname
|
||||||
|
iputils
|
||||||
|
less
|
||||||
|
rootfiles
|
||||||
|
tar
|
||||||
|
vim-minimal
|
||||||
|
yum
|
||||||
|
xz
|
||||||
|
|
||||||
|
-brotli
|
||||||
|
-crypto-policies-scripts
|
||||||
|
-firewalld
|
||||||
|
-diffutils
|
||||||
|
-elfutils-debuginfod-client
|
||||||
|
-gettext*
|
||||||
|
-glibc-langpack-en
|
||||||
|
-gnupg2-smime
|
||||||
|
-grub\*
|
||||||
|
-iptables
|
||||||
|
-kernel
|
||||||
|
-libevent
|
||||||
|
-openssl
|
||||||
|
-os-prober
|
||||||
|
-open-vm-tools
|
||||||
|
-pinentry
|
||||||
|
-platform-python-pip
|
||||||
|
-shared-mime-info
|
||||||
|
-trousers
|
||||||
|
-unbound-libs
|
||||||
|
-xkeyboard-config
|
||||||
|
%end
|
||||||
|
|
||||||
|
|
||||||
|
%post --erroronfail --log=/root/anaconda-post.log
|
||||||
|
# generate build time file for compatibility with CentOS
|
||||||
|
/bin/date +%Y%m%d_%H%M > /etc/BUILDTIME
|
||||||
|
|
||||||
|
# set DNF infra variable to container for compatibility with CentOS
|
||||||
|
echo 'container' > /etc/dnf/vars/infra
|
||||||
|
|
||||||
|
# import AlmaLinux PGP key
|
||||||
|
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-AlmaLinux
|
||||||
|
|
||||||
|
# install only en_US.UTF-8 locale files, see
|
||||||
|
# https://fedoraproject.org/wiki/Changes/Glibc_locale_subpackaging for details
|
||||||
|
echo '%_install_langs en_US.UTF-8' > /etc/rpm/macros.image-language-conf
|
||||||
|
|
||||||
|
# force each container to have a unique machine-id
|
||||||
|
> /etc/machine-id
|
||||||
|
|
||||||
|
# create tmp directories because there is no tmpfs support in Docker
|
||||||
|
umount /run
|
||||||
|
systemd-tmpfiles --create --boot
|
||||||
|
|
||||||
|
# disable login prompt and mounts
|
||||||
|
systemctl mask console-getty.service \
|
||||||
|
dev-hugepages.mount \
|
||||||
|
getty.target \
|
||||||
|
systemd-logind.service \
|
||||||
|
sys-fs-fuse-connections.mount \
|
||||||
|
systemd-remount-fs.service
|
||||||
|
|
||||||
|
# remove unnecessary files
|
||||||
|
rm -f /var/lib/dnf/history.* \
|
||||||
|
/run/nologin
|
||||||
|
rm -fr /var/log/* \
|
||||||
|
/tmp/* /tmp/.* \
|
||||||
|
/boot || true
|
||||||
|
%end
|
Loading…
Reference in New Issue
Block a user