Skip to content

Commit 45ba6b0

Browse files
committed
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.
1 parent d819f71 commit 45ba6b0

12 files changed

+121
-86
lines changed

CMakeLists.txt

+35-15
Original file line numberDiff line numberDiff line change
@@ -155,34 +155,39 @@ enable_testing()
155155
# Custom targets to build and test mscp in docker containers.
156156
# foreach(IN ZIP_LISTS) (cmake >= 3.17) can shorten the following lists.
157157
# However, ubuntu 20.04 has cmake 3.16.3. So this is a roundabout trick.
158-
list(APPEND DIST_NAMES ubuntu ubuntu rocky rocky almalinux alpine)
158+
list(APPEND DIST_IDS ubuntu ubuntu rocky rocky almalinux alpine)
159159
list(APPEND DIST_VERS 20.04 22.04 8.9 9.3 9.3 3.19)
160160
list(APPEND DIST_PKGS deb deb rpm rpm rpm static)
161161

162-
list(LENGTH DIST_NAMES _DIST_LISTLEN)
162+
list(LENGTH DIST_IDS _DIST_LISTLEN)
163163
math(EXPR DIST_LISTLEN "${_DIST_LISTLEN} - 1")
164164

165165
foreach(x RANGE ${DIST_LISTLEN})
166-
list(GET DIST_NAMES ${x} DIST_NAME)
166+
list(GET DIST_IDS ${x} DIST_ID)
167167
list(GET DIST_VERS ${x} DIST_VER)
168168
list(GET DIST_PKGS ${x} DIST_PKG)
169169

170-
set(DOCKER_IMAGE mscp-${DIST_NAME}:${DIST_VER})
171-
set(DOCKER_INDEX ${DIST_NAME}-${DIST_VER})
172-
set(PKG_FILE_NAME
173-
mscp_${DIST_NAME}-${DIST_VER}-${ARCH}.${DIST_PKG})
170+
set(DOCKER_IMAGE mscp-${DIST_ID}:${DIST_VER})
171+
set(DOCKER_INDEX ${DIST_ID}-${DIST_VER})
172+
execute_process(
173+
COMMAND ${CMAKE_SOURCE_DIR}/scripts/install-build-deps.sh
174+
--dont-install --platform Linux-${DIST_ID}
175+
OUTPUT_VARIABLE REQUIREDPKGS
176+
OUTPUT_STRIP_TRAILING_WHITESPACE)
174177

175178
add_custom_target(docker-build-${DOCKER_INDEX}
176179
COMMENT "Build mscp in ${DOCKER_IMAGE} container"
177180
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
178181
COMMAND
179-
docker build -t ${DOCKER_IMAGE} -f Dockerfile/${DOCKER_INDEX}.Dockerfile .)
182+
docker build --build-arg REQUIREDPKGS=${REQUIREDPKGS}
183+
-t ${DOCKER_IMAGE} -f Dockerfile/${DOCKER_INDEX}.Dockerfile .)
180184

181185
add_custom_target(docker-build-${DOCKER_INDEX}-no-cache
182186
COMMENT "Build mscp in ${DOCKER_IMAGE} container"
183187
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
184188
COMMAND
185-
docker build --no-cache -t ${DOCKER_IMAGE} -f Dockerfile/${DOCKER_INDEX}.Dockerfile .)
189+
docker build --build-arg REQUIREDPKGS=${REQUIREDPKGS} --no-cache
190+
-t ${DOCKER_IMAGE} -f Dockerfile/${DOCKER_INDEX}.Dockerfile .)
186191

187192
add_custom_target(docker-test-${DOCKER_INDEX}
188193
COMMENT "Test mscp in ${DOCKER_IMAGE} container"
@@ -204,12 +209,19 @@ add_custom_target(docker-test-all DEPENDS ${DOCKER_TESTS})
204209
### debuild-related definitions
205210

206211
set(DEBBUILDCONTAINER mscp-build-deb)
212+
execute_process(
213+
COMMAND ${CMAKE_SOURCE_DIR}/scripts/install-build-deps.sh
214+
--dont-install --platform Linux-ubuntu
215+
OUTPUT_VARIABLE REQUIREDPKGS_DEB
216+
OUTPUT_STRIP_TRAILING_WHITESPACE)
217+
207218
add_custom_target(build-deb
208219
COMMENT "build mscp deb files inside a container"
209220
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
210221
BYPRODUCTS ${CMAKE_BINARY_DIR}/debbuild
211222
COMMAND
212-
docker build -t ${DEBBUILDCONTAINER} -f Dockerfile/build-deb.Dockerfile .
223+
docker build --build-arg REQUIREDPKGS=${REQUIREDPKGS_DEB}
224+
-t ${DEBBUILDCONTAINER} -f Dockerfile/build-deb.Dockerfile .
213225
COMMAND
214226
docker run --rm -v ${CMAKE_BINARY_DIR}:/out ${DEBBUILDCONTAINER}
215227
cp -r /debbuild /out/)
@@ -222,20 +234,28 @@ configure_file(
222234
${mscp_SOURCE_DIR}/rpm/mscp.spec.in
223235
${mscp_SOURCE_DIR}/rpm/mscp.spec
224236
@ONLY)
225-
configure_file(
226-
${mscp_SOURCE_DIR}/Dockerfile/build-srpm.Dockerfile.in
227-
${mscp_SOURCE_DIR}/Dockerfile/build-srpm.Dockerfile
228-
@ONLY)
237+
#configure_file(
238+
# ${mscp_SOURCE_DIR}/Dockerfile/build-srpm.Dockerfile.in
239+
# ${mscp_SOURCE_DIR}/Dockerfile/build-srpm.Dockerfile
240+
# @ONLY)
229241

230242
# Custom target to build mscp as a src.rpm in docker.
231243
set(RPMBUILDCONTAINER mscp-build-srpm)
232244
set(SRPMFILE mscp-${MSCP_VERSION}-1.el9.src.rpm)
245+
execute_process(
246+
COMMAND ${CMAKE_SOURCE_DIR}/scripts/install-build-deps.sh
247+
--dont-install --platform Linux-rocky
248+
OUTPUT_VARIABLE REQUIREDPKGS_RPM
249+
OUTPUT_STRIP_TRAILING_WHITESPACE)
250+
233251
add_custom_target(build-srpm
234252
COMMENT "Build mscp src.rpm inside a container"
235253
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
236254
BYPRODUCTS ${CMAKE_BINARY_DIR}/${SRPMFILE}
237255
COMMAND
238-
docker build -t ${RPMBUILDCONTAINER} -f Dockerfile/build-srpm.Dockerfile .
256+
docker build --build-arg REQUIREDPKGS=${REQUIREDPKGS_RPM}
257+
--build-arg MSCP_VERSION=${MSCP_VERSION}
258+
-t ${RPMBUILDCONTAINER} -f Dockerfile/build-srpm.Dockerfile .
239259
COMMAND
240260
docker run --rm -v ${CMAKE_BINARY_DIR}:/out ${RPMBUILDCONTAINER}
241261
cp /root/rpmbuild/SRPMS/${SRPMFILE} /out/)

Dockerfile/.gitignore

-3
This file was deleted.

Dockerfile/README.md

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11

22
Dockerfiles for building and testing mscp.
33

4-
Build container:
5-
6-
```
7-
docker build -t mscp-DIST:VER -f docker/DIST-VER.Dockerfile .
8-
```
9-
10-
Run test:
11-
12-
```
13-
docker run --init --rm mscp-DST:VER /mscp/scripts/test-in-container.sh
14-
```
15-
16-
Custom targets to build and test mscp in the containers are provided
17-
via `cmake`. See `make docker-*` targets. `make docker-build-all`
18-
builds all container images, and `make docker-test-all` runs the test
19-
in all container images.
4+
cmake provides custom targets to build and test mscp in the containers
5+
See `make docker-*` targets. `make docker-build-all` builds all
6+
container images, and `make docker-test-all` runs the test in all
7+
container images.

Dockerfile/almalinux-9.3.Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
FROM almalinux:9.3
22

3+
ARG REQUIREDPKGS
4+
35
# install pytest, sshd for test, and rpm-build
46
RUN set -ex && yum -y install \
5-
python3 python3-pip python3-devel openssh openssh-server openssh-clients rpm-build
7+
${REQUIREDPKGS} python3 python3-pip python3-devel \
8+
openssh openssh-server openssh-clients rpm-build
69

710
RUN python3 -m pip install pytest
811

@@ -28,9 +31,6 @@ ARG mscpdir="/mscp"
2831

2932
COPY . ${mscpdir}
3033

31-
# install build dependency
32-
RUN ${mscpdir}/scripts/install-build-deps.sh
33-
3434
# build
3535
RUN cd ${mscpdir} \
3636
&& rm -rf build \

Dockerfile/alpine-3.19.Dockerfile

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
FROM alpine:3.19
22

3+
# do not use REQUIREDPKGS build argument because
4+
# this Dockerfile compiles mscp with conan,so we do not need
5+
# libssl-dev and zlib-dev
6+
37
# Build mscp with conan to create single binary mscp
48

59
RUN apk add --no-cache \
6-
gcc make cmake python3 py3-pip perl linux-headers libc-dev \
7-
openssh bash python3-dev py3-pytest g++
10+
gcc make cmake libc-dev \
11+
linux-headers openssh bash perl \
12+
python3 py3-pip python3-dev py3-pytest g++
813

914
RUN pip3 install --break-system-packages conan
1015

Dockerfile/build-deb.Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
FROM ubuntu:22.04
22

3+
ARG REQUIREDPKGS
4+
35
ARG DEBIAN_FRONTEND=noninteractive
46
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
5-
ca-certificates build-essential devscripts debhelper gcc make cmake
7+
${REQUIREDPKGS} ca-certificates \
8+
build-essential devscripts debhelper gcc make cmake
69

710
ARG mscpdir="/debbuild/mscp"
811

912
COPY . ${mscpdir}
1013

11-
# install build dependency
12-
RUN ${mscpdir}/scripts/install-build-deps.sh
13-
1414
# build
1515
RUN cd ${mscpdir} \
1616
&& debuild -us -uc -S \

Dockerfile/build-srpm.Dockerfile.in Dockerfile/build-srpm.Dockerfile

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
FROM rockylinux:9
22

3+
ARG REQUIREDPKGS
4+
ARG MSCP_VERSION
5+
36
# install pytest, sshd for test, and rpm-build
4-
RUN set -ex && yum -y install rpm-build rpmdevtools
7+
RUN set -ex && yum -y install ${REQUIREDPKGS} rpm-build rpmdevtools
58

6-
ARG mscpdir="/mscp-@MSCP_VERSION@"
7-
ARG mscptgz="mscp-@MSCP_VERSION@.tar.gz"
9+
ARG mscpdir="/mscp-${MSCP_VERSION}"
10+
ARG mscptgz="mscp-${MSCP_VERSION}.tar.gz"
811

912
COPY . ${mscpdir}
1013

11-
# install build dependency
12-
RUN ${mscpdir}/scripts/install-build-deps.sh
13-
1414
# prepare rpmbuild
1515
RUN rpmdev-setuptree \
1616
&& rm -rf ${mscpdir}/build \

Dockerfile/rocky-8.9.Dockerfile

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
FROM rockylinux:8.9
22

3+
ARG REQUIREDPKGS
4+
35
# install pytest, sshd for test, and rpm-build
46
RUN set -ex && yum -y install \
5-
python3 python3-pip python3-devel openssh openssh-server openssh-clients rpm-build
7+
${REQUIREDPKGS} \
8+
python3 python3-pip python3-devel \
9+
openssh openssh-server openssh-clients rpm-build
610

711
RUN python3 -m pip install pytest
812

@@ -29,9 +33,6 @@ ARG mscpdir="/mscp"
2933

3034
COPY . ${mscpdir}
3135

32-
# install build dependency
33-
RUN ${mscpdir}/scripts/install-build-deps.sh
34-
3536
# build
3637
RUN cd ${mscpdir} \
3738
&& rm -rf build \

Dockerfile/rocky-9.3.Dockerfile

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
FROM rockylinux:9.3
22

3+
ARG REQUIREDPKGS
4+
35
# install pytest, sshd for test, and rpm-build
46
RUN set -ex && yum -y install \
5-
python3 python3-pip python3-devel openssh openssh-server openssh-clients rpm-build
7+
${REQUIREDPKGS} \
8+
python3 python3-pip python3-devel \
9+
openssh openssh-server openssh-clients rpm-build
610

711
RUN python3 -m pip install pytest
812

@@ -28,9 +32,6 @@ ARG mscpdir="/mscp"
2832

2933
COPY . ${mscpdir}
3034

31-
# install build dependency
32-
RUN ${mscpdir}/scripts/install-build-deps.sh
33-
3435
# build
3536
RUN cd ${mscpdir} \
3637
&& rm -rf build \

Dockerfile/ubuntu-20.04.Dockerfile

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
FROM ubuntu:20.04
22

3+
ARG REQUIREDPKGS
4+
35
ARG DEBIAN_FRONTEND=noninteractive
46
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
5-
ca-certificates
6-
7-
# install pytest, and sshd for test
8-
RUN apt-get install -y --no-install-recommends \
9-
python3 python3-pip python3-dev openssh-server
7+
${REQUIREDPKGS} ca-certificates python3 python3-pip python3-dev openssh-server
108

119
RUN python3 -m pip install pytest
1210

13-
1411
# preparation for sshd
1512
RUN mkdir /var/run/sshd \
1613
&& ssh-keygen -A \
@@ -31,10 +28,6 @@ ARG mscpdir="/mscp"
3128

3229
COPY . ${mscpdir}
3330

34-
# install build dependency
35-
RUN ${mscpdir}/scripts/install-build-deps.sh
36-
37-
3831
# build
3932
RUN cd ${mscpdir} \
4033
&& rm -rf build \

Dockerfile/ubuntu-22.04.Dockerfile

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
FROM ubuntu:22.04
22

3+
ARG REQUIREDPKGS
4+
35
ARG DEBIAN_FRONTEND=noninteractive
46
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
5-
ca-certificates
6-
7-
# install pytest, and sshd for test
8-
RUN apt-get install -y --no-install-recommends \
9-
python3 python3-pip python3-dev openssh-server
7+
${REQUIREDPKGS} ca-certificates python3 python3-pip python3-dev openssh-server
108

119
RUN python3 -m pip install pytest
1210

13-
1411
# preparation for sshd
1512
RUN mkdir /var/run/sshd \
1613
&& ssh-keygen -A \
@@ -31,10 +28,6 @@ ARG mscpdir="/mscp"
3128

3229
COPY . ${mscpdir}
3330

34-
# install build dependency
35-
RUN ${mscpdir}/scripts/install-build-deps.sh
36-
37-
3831
# build
3932
RUN cd ${mscpdir} \
4033
&& rm -rf build \

0 commit comments

Comments
 (0)