From afeeff442465fc3dd26076bbe7aaf203d725633a Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Wed, 3 Apr 2019 11:44:03 +0200 Subject: [PATCH] Add ci --- .ci/Makefile | 179 ++++++++++++++++++++++++++++++++ .ci/docker/alpine/Dockerfile | 46 ++++++++ .ci/docker/archlinux/Dockerfile | 46 ++++++++ .ci/docker/centos/Dockerfile | 52 ++++++++++ .ci/docker/debian/Dockerfile | 49 +++++++++ .ci/docker/fedora/Dockerfile | 49 +++++++++ .ci/docker/opensuse/Dockerfile | 49 +++++++++ .ci/docker/ubuntu/Dockerfile | 49 +++++++++ .ci/sample/CMakeLists.txt | 22 ++++ .ci/sample/main.cpp | 10 ++ .dockerignore | 21 ++++ 11 files changed, 572 insertions(+) create mode 100644 .ci/Makefile create mode 100644 .ci/docker/alpine/Dockerfile create mode 100644 .ci/docker/archlinux/Dockerfile create mode 100644 .ci/docker/centos/Dockerfile create mode 100644 .ci/docker/debian/Dockerfile create mode 100644 .ci/docker/fedora/Dockerfile create mode 100644 .ci/docker/opensuse/Dockerfile create mode 100644 .ci/docker/ubuntu/Dockerfile create mode 100644 .ci/sample/CMakeLists.txt create mode 100644 .ci/sample/main.cpp create mode 100644 .dockerignore diff --git a/.ci/Makefile b/.ci/Makefile new file mode 100644 index 000000000..511598c0a --- /dev/null +++ b/.ci/Makefile @@ -0,0 +1,179 @@ +PROJECT := clp +BRANCH := $(shell git rev-parse --abbrev-ref HEAD) +SHA1 := $(shell git rev-parse --verify HEAD) + +# General commands +.PHONY: help +BOLD=\e[1m +RESET=\e[0m + +help: + @echo -e "${BOLD}SYNOPSIS${RESET}" + @echo -e "\tmake [NOCACHE=1]" + @echo + @echo -e "${BOLD}DESCRIPTION${RESET}" + @echo -e "\ttest build inside docker container to have a reproductible build." + @echo + @echo -e "${BOLD}MAKE TARGETS${RESET}" + @echo -e "\t${BOLD}help${RESET}: display this help and exit." + @echo + @echo -e "\t${BOLD}env${RESET}: build a virtual env image." + @echo -e "\t${BOLD}sh_env_${RESET}: run a container using the virtual env image (debug purpose)." + @echo + @echo -e "\t${BOLD}devel${RESET}: build the library using all devel images." + @echo -e "\t${BOLD}devel_${RESET}: build the library using a specific devel image." + @echo -e "\t${BOLD}test_${RESET}: auto test using the devel image." + @echo -e "\t${BOLD}sh_${RESET}: run a container using the devel image (debug purpose)." + @echo + @echo -e "\t${BOLD}install${RESET}: execute the cmake target ${BOLD}install${RESET} using all devel image container, then create an install image with it." + @echo -e "\t${BOLD}install_${RESET}: execute the cmake target ${BOLD}install${RESET} using the devel image container specified, then create an install image with it." + @echo -e "\t${BOLD}test_install${RESET}: configure, build, install then test a sample project against it using all ${BOLD}install${RESET} image containers." + @echo -e "\t${BOLD}test_install_${RESET}: configure, build, install then test a sample project against it using the ${BOLD}install${RESET} image container specified." + @echo -e "\t${BOLD}sh_install_${RESET}: run a container using the install image (debug purpose)." + @echo + @echo -e "\t${BOLD}clean${RESET}: Remove cache and docker image." + @echo -e "\t${BOLD}clean_${RESET}: Remove cache and docker image for the specified distro." + @echo + @echo -e "\t${BOLD}${RESET}:" + @echo -e "\t\t${BOLD}alpine${RESET} (latest)" + @echo -e "\t\t${BOLD}archlinux${RESET} (latest)" + @echo -e "\t\t${BOLD}centos${RESET} (latest)" + @echo -e "\t\t${BOLD}fedora${RESET} (latest)" + @echo -e "\t\t${BOLD}opensuse${RESET} (tumbleweed)" + @echo -e "\t\t${BOLD}debian${RESET} (latest)" + @echo -e "\t\t${BOLD}ubuntu${RESET} (latest)" + @echo -e "\te.g. 'make test_ubuntu'" + @echo + @echo -e "\t${BOLD}NOCACHE=1${RESET}: use 'docker build --no-cache' when building container (default use cache)." + @echo + @echo -e "branch: $(BRANCH)" + @echo -e "sha1: $(SHA1)" + +# Need to add cmd_distro to PHONY otherwise target are ignored since they do not +# contain recipe (using FORCE do not work here) +.PHONY: all +all: devel + +# Delete all implicit rules to speed up makefile +MAKEFLAGS += --no-builtin-rules +.SUFFIXES: +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = +# Keep all intermediate files +# ToDo: try to remove it later +.SECONDARY: + +# Docker image name prefix. +IMAGE := ${PROJECT} + +ifdef NOCACHE +DOCKER_BUILD_CMD := docker build --no-cache +else +DOCKER_BUILD_CMD := docker build +endif + +DOCKER_RUN_CMD := docker run --rm --init --net=host + +# Currently supported distro +DISTROS = alpine archlinux centos fedora opensuse debian ubuntu + +# $* stem +# $< first prerequist +# $@ target name + +# ENV +targets = $(addprefix env_, $(DISTROS)) +.PHONY: env $(targets) +env: $(targets) +$(targets): env_%: cache/%/docker_env.tar +cache/%/docker_env.tar: docker/%/Dockerfile + @docker image rm -f ${IMAGE}_$*:env 2>/dev/null + ${DOCKER_BUILD_CMD} --target=env --tag ${IMAGE}_$*:env -f $< docker/$* + @rm -f $@ + mkdir -p cache/$* + docker save ${IMAGE}_$*:env -o $@ + +# Run a container using the env image. +targets = $(addprefix sh_env_, $(DISTROS)) +.PHONY: $(targets) +$(targets): sh_env_%: cache/%/docker_env.tar + ${DOCKER_RUN_CMD} -it --name ${IMAGE}_$* ${IMAGE}_$*:env /bin/sh + +# DEVEL +targets = $(addprefix devel_, $(DISTROS)) +.PHONY: devel $(targets) +devel: $(targets) +$(targets): devel_%: cache/%/docker_devel.tar +cache/%/docker_devel.tar: docker/%/Dockerfile \ + ../CMakeLists.txt ../cmake \ + ../Clp + @docker image rm -f ${IMAGE}_$*:devel 2>/dev/null + ${DOCKER_BUILD_CMD} --target=devel --tag ${IMAGE}_$*:devel -f $< .. + @rm -f $@ + mkdir -p cache/$* + docker save ${IMAGE}_$*:devel -o $@ + +# DOCKER BASH INSTALL (debug) +targets = $(addprefix sh_devel_, $(DISTROS)) +.PHONY: $(targets) +$(targets): sh_devel_%: cache/%/docker_devel.tar + ${DOCKER_RUN_CMD} -it --name ${IMAGE}_$* ${IMAGE}_$*:devel /bin/sh + +# TEST DEVEL +targets = $(addprefix test_, $(DISTROS)) +.PHONY: test $(targets) +test: $(targets) +$(targets): test_%: cache/%/docker_devel.tar + ${DOCKER_RUN_CMD} -t --name ${IMAGE}_$* ${IMAGE}_$*:devel cmake --build build --target test + +# INSTALL +targets = $(addprefix install_, $(DISTROS)) +.PHONY: install $(targets) +install: $(targets) +$(targets): install_%: cache/%/docker_install.tar +cache/%/docker_install.tar: docker/%/Dockerfile \ + sample + @docker image rm -f ${IMAGE}_$*:install 2>/dev/null + ${DOCKER_BUILD_CMD} --target=install --tag ${IMAGE}_$*:install -f $< .. + @rm -f $@ + mkdir -p cache/$* + docker save ${IMAGE}_$*:install -o $@ + +# DOCKER BASH INSTALL (debug) +targets = $(addprefix sh_install_, $(DISTROS)) +.PHONY: $(targets) +$(targets): sh_install_%: cache/%/docker_install.tar + ${DOCKER_RUN_CMD} -it --name ${IMAGE}_$* ${IMAGE}_$*:install /bin/sh + +# TEST INSTALL +targets = $(addprefix test_install_, $(DISTROS)) +.PHONY: test_install $(targets) +test_install: $(targets) +$(targets): test_install_%: cache/%/docker_install.tar sample + @docker load -i cache/$*/docker_install.tar + ${DOCKER_RUN_CMD} -t --name ${IMAGE}_$* ${IMAGE}_$*:install /bin/sh -c \ + "cmake -H. -Bbuild; \ + cmake --build build --target all; \ + cmake --build build --target test; \ + cmake --build build --target install" + +# CLEAN +targets = $(addprefix clean_, $(DISTROS)) +.PHONY: clean $(targets) +clean: $(targets) + -rmdir cache +$(targets): clean_%: + docker container prune -f + docker image prune -f + -docker image rm -f ${IMAGE}_$*:install 2>/dev/null + -docker image rm -f ${IMAGE}_$*:devel 2>/dev/null + -docker image rm -f ${IMAGE}_$*:env 2>/dev/null + -rm -f cache/$*/docker_install.tar + -rm -f cache/$*/docker_devel.tar + -rm -f cache/$*/docker_env.tar + -rmdir cache/$* + +.PHONY: distclean +distclean: clean + -docker container rm -f $$(docker container ls -aq) + -docker image rm -f $$(docker image ls -aq) diff --git a/.ci/docker/alpine/Dockerfile b/.ci/docker/alpine/Dockerfile new file mode 100644 index 000000000..8cf650fef --- /dev/null +++ b/.ci/docker/alpine/Dockerfile @@ -0,0 +1,46 @@ +# Create a virtual environment with all tools installed +# ref: https://hub.docker.com/_/alpine +FROM alpine:edge AS env +LABEL maintainer="corentinl@google.com" +# Install system build dependencies +ENV PATH=$PATH:/usr/local/bin +RUN apk add --no-cache git build-base linux-headers cmake + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/CoinUtils.git \ +&& cd CoinUtils \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf CoinUtils + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/Osi.git \ +&& cd Osi \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf Osi + +CMD [ "/bin/sh" ] + +# Add the library src to our build env +FROM env AS devel +# Create lib directory +WORKDIR /home/lib +# Bundle lib source +COPY . . +# CMake configure +RUN cmake -S. -Bbuild +# CMake build +RUN cmake --build build --target all -v +# CMake build +RUN cmake --build build --target install + +# Create an install image +FROM env AS install +# Copy lib from devel to prod +COPY --from=devel /usr/local /usr/local/ +# Copy sample +WORKDIR /home/sample +COPY .ci/sample . diff --git a/.ci/docker/archlinux/Dockerfile b/.ci/docker/archlinux/Dockerfile new file mode 100644 index 000000000..77e8b1d1a --- /dev/null +++ b/.ci/docker/archlinux/Dockerfile @@ -0,0 +1,46 @@ +# Create a virtual environment with all tools installed +# ref: https://hub.docker.com/_/archlinux/ +FROM archlinux/base AS env +LABEL maintainer="corentinl@google.com" +# Install system build dependencies +ENV PATH=$PATH:/usr/local/bin +RUN pacman -Syu --noconfirm base-devel git cmake + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/CoinUtils.git \ +&& cd CoinUtils \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf CoinUtils + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/Osi.git \ +&& cd Osi \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf Osi + +CMD [ "/bin/sh" ] + +# Add the library src to our build env +FROM env AS devel +# Create lib directory +WORKDIR /home/lib +# Bundle lib source +COPY . . +# CMake configure +RUN cmake -S. -Bbuild +# CMake build +RUN cmake --build build --target all -v +# CMake build +RUN cmake --build build --target install + +# Create an install image +FROM env AS install +# Copy lib from devel to prod +COPY --from=devel /usr/local /usr/local/ +# Copy sample +WORKDIR /home/sample +COPY .ci/sample . diff --git a/.ci/docker/centos/Dockerfile b/.ci/docker/centos/Dockerfile new file mode 100644 index 000000000..f206b256b --- /dev/null +++ b/.ci/docker/centos/Dockerfile @@ -0,0 +1,52 @@ +# Create a virtual environment with all tools installed +# ref: https://hub.docker.com/_/centos +FROM centos:latest AS env +LABEL maintainer="corentinl@google.com" +# Install system build dependencies +ENV PATH=$PATH:/usr/local/bin +RUN yum -y update \ +&& yum -y groupinstall "Development Tools" \ +&& yum -y install epel-release \ +&& yum -y install cmake3 \ +&& ln -s /usr/bin/cmake3 /usr/local/bin/cmake \ +&& yum clean all \ +&& rm -rf /var/cache/yum + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/CoinUtils.git \ +&& cd CoinUtils \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf CoinUtils + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/Osi.git \ +&& cd Osi \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf Osi + +CMD [ "/bin/sh" ] + +# Add the library src to our build env +FROM env AS devel +# Create lib directory +WORKDIR /home/lib +# Bundle lib source +COPY . . +# CMake configure +RUN cmake -H. -Bbuild +# CMake build +RUN cmake --build build --target all +# CMake build +RUN cmake --build build --target install + +# Create an install image +FROM env AS install +# Copy lib from devel to prod +COPY --from=devel /usr/local /usr/local/ +# Copy sample +WORKDIR /home/sample +COPY .ci/sample . diff --git a/.ci/docker/debian/Dockerfile b/.ci/docker/debian/Dockerfile new file mode 100644 index 000000000..fccdf808a --- /dev/null +++ b/.ci/docker/debian/Dockerfile @@ -0,0 +1,49 @@ +# Create a virtual environment with all tools installed +# ref: https://hub.docker.com/_/debian +FROM debian:latest AS env +LABEL maintainer="corentinl@google.com" +# Install system build dependencies +ENV PATH=$PATH:/usr/local/bin +RUN apt-get update -q && \ +apt-get install -yq git build-essential cmake && \ +apt-get clean && \ +rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/CoinUtils.git \ +&& cd CoinUtils \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf CoinUtils + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/Osi.git \ +&& cd Osi \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf Osi + +CMD [ "/bin/sh" ] + +# Add the library src to our build env +FROM env AS devel +# Create lib directory +WORKDIR /home/lib +# Bundle lib source +COPY . . +# CMake configure +RUN cmake -S. -Bbuild +# CMake build +RUN cmake --build build --target all +# CMake build +RUN cmake --build build --target install + +# Create an install image +FROM env AS install +# Copy lib from devel to prod +COPY --from=devel /usr/local /usr/local/ +# Copy sample +WORKDIR /home/sample +COPY .ci/sample . diff --git a/.ci/docker/fedora/Dockerfile b/.ci/docker/fedora/Dockerfile new file mode 100644 index 000000000..7fc72a489 --- /dev/null +++ b/.ci/docker/fedora/Dockerfile @@ -0,0 +1,49 @@ +# Create a virtual environment with all tools installed +# ref: https://hub.docker.com/_/fedora +FROM fedora:latest AS env +LABEL maintainer="corentinl@google.com" +# Install system build dependencies +ENV PATH=$PATH:/usr/local/bin +RUN dnf -y update \ +&& dnf -y groupinstall "Development Tools" \ +&& dnf -y install cmake gcc-c++ \ +&& dnf clean all + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/CoinUtils.git \ +&& cd CoinUtils \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf CoinUtils + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/Osi.git \ +&& cd Osi \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf Osi + +CMD [ "/bin/sh" ] + +# Add the library src to our build env +FROM env AS devel +# Create lib directory +WORKDIR /home/lib +# Bundle lib source +COPY . . +# CMake configure +RUN cmake -S. -Bbuild +# CMake build +RUN cmake --build build --target all -v +# CMake build +RUN cmake --build build --target install + +# Create an install image +FROM env AS install +# Copy lib from devel to prod +COPY --from=devel /usr/local /usr/local/ +# Copy sample +WORKDIR /home/sample +COPY .ci/sample . diff --git a/.ci/docker/opensuse/Dockerfile b/.ci/docker/opensuse/Dockerfile new file mode 100644 index 000000000..1695addbd --- /dev/null +++ b/.ci/docker/opensuse/Dockerfile @@ -0,0 +1,49 @@ +# Create a virtual environment with all tools installed +# ref: https://hub.docker.com/r/opensuse/tumbleweed +FROM opensuse/tumbleweed AS env +LABEL maintainer="corentinl@google.com" +# Install system build dependencies +ENV PATH=$PATH:/usr/local/bin +RUN zypper up -y \ +&& zypper install -y gcc gcc-c++ cmake git \ +&& zypper clean -a +ENV CC=gcc CXX=g++ + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/CoinUtils.git \ +&& cd CoinUtils \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf CoinUtils + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/Osi.git \ +&& cd Osi \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf Osi + +CMD [ "/bin/sh" ] + +# Add the library src to our build env +FROM env AS devel +# Create lib directory +WORKDIR /home/lib +# Bundle lib source +COPY . . +# CMake configure +RUN cmake -S. -Bbuild +# CMake build +RUN cmake --build build --target all -v +# CMake build +RUN cmake --build build --target install + +# Create an install image +FROM env AS install +# Copy lib from devel to prod +COPY --from=devel /usr/local /usr/local/ +# Copy sample +WORKDIR /home/sample +COPY .ci/sample . diff --git a/.ci/docker/ubuntu/Dockerfile b/.ci/docker/ubuntu/Dockerfile new file mode 100644 index 000000000..528d34f9d --- /dev/null +++ b/.ci/docker/ubuntu/Dockerfile @@ -0,0 +1,49 @@ +# Create a virtual environment with all tools installed +# ref: https://hub.docker.com/_/ubuntu +FROM ubuntu:latest AS env +LABEL maintainer="corentinl@google.com" +# Install system build dependencies +ENV PATH=$PATH:/usr/local/bin +RUN apt-get update -q && \ +apt-get install -yq git build-essential cmake && \ +apt-get clean && \ +rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/CoinUtils.git \ +&& cd CoinUtils \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf CoinUtils + +RUN cd /tmp \ +&& git clone https://github.com/Mizux/Osi.git \ +&& cd Osi \ +&& cmake -H. -Bbuild \ +&& cmake --build build --target install \ +&& cd .. \ +&& rm -rf Osi + +CMD [ "/bin/sh" ] + +# Add the library src to our build env +FROM env AS devel +# Create lib directory +WORKDIR /home/lib +# Bundle lib source +COPY . . +# CMake configure +RUN cmake -H. -Bbuild +# CMake build +RUN cmake --build build --target all +# CMake build +RUN cmake --build build --target install + +# Create an install image +FROM env AS install +# Copy lib from devel to prod +COPY --from=devel /usr/local /usr/local/ +# Copy sample +WORKDIR /home/sample +COPY .ci/sample . diff --git a/.ci/sample/CMakeLists.txt b/.ci/sample/CMakeLists.txt new file mode 100644 index 000000000..2e78a62e5 --- /dev/null +++ b/.ci/sample/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.5) +project(Sample VERSION 1.0.0 LANGUAGES CXX) + +include(CTest) +find_package(Clp REQUIRED) + +add_executable(sample main.cpp) +#target_compile_features(sample PUBLIC cxx_std_11) +set_target_properties(sample PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON + VERSION ${PROJECT_VERSION}) +target_link_libraries(sample PRIVATE Coin::Clp) + +if(BUILD_TESTING) + add_test(NAME sample_UT COMMAND sample) +endif() + +include(GNUInstallDirs) +install(TARGETS sample + EXPORT SampleTargets + DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/.ci/sample/main.cpp b/.ci/sample/main.cpp new file mode 100644 index 000000000..765fd4caf --- /dev/null +++ b/.ci/sample/main.cpp @@ -0,0 +1,10 @@ +#include +#include +#include + +int main(int argc, char** argv) { + std::cout << "coinutils version: " << COINUTILS_VERSION << std::endl; + std::cout << "clp version: " << CLP_VERSION << std::endl; + return 0; +} + diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..64ca80501 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,21 @@ +# Project Files unneeded by docker +.ci/cache +.ci/docker +.git +.gitignore +.github +.dockerignore +.travis.yml +.clang-format +AUTHORS +INSTALL +install-sh +missing +README +README.md + +build/ + +# Editor directories and files +*.user +*.swp