install-build-deps.sh has --dont-install and --platform options.

All docker files do not call isntall-build-deps.sh. Instead, cmake passes
REQUIREDPKGS to Dockerfiles, which is derived from the output of
./scripts/install-build-deps.sh --dont-install --platform PLATFORM.
This change enables caching package installaion during docker build.
This commit is contained in:
Ryo Nakamura
2024-02-11 14:04:43 +09:00
parent d819f715c8
commit 45ba6b077e
12 changed files with 122 additions and 87 deletions

View File

@@ -155,34 +155,39 @@ enable_testing()
# Custom targets to build and test mscp in docker containers.
# foreach(IN ZIP_LISTS) (cmake >= 3.17) can shorten the following lists.
# However, ubuntu 20.04 has cmake 3.16.3. So this is a roundabout trick.
list(APPEND DIST_NAMES ubuntu ubuntu rocky rocky almalinux alpine)
list(APPEND DIST_IDS ubuntu ubuntu rocky rocky almalinux alpine)
list(APPEND DIST_VERS 20.04 22.04 8.9 9.3 9.3 3.19)
list(APPEND DIST_PKGS deb deb rpm rpm rpm static)
list(LENGTH DIST_NAMES _DIST_LISTLEN)
list(LENGTH DIST_IDS _DIST_LISTLEN)
math(EXPR DIST_LISTLEN "${_DIST_LISTLEN} - 1")
foreach(x RANGE ${DIST_LISTLEN})
list(GET DIST_NAMES ${x} DIST_NAME)
list(GET DIST_IDS ${x} DIST_ID)
list(GET DIST_VERS ${x} DIST_VER)
list(GET DIST_PKGS ${x} DIST_PKG)
set(DOCKER_IMAGE mscp-${DIST_NAME}:${DIST_VER})
set(DOCKER_INDEX ${DIST_NAME}-${DIST_VER})
set(PKG_FILE_NAME
mscp_${DIST_NAME}-${DIST_VER}-${ARCH}.${DIST_PKG})
set(DOCKER_IMAGE mscp-${DIST_ID}:${DIST_VER})
set(DOCKER_INDEX ${DIST_ID}-${DIST_VER})
execute_process(
COMMAND ${CMAKE_SOURCE_DIR}/scripts/install-build-deps.sh
--dont-install --platform Linux-${DIST_ID}
OUTPUT_VARIABLE REQUIREDPKGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_target(docker-build-${DOCKER_INDEX}
COMMENT "Build mscp in ${DOCKER_IMAGE} container"
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
COMMAND
docker build -t ${DOCKER_IMAGE} -f Dockerfile/${DOCKER_INDEX}.Dockerfile .)
docker build --build-arg REQUIREDPKGS=${REQUIREDPKGS}
-t ${DOCKER_IMAGE} -f Dockerfile/${DOCKER_INDEX}.Dockerfile .)
add_custom_target(docker-build-${DOCKER_INDEX}-no-cache
COMMENT "Build mscp in ${DOCKER_IMAGE} container"
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
COMMAND
docker build --no-cache -t ${DOCKER_IMAGE} -f Dockerfile/${DOCKER_INDEX}.Dockerfile .)
docker build --build-arg REQUIREDPKGS=${REQUIREDPKGS} --no-cache
-t ${DOCKER_IMAGE} -f Dockerfile/${DOCKER_INDEX}.Dockerfile .)
add_custom_target(docker-test-${DOCKER_INDEX}
COMMENT "Test mscp in ${DOCKER_IMAGE} container"
@@ -204,12 +209,19 @@ add_custom_target(docker-test-all DEPENDS ${DOCKER_TESTS})
### debuild-related definitions
set(DEBBUILDCONTAINER mscp-build-deb)
execute_process(
COMMAND ${CMAKE_SOURCE_DIR}/scripts/install-build-deps.sh
--dont-install --platform Linux-ubuntu
OUTPUT_VARIABLE REQUIREDPKGS_DEB
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_target(build-deb
COMMENT "build mscp deb files inside a container"
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
BYPRODUCTS ${CMAKE_BINARY_DIR}/debbuild
COMMAND
docker build -t ${DEBBUILDCONTAINER} -f Dockerfile/build-deb.Dockerfile .
docker build --build-arg REQUIREDPKGS=${REQUIREDPKGS_DEB}
-t ${DEBBUILDCONTAINER} -f Dockerfile/build-deb.Dockerfile .
COMMAND
docker run --rm -v ${CMAKE_BINARY_DIR}:/out ${DEBBUILDCONTAINER}
cp -r /debbuild /out/)
@@ -222,20 +234,28 @@ configure_file(
${mscp_SOURCE_DIR}/rpm/mscp.spec.in
${mscp_SOURCE_DIR}/rpm/mscp.spec
@ONLY)
configure_file(
${mscp_SOURCE_DIR}/Dockerfile/build-srpm.Dockerfile.in
${mscp_SOURCE_DIR}/Dockerfile/build-srpm.Dockerfile
@ONLY)
#configure_file(
# ${mscp_SOURCE_DIR}/Dockerfile/build-srpm.Dockerfile.in
# ${mscp_SOURCE_DIR}/Dockerfile/build-srpm.Dockerfile
# @ONLY)
# Custom target to build mscp as a src.rpm in docker.
set(RPMBUILDCONTAINER mscp-build-srpm)
set(SRPMFILE mscp-${MSCP_VERSION}-1.el9.src.rpm)
execute_process(
COMMAND ${CMAKE_SOURCE_DIR}/scripts/install-build-deps.sh
--dont-install --platform Linux-rocky
OUTPUT_VARIABLE REQUIREDPKGS_RPM
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_target(build-srpm
COMMENT "Build mscp src.rpm inside a container"
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
BYPRODUCTS ${CMAKE_BINARY_DIR}/${SRPMFILE}
COMMAND
docker build -t ${RPMBUILDCONTAINER} -f Dockerfile/build-srpm.Dockerfile .
docker build --build-arg REQUIREDPKGS=${REQUIREDPKGS_RPM}
--build-arg MSCP_VERSION=${MSCP_VERSION}
-t ${RPMBUILDCONTAINER} -f Dockerfile/build-srpm.Dockerfile .
COMMAND
docker run --rm -v ${CMAKE_BINARY_DIR}:/out ${RPMBUILDCONTAINER}
cp /root/rpmbuild/SRPMS/${SRPMFILE} /out/)

View File

@@ -1,3 +0,0 @@
# generated by cmake
build-srpm.Dockerfile

View File

@@ -1,19 +1,7 @@
Dockerfiles for building and testing mscp.
Build container:
```
docker build -t mscp-DIST:VER -f docker/DIST-VER.Dockerfile .
```
Run test:
```
docker run --init --rm mscp-DST:VER /mscp/scripts/test-in-container.sh
```
Custom targets to build and test mscp in the containers are provided
via `cmake`. See `make docker-*` targets. `make docker-build-all`
builds all container images, and `make docker-test-all` runs the test
in all container images.
cmake provides custom targets to build and test mscp in the containers
See `make docker-*` targets. `make docker-build-all` builds all
container images, and `make docker-test-all` runs the test in all
container images.

View File

@@ -1,8 +1,11 @@
FROM almalinux:9.3
ARG REQUIREDPKGS
# install pytest, sshd for test, and rpm-build
RUN set -ex && yum -y install \
python3 python3-pip python3-devel openssh openssh-server openssh-clients rpm-build
${REQUIREDPKGS} python3 python3-pip python3-devel \
openssh openssh-server openssh-clients rpm-build
RUN python3 -m pip install pytest
@@ -28,9 +31,6 @@ ARG mscpdir="/mscp"
COPY . ${mscpdir}
# install build dependency
RUN ${mscpdir}/scripts/install-build-deps.sh
# build
RUN cd ${mscpdir} \
&& rm -rf build \

View File

@@ -1,10 +1,15 @@
FROM alpine:3.19
# do not use REQUIREDPKGS build argument because
# this Dockerfile compiles mscp with conan,so we do not need
# libssl-dev and zlib-dev
# Build mscp with conan to create single binary mscp
RUN apk add --no-cache \
gcc make cmake python3 py3-pip perl linux-headers libc-dev \
openssh bash python3-dev py3-pytest g++
gcc make cmake libc-dev \
linux-headers openssh bash perl \
python3 py3-pip python3-dev py3-pytest g++
RUN pip3 install --break-system-packages conan

View File

@@ -1,16 +1,16 @@
FROM ubuntu:22.04
ARG REQUIREDPKGS
ARG DEBIAN_FRONTEND=noninteractive
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
ca-certificates build-essential devscripts debhelper gcc make cmake
${REQUIREDPKGS} ca-certificates \
build-essential devscripts debhelper gcc make cmake
ARG mscpdir="/debbuild/mscp"
COPY . ${mscpdir}
# install build dependency
RUN ${mscpdir}/scripts/install-build-deps.sh
# build
RUN cd ${mscpdir} \
&& debuild -us -uc -S \

View File

@@ -1,16 +1,16 @@
FROM rockylinux:9
# install pytest, sshd for test, and rpm-build
RUN set -ex && yum -y install rpm-build rpmdevtools
ARG REQUIREDPKGS
ARG MSCP_VERSION
ARG mscpdir="/mscp-@MSCP_VERSION@"
ARG mscptgz="mscp-@MSCP_VERSION@.tar.gz"
# install pytest, sshd for test, and rpm-build
RUN set -ex && yum -y install ${REQUIREDPKGS} rpm-build rpmdevtools
ARG mscpdir="/mscp-${MSCP_VERSION}"
ARG mscptgz="mscp-${MSCP_VERSION}.tar.gz"
COPY . ${mscpdir}
# install build dependency
RUN ${mscpdir}/scripts/install-build-deps.sh
# prepare rpmbuild
RUN rpmdev-setuptree \
&& rm -rf ${mscpdir}/build \

View File

@@ -1,8 +1,12 @@
FROM rockylinux:8.9
ARG REQUIREDPKGS
# install pytest, sshd for test, and rpm-build
RUN set -ex && yum -y install \
python3 python3-pip python3-devel openssh openssh-server openssh-clients rpm-build
${REQUIREDPKGS} \
python3 python3-pip python3-devel \
openssh openssh-server openssh-clients rpm-build
RUN python3 -m pip install pytest
@@ -29,9 +33,6 @@ ARG mscpdir="/mscp"
COPY . ${mscpdir}
# install build dependency
RUN ${mscpdir}/scripts/install-build-deps.sh
# build
RUN cd ${mscpdir} \
&& rm -rf build \

View File

@@ -1,8 +1,12 @@
FROM rockylinux:9.3
ARG REQUIREDPKGS
# install pytest, sshd for test, and rpm-build
RUN set -ex && yum -y install \
python3 python3-pip python3-devel openssh openssh-server openssh-clients rpm-build
${REQUIREDPKGS} \
python3 python3-pip python3-devel \
openssh openssh-server openssh-clients rpm-build
RUN python3 -m pip install pytest
@@ -28,9 +32,6 @@ ARG mscpdir="/mscp"
COPY . ${mscpdir}
# install build dependency
RUN ${mscpdir}/scripts/install-build-deps.sh
# build
RUN cd ${mscpdir} \
&& rm -rf build \

View File

@@ -1,16 +1,13 @@
FROM ubuntu:20.04
ARG REQUIREDPKGS
ARG DEBIAN_FRONTEND=noninteractive
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
ca-certificates
# install pytest, and sshd for test
RUN apt-get install -y --no-install-recommends \
python3 python3-pip python3-dev openssh-server
${REQUIREDPKGS} ca-certificates python3 python3-pip python3-dev openssh-server
RUN python3 -m pip install pytest
# preparation for sshd
RUN mkdir /var/run/sshd \
&& ssh-keygen -A \
@@ -31,10 +28,6 @@ ARG mscpdir="/mscp"
COPY . ${mscpdir}
# install build dependency
RUN ${mscpdir}/scripts/install-build-deps.sh
# build
RUN cd ${mscpdir} \
&& rm -rf build \

View File

@@ -1,16 +1,13 @@
FROM ubuntu:22.04
ARG REQUIREDPKGS
ARG DEBIAN_FRONTEND=noninteractive
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
ca-certificates
# install pytest, and sshd for test
RUN apt-get install -y --no-install-recommends \
python3 python3-pip python3-dev openssh-server
${REQUIREDPKGS} ca-certificates python3 python3-pip python3-dev openssh-server
RUN python3 -m pip install pytest
# preparation for sshd
RUN mkdir /var/run/sshd \
&& ssh-keygen -A \
@@ -31,10 +28,6 @@ ARG mscpdir="/mscp"
COPY . ${mscpdir}
# install build dependency
RUN ${mscpdir}/scripts/install-build-deps.sh
# build
RUN cd ${mscpdir} \
&& rm -rf build \

View File

@@ -3,34 +3,71 @@
# Install build dpenedencies.
set -e
set -u
#set -u
function print_help() {
echo "$0 [options]"
echo " --dont-install Print required packages."
echo " --platform [PLATFORM] PLATFORM is Kernel-ID, e.g., Linux-ubuntu."
echo " Automatically detected if not specified."
}
platform=$(uname -s)
doinstall=1
if [ -e /etc/os-release ]; then
source /etc/os-release
platform=${platform}-${ID}
fi
set -x
while getopts h-: opt; do
optarg="${!OPTIND}"
[[ "$opt" = - ]] && opt="-$OPTARG"
case "-${opt}" in
--dont-install)
doinstall=0
;;
--platform)
platform=$optarg
shift
;;
-h)
print_help
exit 0
;;
*)
print_help
exit 1
;;
esac
done
case $platform in
Darwin)
brew install openssl@1.1
cmd="brew install"
pkgs="openssl@1.1"
;;
Linux-ubuntu*)
apt-get install --no-install-recommends -y \
gcc make cmake zlib1g-dev libssl-dev libkrb5-dev
cmd="apt-get install --no-install-recommends -y"
pkgs="gcc make cmake zlib1g-dev libssl-dev libkrb5-dev"
;;
Linux-centos* | Linux-rhel* | Linux-rocky* | Linux-almalinux)
yum install -y \
gcc make cmake zlib-devel openssl-devel rpm-build
cmd="yum install -y"
pkgs="gcc make cmake zlib-devel openssl-devel rpm-build"
;;
FreeBSD-freebsd)
pkg install cmake
cmd="pkg install"
pkgs="cmake"
;;
*)
echo "unsupported platform: $platform"
exit 1
;;
esac
if [ $doinstall -gt 0 ]; then
echo do "$cmd $pkgs"
$cmd $pkgs
else
echo $pkgs
fi