Use 3 files
build.sh
#!/bin/bash
set -e
if [[ $UID == 0 ]]; then
echo "You must not run this as root." 1>&2
exit 1
fi
if !(type docker >/dev/null); then
echo "Docker is not installing on this machine." 1>&2
exit 1
fi
#Click here for the processing to be performed before building the docker container
WORKDIR=$(cd $(dirname $0); pwd)
NAME=base-files-11ubuntu4
#Described so far
#Image name build_deb is rewritten by the deb file to build
#Example: build_base-files
sudo docker build -t build_deb ${WORKDIR}
sudo docker run -e NAME=${NAME} -e UGID="${UID}:$(id -u)" -v ${WORKDIR}/out:/deb -it build_deb
Dockerfile
FROM ubuntu:20.04
ARG NAME="base-files-11ubuntu4"
#Describe the directory name to be built
ARG UID=65587
#With a large value so as not to conflict
RUN sed -i"" -e 's%http://[^ ]\+%mirror://mirrors.ubuntu.com/mirrors.txt%g' /etc/apt/sources.list \
&& apt-get update \
&& apt-get -y upgrade \
&& apt-get install -y --no-install-recommends build-essential devscripts zstd gawk libc6 libcrypt1 debhelper dh-systemd apt-utils sudo \
&& rm -rf /tmp/* /var/tmp/* \
&& apt-get clean
#Install dependencies
RUN echo "root:root" | chpasswd && \
adduser --disabled-password --uid ${UID} --gecos "" docker && \
echo "docker:docker" | chpasswd && \
echo "%docker ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/docker && \
chmod 0440 /etc/sudoers.d/docker
#Creating a user that sudo can use without entering a password
RUN mkdir -p /debuild/build /deb
ADD ./${NAME} /debuild/build/${NAME}
ADD ./debuild.sh /debuild/debuild.sh
RUN chmod +x /debuild/debuild.sh \
&& chown -R docker:docker /debuild
USER ${UID}
WORKDIR /debuild
CMD ["./debuild.sh"]
debuild.sh
#!/bin/bash -e
if [ $UID != 65587 ]; then
echo "You have to run this on Docker" 1>&2
exit 1
fi
#Suppress running outside of Docker container
export EDITOR=vim
cd /debuild/build/$NAME
#Describe the process before build
debuild -us -uc
#Build
cd ..
tar cf ${BASE_FILES}serene${VERSION:5}.tar \
base-files-dbgsym_${BASE_FILES:11}serene${VERSION:5}_amd64.ddeb \
base-files_${BASE_FILES:11}serene${VERSION:5}.dsc \
base-files_${BASE_FILES:11}serene${VERSION:5}_amd64.build \
base-files_${BASE_FILES:11}serene${VERSION:5}_amd64.buildinfo \
base-files_${BASE_FILES:11}serene${VERSION:5}_amd64.changes \
base-files_${BASE_FILES:11}serene${VERSION:5}_amd64.deb \
lsb-release-udeb_${BASE_FILES:11}serene${VERSION:5}_all.udeb
zstd ${BASE_FILES}serene${VERSION:5}.tar
sudo mv -f *.xz /deb 2>/dev/null
sudo mv -f *.zst /deb 2>/dev/null
sudo chown -R ${H_UGID} /deb 2>/dev/null
#Tar the build.Compress to zst, to shared directory with host with source package
Recommended Posts