cleanup docker files and build/test procedure

This commit is contained in:
Ryo Nakamura
2022-11-06 16:00:18 +09:00
parent 15dbb564c8
commit df404ec3c6
14 changed files with 174 additions and 108 deletions

View File

@@ -20,7 +20,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: install build dependency
run: sudo ./install-build-deps.sh
run: sudo ./scripts/install-build-deps.sh
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.

View File

@@ -41,7 +41,7 @@ jobs:
uses: actions/checkout@v3
- name: Install build dependency
run: sudo ./install-build-deps.sh
run: sudo ./scripts/install-build-deps.sh
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL

View File

@@ -1,4 +1,4 @@
name: test on ubuntu
name: test
on:
push:
@@ -12,11 +12,14 @@ env:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build test container
run: docker build --rm -t mscp-test -f docker/Dockerfile-test .
- name: Run test
run: docker run --init --rm mscp-test bash -c "/usr/sbin/sshd; cd /mscp/build; ctest --verbose"
- name: Build ubuntu 22.04 container
run: docker build --rm -t mscp-ubuntu:22.04 -f docker/ubuntu-22.04.Dockerfile .
- name: Run test on ubuntu 22.04
run: docker run --init --rm mscp-ubuntu:22.04 /mscp/scripts/test-in-container.sh
- name: Build centos 8 container
run: docker build --rm -t mscp-centos:8 -f docker/centos-8.Dockerfile .
- name: Run test on centos 8
run: docker run --init --rm mscp-centos:8 /mscp/scripts/test-in-container.sh

View File

@@ -1,7 +1,9 @@
cmake_minimum_required(VERSION 3.13)
file (STRINGS "VERSION" MSCP_VERSION)
project(mscp
VERSION 0.0.0
VERSION ${MSCP_VERSION}
LANGUAGES C)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
@@ -77,24 +79,30 @@ if(BUILD_PKG)
add_custom_target(package-ubuntu-20.04-in-docker
COMMENT "Build mscp in ubuntu 20.04 docker container"
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
COMMAND docker build -t mscp-ubuntu:20.04 -f docker/ubuntu-20.04.Dockerfile .
COMMAND docker run --init --rm mscp-ubuntu:20.04
/mscp/scripts/test-in-container.sh
COMMAND docker run --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}
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
COMMAND docker build -t mscp-ubuntu:22.04 -f docker/ubuntu-22.04.Dockerfile .
COMMAND docker run --init --rm mscp-ubuntu:22.04
/mscp/scripts/test-in-container.sh
COMMAND docker run --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}
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
COMMAND docker build -t mscp-centos:8 -f docker/centos-8.Dockerfile .
COMMAND docker run --init --rm mscp-centos:8
/mscp/scripts/test-in-container.sh
COMMAND docker run --rm -v ${CMAKE_BINARY_DIR}:/out mscp-centos:8
cp /mscp/build/mscp_${PROJECT_VERSION}-centos-8-${ARCH}.rpm /out/)
# build on all conatiners

1
VERSION Normal file
View File

@@ -0,0 +1 @@
0.0.0

View File

@@ -1,30 +0,0 @@
FROM ubuntu:latest
ARG DEBIAN_FRONTEND=noninteractive
ARG mscpdir="/mscp"
COPY . ${mscpdir}
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
ca-certificates
# install numpy and pytest, and sshd for test
RUN apt-get install -y --no-install-recommends \
python3 python3-pip openssh-server
RUN python3 -m pip install numpy pytest
# preparation for sshd
RUN mkdir /var/run/sshd \
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
&& mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
# build
RUN ${mscpdir}/install-build-deps.sh
RUN cd ${mscpdir} \
&& rm -rf build \
&& mkdir build && cd build \
&& cmake .. && make

View File

@@ -1,19 +0,0 @@
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
ARG mscpdir="/mscp"
COPY . ${mscpdir}
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
ca-certificates
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 DEB CPackConfig.cmake

View File

@@ -1,19 +0,0 @@
FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
ARG mscpdir="/mscp"
COPY . ${mscpdir}
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
ca-certificates
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 DEB CPackConfig.cmake

View File

@@ -1,31 +1,37 @@
Build `mscp` in docker containers.
Build docker containers.
```console
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:20.04 -f docker/ubuntu-20.04.Dockerfile .
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 docker/Dockerfile-centos-8 .
docker run -it --rm -v (pwd):/out mscp-centos:8 \
```
Test `mscp` in the containers.
```console
docker run --init --rm mscp-ubuntu:20.04 /build/mscp/scripts/test-in-container.sh
docker run --init --rm mscp-ubuntu:22.04 /build/mscp/scripts/test-in-container.sh
docker run --init --rm mscp-centos:8 /build/mscp/scripts/test-in-container.sh
```
Retrieve deb/rpm packages.
```console
docker run --rm -v (pwd):/out mscp-ubuntu:20.04 \
cp /mscp/build/mscp_0.0.0-ubuntu-20.04-x86_64.deb /out/
docker run --rm -v (pwd):/out mscp-ubuntu:22.04 \
cp /mscp/build/mscp_0.0.0-ubuntu-22.04-x86_64.deb /out/
docker run --rm -v (pwd):/out mscp-centos:8 \
cp /mscp/build/mscp_0.0.0-centos-8-x86_64.rpm /out/
```
Test `mscp` in a ubuntu:latest docker container.
```console
cd ..
docker build --rm -t mscp-test -f docker/Dockerfile-test .
docker run --init --rm mscp-test bash -c "/usr/sbin/sshd; cd /mscp/build; ctest --verbose"
```
I don't know whether these these are good way.
I don't know whether these are good way.

View File

@@ -9,16 +9,27 @@ RUN cd /etc/yum.repos.d/
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-*
# install numpy and pytest, sshd for test, and rpm-build
RUN set -ex && yum -y update && yum -y install \
rpm-build
python3 python3-pip openssh openssh-server openssh-clients rpm-build
RUN ${mscpdir}/install-build-deps.sh
RUN cd ${mscpdir} \
&& rm -rf build
RUN python3 -m pip install numpy pytest
# preparation for sshd
RUN mkdir /var/run/sshd \
&& ssh-keygen -A \
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
&& mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
# install build dependency
RUN ${mscpdir}/scripts/install-build-deps.sh
# build
RUN cd ${mscpdir} \
&& rm -rf build \
&& cmake -B build -DBUILD_PKG=1 \
&& cd ${mscpdir}/build \
&& make \
&& cpack -G RPM CPackConfig.cmake

View File

@@ -0,0 +1,34 @@
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
ARG mscpdir="/mscp"
COPY . ${mscpdir}
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
ca-certificates
# install numpy and pytest, and sshd for test
RUN apt-get install -y --no-install-recommends \
python3 python3-pip openssh-server
RUN python3 -m pip install numpy pytest
# preparation for sshd
RUN mkdir /var/run/sshd \
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
&& mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
# install build dependency
RUN ${mscpdir}/scripts/install-build-deps.sh
# build
RUN cd ${mscpdir} \
&& rm -rf build \
&& cmake -B build -DBUILD_PKG=1 \
&& cd ${mscpdir}/build \
&& make \
&& cpack -G DEB CPackConfig.cmake

View File

@@ -0,0 +1,34 @@
FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
ARG mscpdir="/mscp"
COPY . ${mscpdir}
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
ca-certificates
# install numpy and pytest, and sshd for test
RUN apt-get install -y --no-install-recommends \
python3 python3-pip openssh-server
RUN python3 -m pip install numpy pytest
# preparation for sshd
RUN mkdir /var/run/sshd \
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
&& mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
# install build dependency
RUN ${mscpdir}/scripts/install-build-deps.sh
# build
RUN cd ${mscpdir} \
&& rm -rf build \
&& cmake -B build -DBUILD_PKG=1 \
&& cd ${mscpdir}/build \
&& make \
&& cpack -G DEB CPackConfig.cmake

View File

@@ -1,4 +1,6 @@
#!/bin/bash -e
#
# Install build dpenedencies.
source /etc/os-release
set -x

35
scripts/test-in-container.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/bash -e
#
# Run this script in docker containers. This script installs mscp from built package
# and run test for mscp in the installed path.
source /etc/os-release
script_dir=$(cd $(dirname ${0}) && pwd)
cd $script_dir
project_version=$(cat ../VERSION)
arch=$(uname -p)
set -x
# install package
case $ID in
ubuntu*)
pkg=mscp_${project_version}-${ID}-${VERSION_ID}-${arch}.deb
dpkg -i ../build/$pkg
;;
centos* | rhel*)
pkg=mscp_${project_version}-${ID}-${VERSION_ID}-${arch}.rpm
rpm -iv ../build/$pkg
;;
*)
echo "unsupported test platform: $ID"
exit 1
esac
# Run sshd
if [ ! -e /var/run/sshd.pid ]; then
/usr/sbin/sshd
fi
# Run test
python3 -m pytest ../test -v