diff options
author | Ryo Nakamura <upa@haeena.net> | 2022-11-05 21:26:34 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2022-11-05 21:26:34 +0900 |
commit | fc56c53d04d7e499a91d0526842a6072477ddb96 (patch) | |
tree | 3675ef7d3b2f904b843f1c969b0f9b110c458724 | |
parent | 6e6e5066c7ad83ad2daf8f8ccbe7231211e41c97 (diff) |
add install-build-deps.sh and fix docker build procedure
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | docker/.gitignore | 2 | ||||
-rw-r--r-- | docker/Dockerfile-centos-8 | 22 | ||||
-rw-r--r-- | docker/Dockerfile-ubuntu-20.04 | 18 | ||||
-rw-r--r-- | docker/Dockerfile-ubuntu-22.04 | 18 | ||||
-rw-r--r-- | docker/README.md | 8 | ||||
-rwxr-xr-x | install-build-deps.sh | 16 |
7 files changed, 65 insertions, 31 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a182a7..f69f144 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,24 +70,24 @@ if(BUILD_PKG) # Ubuntu 20.04 add_custom_target(package-ubuntu-20.04-in-docker COMMENT "Build mscp in ubuntu 20.04 docker container" - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/docker - COMMAND docker build -t mscp-ubuntu:20.04 -f Dockerfile-ubuntu-20.04 . + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND docker build -t mscp-ubuntu:20.04 -f docker/Dockerfile-ubuntu-20.04 . COMMAND docker run -it --rm -v ${CMAKE_BINARY_DIR}:/out mscp-ubuntu:20.04 cp /mscp/build/mscp_${PROJECT_VERSION}-ubuntu-20.04-${ARCH}.deb /out/) # Ubuntu 22.04 add_custom_target(package-ubuntu-22.04-in-docker COMMENT "Build mscp in ubuntu 22.04 docker container" - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/docker - COMMAND docker build -t mscp-ubuntu:22.04 -f Dockerfile-ubuntu-22.04 . + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND docker build -t mscp-ubuntu:22.04 -f docker/Dockerfile-ubuntu-22.04 . COMMAND docker run -it --rm -v ${CMAKE_BINARY_DIR}:/out mscp-ubuntu:22.04 cp /mscp/build/mscp_${PROJECT_VERSION}-ubuntu-22.04-${ARCH}.deb /out/) # CentOS 8 add_custom_target(package-centos-8-in-docker COMMENT "Build mscp in centos 8 docker container" - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/docker - COMMAND docker build -t mscp-centos:8 -f Dockerfile-centos-8 . + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND docker build -t mscp-centos:8 -f docker/Dockerfile-centos-8 . COMMAND docker run -it --rm -v ${CMAKE_BINARY_DIR}:/out mscp-centos:8 cp /mscp/build/mscp_${PROJECT_VERSION}-centos-8-${ARCH}.rpm /out/) diff --git a/docker/.gitignore b/docker/.gitignore deleted file mode 100644 index 7fcc085..0000000 --- a/docker/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.deb -*.rpm diff --git a/docker/Dockerfile-centos-8 b/docker/Dockerfile-centos-8 index 7c80119..8deae76 100644 --- a/docker/Dockerfile-centos-8 +++ b/docker/Dockerfile-centos-8 @@ -1,7 +1,8 @@ FROM centos:8 -ARG DEBIAN_FRONTEND=noninteractive -ARG workdir="/" +ARG mscpdir="/mscp" + +COPY . ${mscpdir} # from https://stackoverflow.com/questions/70963985/error-failed-to-download-metadata-for-repo-appstream-cannot-prepare-internal RUN cd /etc/yum.repos.d/ @@ -9,10 +10,15 @@ RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* RUN set -ex && yum -y update && yum -y install \ - git cmake gcc make libssh-devel rpm-build + rpm-build + +RUN ${mscpdir}/install-build-deps.sh + +RUN cd ${mscpdir} \ + && rm -rf build + +RUN cd ${mscpdir} \ + && cmake -B build -DBUILD_PKG=1 \ + && cd ${mscpdir}/build \ + &&cpack -G RPM CPackConfig.cmake -RUN cd ${workdir} \ - && git clone --depth=1 https://github.com/upa/mscp \ - && mkdir mscp/build && cd mscp/build \ - && cmake .. -DBUILD_PKG=1 \ - && cpack -G RPM CPackConfig.cmake diff --git a/docker/Dockerfile-ubuntu-20.04 b/docker/Dockerfile-ubuntu-20.04 index d48d4f1..687072c 100644 --- a/docker/Dockerfile-ubuntu-20.04 +++ b/docker/Dockerfile-ubuntu-20.04 @@ -1,13 +1,19 @@ FROM ubuntu:20.04 ARG DEBIAN_FRONTEND=noninteractive -ARG workdir="/" +ARG mscpdir="/mscp" + +COPY . ${mscpdir} RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \ - git cmake build-essential libssh-dev ca-certificates + ca-certificates + +RUN ${mscpdir}/install-build-deps.sh + +RUN cd ${mscpdir} \ + && rm -rf build -RUN cd ${workdir} \ - && git clone --depth=1 https://github.com/upa/mscp \ - && mkdir mscp/build && cd mscp/build \ - && cmake .. -DBUILD_PKG=1 \ +RUN cd ${mscpdir} \ + && cmake -B build -DBUILD_PKG=1 \ + && cd ${mscpdir}/build \ && cpack -G DEB CPackConfig.cmake diff --git a/docker/Dockerfile-ubuntu-22.04 b/docker/Dockerfile-ubuntu-22.04 index eb89243..59a57d2 100644 --- a/docker/Dockerfile-ubuntu-22.04 +++ b/docker/Dockerfile-ubuntu-22.04 @@ -1,13 +1,19 @@ FROM ubuntu:22.04 ARG DEBIAN_FRONTEND=noninteractive -ARG workdir="/" +ARG mscpdir="/mscp" + +COPY . ${mscpdir} RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \ - git cmake build-essential libssh-dev ca-certificates + ca-certificates + +RUN ${mscpdir}/install-build-deps.sh + +RUN cd ${mscpdir} \ + && rm -rf build -RUN cd ${workdir} \ - && git clone --depth=1 https://github.com/upa/mscp \ - && mkdir mscp/build && cd mscp/build \ - && cmake .. -DBUILD_PKG=1 \ +RUN cd ${mscpdir} \ + && cmake -B build -DBUILD_PKG=1 \ + && cd ${mscpdir}/build \ && cpack -G DEB CPackConfig.cmake diff --git a/docker/README.md b/docker/README.md index 07279c3..872d73f 100644 --- a/docker/README.md +++ b/docker/README.md @@ -2,15 +2,17 @@ Build `mscp` in docker containers. ```console -docker build -t mscp-ubuntu:20.04 -f Dockerfile-ubuntu-20.04 . +cd .. + +docker build -t mscp-ubuntu:20.04 -f docker/Dockerfile-ubuntu-20.04 . docker run -it --rm -v (pwd):/out mscp-ubuntu:20.04 \ cp /mscp/build/mscp_0.0.0-ubuntu-20.04-x86_64.deb /out/ -docker build -t mscp-ubuntu:22.04 -f Dockerfile-ubuntu-22.04 . +docker build -t mscp-ubuntu:22.04 -f docker/Dockerfile-ubuntu-22.04 . docker run -it --rm -v (pwd):/out mscp-ubuntu:22.04 \ cp /mscp/build/mscp_0.0.0-ubuntu-22.04-x86_64.deb /out/ -docker build -t mscp-centos:8 -f Dockerfile-centos-8 . +docker build -t mscp-centos:8 -f docker/Dockerfile-centos-8 . docker run -it --rm -v (pwd):/out mscp-centos:8 \ cp /mscp/build/mscp_0.0.0-centos-8-x86_64.rpm /out/ ``` diff --git a/install-build-deps.sh b/install-build-deps.sh new file mode 100755 index 0000000..9f8e9e7 --- /dev/null +++ b/install-build-deps.sh @@ -0,0 +1,16 @@ +#!/bin/bash -e + +source /etc/os-release +set -x + +case $ID in + ubuntu*) + apt-get install -y gcc make cmake libssh-dev + ;; + centos* | rhel*) + dnf install -y gcc make cmake libssh-devel rpm-build + ;; + *) + echo "unsupported dependency install: $ID" + exit 1 +esac |