mirror of
https://github.com/AlmaLinux/ks2rootfs.git
synced 2024-11-25 10:33:08 +00:00
Code reorg and add base type
Signed-off-by: Bala Raman <srbala@gmail.com>
This commit is contained in:
parent
b5c5338667
commit
02d25626b1
24
README.md
24
README.md
@ -20,9 +20,9 @@ Use command below to create `default` docker files
|
|||||||
|
|
||||||
```sh
|
```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 KICKSTART_FILE=kickstarts/almalinux-8-default.x86_64.ks \
|
||||||
-e BUILD_ROOTFS=almalinux-8-docker-default.x86_64.tar.gz \
|
-e IMAGE_NAME=almalinux-8-docker-default.x86_64.tar.gz \
|
||||||
-e BUILD_OUTDIR=default \
|
-e OUTPUT_DIR=default \
|
||||||
almalinux/ks2rootfs
|
almalinux/ks2rootfs
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -30,9 +30,9 @@ Use command below to create `minimal` docker files
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker run --rm --privileged -v "$PWD:/build:z" \
|
docker run --rm --privileged -v "$PWD:/build:z" \
|
||||||
-e BUILD_KICKSTART=kickstarts/almalinux-8-minimal.x86_64.ks \
|
-e KICKSTART_FILE=kickstarts/almalinux-8-minimal.x86_64.ks \
|
||||||
-e BUILD_ROOTFS=almalinux-8-docker-minimal.x86_64.tar.gz \
|
-e IMAGE_NAME=almalinux-8-docker-minimal.x86_64.tar.gz \
|
||||||
-e BUILD_OUTDIR=minimal \
|
-e OUTPUT_DIR=minimal \
|
||||||
almalinux/ks2rootfs
|
almalinux/ks2rootfs
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -44,14 +44,14 @@ Container startup script `ks2rootfs` supports multiple environment varible to cu
|
|||||||
ENVIRONMENT VARIABLES:
|
ENVIRONMENT VARIABLES:
|
||||||
======================
|
======================
|
||||||
|
|
||||||
BUILD_KICKSTART : Reuired - Input kickstart source file (.ks)
|
KICKSTART_FILE : Reuired - Input kickstart source file (.ks)
|
||||||
BUILD_ROOTFS : Required - Rootfs output file name
|
IMAGE_NAME : Required - Rootfs output file name
|
||||||
|
|
||||||
BUILD_WORK_DIR : Optional - Working dir for kickstart source and image destination. Defaults to current directory.
|
BUILD_WORK_DIR : Optional - Working dir for kickstart source and image destination. Defaults to current directory.
|
||||||
BUILD_OUTDIR : Optional - Output directory name in working directory. Ddefault value is 'result'.
|
OUTPUT_DIR : Optional - Output directory name in working directory. Ddefault value is 'result'.
|
||||||
BUILD_FLAG_OUTOUT_IN_PWD : Optional - 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.
|
FLAG_OUTOUT_IN_PWD : Optional - 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 `OUTPUT_DIR` will be ignored.
|
||||||
BUILD_FLAG_WRITE_META : Optional - Generate meta data about the kickstart build system. Default value is true.
|
FLAG_WRITE_META : Optional - Generate meta data about the kickstart build system. Default value is true.
|
||||||
BUILD_FLAG_RETAIN_LOG : Optional - Retain generated output log files under 'logs' output directory. Default value is false.
|
FLAG_RETAIN_LOG : Optional - Retain generated output log files under 'logs' output directory. Default value is false.
|
||||||
|
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
|
@ -10,14 +10,14 @@ Script to create roofs file from a kickstart file using livemedia-creator
|
|||||||
ENVIRONMENT VARIABLES:
|
ENVIRONMENT VARIABLES:
|
||||||
======================
|
======================
|
||||||
|
|
||||||
BUILD_KICKSTART : Reuired - Input kickstart source file (.ks)
|
KICKSTART_FILE : Reuired - Input kickstart source file (.ks)
|
||||||
BUILD_ROOTFS : Required - Rootfs output file name
|
IMAGE_NAME : Required - Rootfs output file name
|
||||||
|
|
||||||
BUILD_WORK_DIR : Optional - Working dir for kickstart source and image destination. Defaults to current directory.
|
BUILD_WORK_DIR : Optional - Working dir for kickstart source and image destination. Defaults to current directory.
|
||||||
BUILD_OUTDIR : Optional - Output directory name in working dir (default - 'result') - Optional
|
OUTPUT_DIR : Optional - Output directory name in working dir (default - 'result') - Optional
|
||||||
BUILD_FLAG_OUTOUT_IN_PWD : Optional - 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.
|
FLAG_OUTOUT_IN_PWD : Optional - 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 `OUTPUT_DIR` will be ignored.
|
||||||
BUILD_FLAG_WRITE_META : Optional - Generate meta data about the kickstart build system. Default value is true.
|
FLAG_WRITE_META : Optional - Generate meta data about the kickstart build system. Default value is true.
|
||||||
BUILD_FLAG_RETAIN_LOG : Optional - Retain generated output log files under 'logs' output directory. Default value is false.
|
FLAG_RETAIN_LOG : Optional - Retain generated output log files under 'logs' output directory. Default value is false.
|
||||||
BUILD_COMPTYPE : Optional - Build compression type default 'xz', gzip and lzma.
|
BUILD_COMPTYPE : Optional - Build compression type default 'xz', gzip and lzma.
|
||||||
USAGE:
|
USAGE:
|
||||||
ks2rootfs KICKSTART_FILE_NAME ROOTFS_FILE_NAME
|
ks2rootfs KICKSTART_FILE_NAME ROOTFS_FILE_NAME
|
||||||
@ -34,58 +34,73 @@ ks2rootfs - Script input summary:
|
|||||||
|
|
||||||
FLAGS
|
FLAGS
|
||||||
-----
|
-----
|
||||||
FLAG_OUTOUT_PWD : ${BUILD_FLAG_OUTOUT_IN_PWD}
|
FLAG_OUTOUT_PWD : ${FLAG_OUTOUT_IN_PWD}
|
||||||
FLAG_WRITE_META : ${BUILD_FLAG_WRITE_META}
|
FLAG_WRITE_META : ${FLAG_WRITE_META}
|
||||||
FLAG_RETAIN_LOG : ${BUILD_FLAG_RETAIN_LOG}
|
FLAG_RETAIN_LOG : ${FLAG_RETAIN_LOG}
|
||||||
|
|
||||||
VARIABLES
|
VARIABLES
|
||||||
---------
|
---------
|
||||||
BUILD_WORK_DIR : ${BUILD_WORK_DIR}
|
BUILD_WORK_DIR : ${BUILD_WORK_DIR}
|
||||||
BUILD_OUTDIR : ${BUILD_OUTDIR}
|
OUTPUT_DIR : ${OUTPUT_DIR}
|
||||||
BUILD_LOGDIR : ${BUILD_LOGDIR}
|
BUILD_LOGDIR : ${BUILD_LOGDIR}
|
||||||
INPUT_KICKSTART : ${BUILD_WORK_DIR}${BUILD_KICKSTART}
|
INPUT_KICKSTART : ${BUILD_WORK_DIR}${KICKSTART_FILE}
|
||||||
OUTPUT_ROOTFS : ${BUILD_OUTDIR}/${BUILD_ROOTFS}
|
OUTPUT_ROOTFS : ${OUTPUT_DIR}/${IMAGE_NAME}
|
||||||
BUILD_COMPTYPE : ${BUILD_COMPTYPE}
|
BUILD_COMPTYPE : ${BUILD_COMPTYPE}
|
||||||
|
BUILD_TYPE : ${BUILD_TYPE}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
BUILD_WORK_DIR=${BUILD_WORK_DIR:-./}
|
BUILD_WORK_DIR=${BUILD_WORK_DIR:-./}
|
||||||
BUILD_KICKSTART=${BUILD_KICKSTART:-$1}
|
KICKSTART_FILE=${KICKSTART_FILE:-$1}
|
||||||
BUILD_ROOTFS=${BUILD_ROOTFS:-$2}
|
IMAGE_NAME=${IMAGE_NAME:-$2}
|
||||||
BUILD_FLAG_WRITE_META=${BUILD_FLAG_WRITE_META:-true}
|
FLAG_WRITE_META=${FLAG_WRITE_META:-false}
|
||||||
BUILD_FLAG_RETAIN_LOG=${BUILD_FLAG_RETAIN_LOG:-false}
|
FLAG_RETAIN_LOG=${FLAG_RETAIN_LOG:-false}
|
||||||
BUILD_FLAG_OUTOUT_IN_PWD=${BUILD_FLAG_OUTOUT_IN_PWD:-false}
|
FLAG_OUTOUT_IN_PWD=${FLAG_OUTOUT_IN_PWD:-false}
|
||||||
BUILD_COMPTYPE=${BUILD_COMPTYPE:-xz}
|
BUILD_COMPTYPE=${BUILD_COMPTYPE:-xz}
|
||||||
|
BUILD_TYPE=${BUILD_TYPE:-default}
|
||||||
|
TYPE='default'
|
||||||
|
|
||||||
USE_PWD_OUTPUT=${USE_PWD_OUTPUT:-false}
|
USE_PWD_OUTPUT=${USE_PWD_OUTPUT:-false}
|
||||||
|
|
||||||
BUILD_OUTDIR=${BUILD_OUTDIR:-result}
|
OUTPUT_DIR=${OUTPUT_DIR:-result}
|
||||||
BUILD_LOGDIR=${BUILD_OUTDIR}/logs
|
BUILD_LOGDIR=${OUTPUT_DIR}/logs
|
||||||
|
|
||||||
if [ ${BUILD_FLAG_OUTOUT_IN_PWD} == 'true' ]; then
|
if [ ${FLAG_OUTOUT_IN_PWD} == 'true' ]; then
|
||||||
echo 'Build output files will be in current working folder ... '
|
echo 'Build output files will be in current working folder ... '
|
||||||
BUILD_OUTDIR=${BUILD_WORK_DIR}
|
OUTPUT_DIR=${BUILD_WORK_DIR}
|
||||||
else
|
else
|
||||||
BUILD_OUTDIR=${BUILD_WORK_DIR}${BUILD_OUTDIR:-result}
|
OUTPUT_DIR=${BUILD_WORK_DIR}${OUTPUT_DIR:-result}
|
||||||
echo "Build output files will be in '${BUILD_OUTDIR}' folder ... "
|
echo "Build output files will be in '${OUTPUT_DIR}' folder ... "
|
||||||
if [[ -d "${BUILD_OUTDIR}" ]]; then
|
if [[ -d "${OUTPUT_DIR}" ]]; then
|
||||||
echo "Output directory ${BUILD_OUTDIR} already exists, please remove it"
|
echo "Output directory ${OUTPUT_DIR} already exists, please remove it"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
mkdir -p ${BUILD_OUTDIR}
|
mkdir -p ${OUTPUT_DIR}
|
||||||
if [[ -d "${BUILD_OUTDIR}" ]]; then
|
if [[ -d "${OUTPUT_DIR}" ]]; then
|
||||||
echo "Output directory ${BUILD_OUTDIR} created successfully"
|
echo "Output directory ${OUTPUT_DIR} created successfully"
|
||||||
else
|
else
|
||||||
echo "Error in creating output directory: ${BUILD_OUTDIR}"
|
echo "Error in creating output directory: ${OUTPUT_DIR}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
case "${BUILD_TYPE}" in
|
||||||
|
base|default|init|micro|minimal|wsl)
|
||||||
|
TYPE="${BUILD_TYPE}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Error: unsupported build type ${BUILD_TYPE}" 1>&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
BUILD_LOGDIR=${BUILD_OUTDIR}/logs
|
if [ ${TYPE} == 'wsl' ]; then
|
||||||
|
BUILD_COMPTYPE = 'gzip'
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z ${BUILD_KICKSTART} ] || [ -z ${BUILD_ROOTFS} ]
|
BUILD_LOGDIR=${OUTPUT_DIR}/logs
|
||||||
|
|
||||||
|
if [ -z ${KICKSTART_FILE} ] || [ -z ${IMAGE_NAME} ]
|
||||||
then
|
then
|
||||||
echo "Please provide two parameters, kickstart source file and rootfs output file name"
|
echo "Please provide two parameters, kickstart source file and rootfs output file name"
|
||||||
usage
|
usage
|
||||||
@ -114,18 +129,23 @@ _EOF
|
|||||||
|
|
||||||
# create rootfs
|
# create rootfs
|
||||||
livemedia-creator --logfile="/tmp/ks2rootfs.log" \
|
livemedia-creator --logfile="/tmp/ks2rootfs.log" \
|
||||||
--make-tar --ks="${BUILD_WORK_DIR}/${BUILD_KICKSTART}" --no-virt \
|
--make-tar --ks="${BUILD_WORK_DIR}/${KICKSTART_FILE}" --no-virt \
|
||||||
--image-only --image-name="${BUILD_ROOTFS}" \
|
--image-only --image-name="${IMAGE_NAME}" \
|
||||||
--anaconda-arg "--product Kickstart to RootFS" \
|
--anaconda-arg "--product Kickstart to RootFS" \
|
||||||
--compression ${BUILD_COMPTYPE}
|
--compression ${BUILD_COMPTYPE}
|
||||||
|
|
||||||
# copy rootfs to working dir
|
# copy rootfs to working dir
|
||||||
cp -rp /var/tmp/${BUILD_ROOTFS} ${BUILD_OUTDIR}/${BUILD_ROOTFS}
|
cp -rp /var/tmp/${IMAGE_NAME} ${OUTPUT_DIR}/${IMAGE_NAME}
|
||||||
echo "Copied disk image from /var/tmp/${BUILD_ROOTFS} to ${BUILD_OUTDIR}/${BUILD_ROOTFS}"
|
echo "Copied disk image from /var/tmp/${IMAGE_NAME} to ${OUTPUT_DIR}/${IMAGE_NAME}"
|
||||||
|
# save list of packages installed
|
||||||
|
jq .[] -r /tmp/dnf.cache/tempfiles.json | awk -F '/' '{print $5}' | sort > ${OUTPUT_DIR}/rpm-packags
|
||||||
|
# cat ${OUTPUT_DIR}/rpm-packags | sed 's/-[0-9].*//g' > ${OUTPUT_DIR}/pkgs-list-only
|
||||||
|
# cat ${OUTPUT_DIR}/rpm-packags | sed 's/.el[0-9].*//g' > ${OUTPUT_DIR}/pkgs-list
|
||||||
|
echo "Generated '${OUTPUT_DIR}/rpm-packags' file."
|
||||||
|
|
||||||
if [ ${BUILD_FLAG_WRITE_META} == 'true' ]; then
|
if [ ${FLAG_WRITE_META} == 'true' ]; then
|
||||||
# extract os-release info
|
# extract os-release info
|
||||||
tar -xvf /var/tmp/${BUILD_ROOTFS} -C /tmp/ --strip-components=3 ./usr/lib/os-release
|
tar -xvf /var/tmp/${IMAGE_NAME} -C /tmp/ --strip-components=3 ./usr/lib/os-release
|
||||||
os_release_id=$(awk -F= '$1=="ID" { print $2 ;}' /tmp/os-release | tr -d '"')
|
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')
|
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
|
||||||
@ -133,18 +153,14 @@ if [ ${BUILD_FLAG_WRITE_META} == 'true' ]; then
|
|||||||
else
|
else
|
||||||
echo 'Writting meta data ... '
|
echo 'Writting meta data ... '
|
||||||
# save distro release info
|
# save distro release info
|
||||||
echo "$distro_release" > ${BUILD_OUTDIR}/distro-release
|
echo "$distro_release" > ${OUTPUT_DIR}/distro-release
|
||||||
fi
|
fi
|
||||||
# save list of packages installed
|
|
||||||
jq .[] -r /tmp/dnf.cache/tempfiles.json | awk -F '/' '{print $5}' | sort > ${BUILD_OUTDIR}/rpm-packags
|
|
||||||
# cat ${BUILD_OUTDIR}/rpm-packags | sed 's/-[0-9].*//g' > ${BUILD_OUTDIR}/pkgs-list-only
|
|
||||||
# cat ${BUILD_OUTDIR}/rpm-packags | sed 's/.el[0-9].*//g' > ${BUILD_OUTDIR}/pkgs-list
|
|
||||||
echo 'Writting meta data completed.'
|
echo 'Writting meta data completed.'
|
||||||
else
|
else
|
||||||
echo 'Skip writing meta data based on configuration.'
|
echo 'Skip writing meta data.'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${BUILD_FLAG_RETAIN_LOG} == 'true' ]; then
|
if [ ${FLAG_RETAIN_LOG} == 'true' ]; then
|
||||||
rm -rf ${BUILD_LOGDIR}
|
rm -rf ${BUILD_LOGDIR}
|
||||||
mkdir -p ${BUILD_LOGDIR} ${BUILD_LOGDIR}/anaconda
|
mkdir -p ${BUILD_LOGDIR} ${BUILD_LOGDIR}/anaconda
|
||||||
echo "Copying logs to '${BUILD_LOGDIR}' ..."
|
echo "Copying logs to '${BUILD_LOGDIR}' ..."
|
||||||
@ -155,11 +171,32 @@ else
|
|||||||
echo 'Skip copying logs data based on configuration (default). '
|
echo 'Skip copying logs data based on configuration (default). '
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat << _EOF > "${BUILD_OUTDIR}/Dockerfile"
|
STARTCMD=$( cat <<EOF
|
||||||
# This file auto generated from 'ks2rootfs' script, any changes will be over-written
|
|
||||||
FROM scratch
|
|
||||||
ADD ${BUILD_ROOTFS} /
|
|
||||||
|
|
||||||
CMD ["/bin/bash"]
|
CMD ["/bin/bash"]
|
||||||
_EOF
|
EOF
|
||||||
echo "Generating '${BUILD_OUTDIR}/Dockerfile' completed."
|
)
|
||||||
|
|
||||||
|
if [ ${TYPE} == 'init' ]; then
|
||||||
|
STARTCMD=$( cat <<EOF
|
||||||
|
|
||||||
|
STOPSIGNAL SIGRTMIN+3
|
||||||
|
CMD ["/bin/init"]
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${TYPE} == 'micro' ]; then
|
||||||
|
STARTCMD=$( cat <<EOF
|
||||||
|
|
||||||
|
CMD ["/bin/sh"]
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat << EOF > "${OUTPUT_DIR}/Dockerfile"
|
||||||
|
FROM scratch
|
||||||
|
ADD ${IMAGE_NAME} /
|
||||||
|
${STARTCMD}
|
||||||
|
EOF
|
||||||
|
echo "Generating '${OUTPUT_DIR}/Dockerfile' completed."
|
||||||
|
Loading…
Reference in New Issue
Block a user