diff options
author | Ryo Nakamura <upa@haeena.net> | 2024-02-11 14:04:43 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2024-02-11 14:04:43 +0900 |
commit | 45ba6b077ede13170855a9a985d06c067fd52a24 (patch) | |
tree | 9e43010eb8be502c7af6eb8055c3e704f36ece12 | |
parent | d819f715c8ab5abd3c02459eb9967cfc00136e34 (diff) |
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.
-rw-r--r-- | CMakeLists.txt | 50 | ||||
-rw-r--r-- | Dockerfile/.gitignore | 3 | ||||
-rw-r--r-- | Dockerfile/README.md | 20 | ||||
-rw-r--r-- | Dockerfile/almalinux-9.3.Dockerfile | 8 | ||||
-rw-r--r-- | Dockerfile/alpine-3.19.Dockerfile | 9 | ||||
-rw-r--r-- | Dockerfile/build-deb.Dockerfile | 8 | ||||
-rw-r--r-- | Dockerfile/build-srpm.Dockerfile (renamed from Dockerfile/build-srpm.Dockerfile.in) | 12 | ||||
-rw-r--r-- | Dockerfile/rocky-8.9.Dockerfile | 9 | ||||
-rw-r--r-- | Dockerfile/rocky-9.3.Dockerfile | 9 | ||||
-rw-r--r-- | Dockerfile/ubuntu-20.04.Dockerfile | 13 | ||||
-rw-r--r-- | Dockerfile/ubuntu-22.04.Dockerfile | 13 | ||||
-rwxr-xr-x | scripts/install-build-deps.sh | 53 |
12 files changed, 121 insertions, 86 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 600cfd6..610c2cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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/) diff --git a/Dockerfile/.gitignore b/Dockerfile/.gitignore deleted file mode 100644 index adab824..0000000 --- a/Dockerfile/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ - -# generated by cmake -build-srpm.Dockerfile diff --git a/Dockerfile/README.md b/Dockerfile/README.md index ff6d45b..6d2245c 100644 --- a/Dockerfile/README.md +++ b/Dockerfile/README.md @@ -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.
\ No newline at end of file +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.
\ No newline at end of file diff --git a/Dockerfile/almalinux-9.3.Dockerfile b/Dockerfile/almalinux-9.3.Dockerfile index 3286f72..640cb6b 100644 --- a/Dockerfile/almalinux-9.3.Dockerfile +++ b/Dockerfile/almalinux-9.3.Dockerfile @@ -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 \ diff --git a/Dockerfile/alpine-3.19.Dockerfile b/Dockerfile/alpine-3.19.Dockerfile index a338161..054d93f 100644 --- a/Dockerfile/alpine-3.19.Dockerfile +++ b/Dockerfile/alpine-3.19.Dockerfile @@ -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 diff --git a/Dockerfile/build-deb.Dockerfile b/Dockerfile/build-deb.Dockerfile index 7d489d9..2b8d71e 100644 --- a/Dockerfile/build-deb.Dockerfile +++ b/Dockerfile/build-deb.Dockerfile @@ -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 \ diff --git a/Dockerfile/build-srpm.Dockerfile.in b/Dockerfile/build-srpm.Dockerfile index f7a8cf0..b4ae974 100644 --- a/Dockerfile/build-srpm.Dockerfile.in +++ b/Dockerfile/build-srpm.Dockerfile @@ -1,16 +1,16 @@ FROM rockylinux:9 +ARG REQUIREDPKGS +ARG MSCP_VERSION + # install pytest, sshd for test, and rpm-build -RUN set -ex && yum -y install rpm-build rpmdevtools +RUN set -ex && yum -y install ${REQUIREDPKGS} rpm-build rpmdevtools -ARG mscpdir="/mscp-@MSCP_VERSION@" -ARG mscptgz="mscp-@MSCP_VERSION@.tar.gz" +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 \ diff --git a/Dockerfile/rocky-8.9.Dockerfile b/Dockerfile/rocky-8.9.Dockerfile index df23d83..5a19699 100644 --- a/Dockerfile/rocky-8.9.Dockerfile +++ b/Dockerfile/rocky-8.9.Dockerfile @@ -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 \ diff --git a/Dockerfile/rocky-9.3.Dockerfile b/Dockerfile/rocky-9.3.Dockerfile index 225aafa..9c15d00 100644 --- a/Dockerfile/rocky-9.3.Dockerfile +++ b/Dockerfile/rocky-9.3.Dockerfile @@ -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 \ diff --git a/Dockerfile/ubuntu-20.04.Dockerfile b/Dockerfile/ubuntu-20.04.Dockerfile index 5a75295..669e9ab 100644 --- a/Dockerfile/ubuntu-20.04.Dockerfile +++ b/Dockerfile/ubuntu-20.04.Dockerfile @@ -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 \ diff --git a/Dockerfile/ubuntu-22.04.Dockerfile b/Dockerfile/ubuntu-22.04.Dockerfile index dff3f7f..3494d8b 100644 --- a/Dockerfile/ubuntu-22.04.Dockerfile +++ b/Dockerfile/ubuntu-22.04.Dockerfile @@ -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 \ diff --git a/scripts/install-build-deps.sh b/scripts/install-build-deps.sh index 5c46a61..3ec3d49 100755 --- a/scripts/install-build-deps.sh +++ b/scripts/install-build-deps.sh @@ -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 |