Building an AutoSD-based base container image
Building an AutoSD-based base container image¶
Build a customized AutoSD-based container image from a Red Hat Enterprise Linux (RHEL) Universal Base Image (UBI). This base container image standardizes your development workflow and reduces deployment complexity for automotive-grade applications.
Prerequisites
- You have Podman installed
- You have have access to your application files on your system
Procedure
-
Create a
Containerfilewith AutoSD specific repository set up:```console title="Containerfile"
Global arguments¶
ARG ROOTFS=/mnt/rootfs
First stage RHEL UBI container¶
FROM registry.access.redhat.com/ubi10:latest as builder
List of packages to install in the AutoSD container¶
ARG PACKAGES=" \ bash \ coreutils-single \ " ARG DISTRO="AutoSD" ARG BASE_URL="https://autosd.sig.centos.org/AutoSD-10/nightly" RG RELEASE_PKG="centos-release-autosd" ARG GPG_KEY="RPM-GPG-KEY-centosofficial" ARG ROOTFS
Disable the RHEL subscription manager¶
RUN dnf --noplugins remove -y -q subscription-manager dnf-plugin-subscription-manager RUN mkdir -p ${ROOTFS}
Set up the AutoSD repository¶
RUN cat <
/etc/yum.repos.d/${DISTRO}.repo [${DISTRO}] name=${DISTRO} baseurl=${BASE_URL}/repos/${DISTRO}/compose/${DISTRO}/\$basearch/os/ gpgcheck=0 enabled=1 skip_if_unavailable=1 EOF Pull packages and import the GPG key¶
RUN dnf install \ --installroot ${ROOTFS} \ --setopt=reposdir=/etc/yum.repos.d --repo ${DISTRO} --releasever 10 \ --setopt install_weak_deps=false --nodocs --nogpgcheck -y \ ${RELEASE_PKG} ${PACKAGES} \ && dnf --installroot ${ROOTFS} clean all \ && rpm --root=${ROOTFS} --import ${ROOTFS}/etc/pki/rpm-gpg/${GPG_KEY}
Final cleanup and pruning¶
RUN rm -f ${ROOTFS}/usr/share/gnupg/help.txt && \ if rpm --dbpath=${ROOTFS}/var/lib/rpm/ -q systemd ; then exit 1 ; fi && \ rm -rfv ${ROOTFS}/var/cache/ ${ROOTFS}/var/log/dnf ${ROOTFS}/var/log/yum. ${ROOTFS}/var/lib/rhsm && \ rm -fv ${ROOTFS}/etc/sysconfig/network-scripts/ifcfg-* && \ echo -n > ${ROOTFS}/etc/machine-id && \ install -d ${ROOTFS}/run/lock -m 0755 -o root -g root
Second stage: Create the actual AutoSD container¶
FROM scratch ENV container oci ARG ROOTFS COPY --from=builder ${ROOTFS} / COPY --from=builder /etc/yum.repos.d/${DISTRO}.repo /etc/yum.repos.d/ RUN rm -fv /etc/yum.repos.d/centos.repo && rm -rfv /var/log/ CMD ["/bin/bash"] ```
-
Build the image in the
Containerfiledirectory:console $ podman build -t localhost/autosd10 . -
Verify the image build from your
Containerfile:console $ podman images $ podman run -ti --rm localhost/autosd10
To install additional packages such as dnf and wget, use buildah in your AutoSD-based base image.
-
Create a
buildahimage.shscript to add packages:console title="buildahimage.sh" ctr=$(buildah from localhost/autosd10) mnt=$(buildah mount $ctr) dnf install --installroot $mnt --releasever 10 --setopt install_weak_deps=false --nodocs -y dnf rpm wget dnf clean all --installroot $mnt buildah umount $ctr buildah commit $ctr custom_autosd10 -
Run the
buildahimage.shin the script directory:console $ buildah unshare < ./buildahimage.sh
Additional resources