Skip to content

Commit cacb7a0

Browse files
committed
Add CMake CI
1 parent 1496c20 commit cacb7a0

File tree

11 files changed

+642
-0
lines changed

11 files changed

+642
-0
lines changed

.dockerignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Project Files unneeded by docker
2+
ci/cache
3+
ci/docker
4+
.git
5+
.gitignore
6+
.github
7+
.dockerignore
8+
.travis.yml
9+
.clang-format
10+
AUTHORS
11+
INSTALL
12+
install-sh
13+
missing
14+
README
15+
README.md
16+
17+
build/
18+
19+
# Editor directories and files
20+
*.user
21+
*.swp

ci/Makefile

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
PROJECT := cgl
2+
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
3+
SHA1 := $(shell git rev-parse --verify HEAD)
4+
5+
# General commands
6+
.PHONY: help
7+
BOLD=\e[1m
8+
RESET=\e[0m
9+
10+
help:
11+
@echo -e "${BOLD}SYNOPSIS${RESET}"
12+
@echo -e "\tmake <target> [NOCACHE=1]"
13+
@echo
14+
@echo -e "${BOLD}DESCRIPTION${RESET}"
15+
@echo -e "\ttest build inside docker container to have a reproductible build."
16+
@echo
17+
@echo -e "${BOLD}MAKE TARGETS${RESET}"
18+
@echo -e "\t${BOLD}help${RESET}: display this help and exit."
19+
@echo
20+
@echo -e "\t${BOLD}<stage>${RESET}: build <stage> docker images for ALL DISTROS."
21+
@echo -e "\t${BOLD}<distro>_<stage>${RESET}: build <stage> docker image for a specific distro."
22+
@echo -e "\t${BOLD}save_<stage>${RESET}: Save <stage> docker images for ALL DISTROS."
23+
@echo -e "\t${BOLD}save_<distro>_<stage>${RESET}: Save the <stage> docker image for a specific distro."
24+
@echo -e "\t${BOLD}sh_<distro>_<stage>${RESET}: run a container using the <stage> docker image specified (debug purpose)."
25+
@echo
26+
@echo -e "\tWith ${BOLD}<stage>${RESET}:"
27+
@echo -e "\t\t${BOLD}env${RESET}"
28+
@echo -e "\t\t${BOLD}devel${RESET}"
29+
@echo -e "\t\t${BOLD}build${RESET}"
30+
@echo -e "\t\t${BOLD}test${RESET}"
31+
@echo -e "\t\t${BOLD}install_env${RESET}"
32+
@echo -e "\t\t${BOLD}install_devel${RESET}"
33+
@echo -e "\t\t${BOLD}install_build${RESET}"
34+
@echo -e "\t\t${BOLD}install_test${RESET}"
35+
@echo -e "\te.g. 'make build'"
36+
@echo
37+
@echo -e "\tWith ${BOLD}<distro>${RESET}:"
38+
@echo -e "\t\t${BOLD}alpine${RESET} (edge)"
39+
@echo -e "\t\t${BOLD}archlinux${RESET} (latest)"
40+
@echo -e "\t\t${BOLD}centos${RESET} (latest)"
41+
@echo -e "\t\t${BOLD}debian${RESET} (latest)"
42+
@echo -e "\t\t${BOLD}fedora${RESET} (latest)"
43+
@echo -e "\t\t${BOLD}opensuse${RESET} (leap)"
44+
@echo -e "\t\t${BOLD}ubuntu${RESET} (latest)"
45+
@echo -e "\te.g. 'make ubuntu_test'"
46+
@echo
47+
@echo -e "\t${BOLD}clean${RESET}: Remove cache and ALL docker images."
48+
@echo -e "\t${BOLD}clean_<distro>${RESET}: Remove cache and docker images for the specified distro."
49+
@echo -e "\t${BOLD}clean_<vm>${RESET}: Remove virtual machine for the specified vm."
50+
@echo
51+
@echo -e "\t${BOLD}NOCACHE=1${RESET}: use 'docker build --no-cache' when building container (default use cache)."
52+
@echo
53+
@echo -e "branch: $(BRANCH)"
54+
@echo -e "sha1: $(SHA1)"
55+
56+
# Need to add cmd_distro to PHONY otherwise target are ignored since they do not
57+
# contain recipe (using FORCE do not work here)
58+
.PHONY: all
59+
all: build
60+
61+
# Delete all implicit rules to speed up makefile
62+
MAKEFLAGS += --no-builtin-rules
63+
.SUFFIXES:
64+
# Remove some rules from gmake that .SUFFIXES does not remove.
65+
SUFFIXES =
66+
# Keep all intermediate files
67+
# ToDo: try to remove it later
68+
.SECONDARY:
69+
70+
# Docker image name prefix.
71+
IMAGE := ${PROJECT}
72+
73+
ifdef NOCACHE
74+
DOCKER_BUILD_CMD := docker build --no-cache
75+
else
76+
DOCKER_BUILD_CMD := docker build
77+
endif
78+
79+
DOCKER_RUN_CMD := docker run --rm --init --net=host
80+
81+
# Currently supported distro
82+
DISTROS = alpine archlinux centos debian fedora opensuse ubuntu
83+
84+
# $* stem
85+
# $< first prerequist
86+
# $@ target name
87+
88+
############
89+
## STAGES ##
90+
############
91+
STAGES = env devel build test install_env install_devel install_build install_test
92+
define make-stage-target =
93+
#$$(info STAGE: $1)
94+
#$$(info Create targets: $1 $(addsuffix _$1, $(DISTROS)).)
95+
targets_$1 = $(addsuffix _$1, $(DISTROS))
96+
.PHONY: $1 $$(targets_$1)
97+
$1: $$(targets_$1)
98+
$$(targets_$1): %_$1: docker/%/Dockerfile
99+
#@docker image rm -f ${IMAGE}:$$*_$1 2>/dev/null
100+
${DOCKER_BUILD_CMD} --target=$1 --tag ${IMAGE}:$$*_$1 -f $$< ..
101+
102+
#$$(info Create targets: save_$1 $(addprefix save_, $(addsuffix _$1, $(DISTROS))) (debug).)
103+
save_targets_$1 = $(addprefix save_, $(addsuffix _$1, $(DISTROS)))
104+
.PHONY: save_$1 $$(save_targets_$1)
105+
save_$1: $$(save_targets_$1)
106+
$$(save_targets_$1): save_%_$1: cache/%/docker_$1.tar
107+
cache/%/docker_$1.tar: %_$1
108+
@rm -f $$@
109+
mkdir -p cache/$$*
110+
docker save ${IMAGE}:$$*_$1 -o $$@
111+
112+
#$$(info Create targets: $(addprefix sh_, $(addsuffix _$1, $(DISTROS))) (debug).)
113+
sh_targets_$1 = $(addprefix sh_, $(addsuffix _$1, $(DISTROS)))
114+
.PHONY: $$(sh_targets_$1)
115+
$$(sh_targets_$1): sh_%_$1: %_$1
116+
${DOCKER_RUN_CMD} -it --name ${IMAGE}_$$*_$1 ${IMAGE}:$$*_$1
117+
118+
#$$(info Create targets: $(addprefix clean_, $(addsuffix _$1, $(DISTROS))).)
119+
clean_targets_$1 = $(addprefix clean_, $(addsuffix _$1, $(DISTROS)))
120+
.PHONY: clean_$1 $$(clean_targets_$1)
121+
clean_$1: $$(clean_targets_$1)
122+
$$(clean_targets_$1): clean_%_$1:
123+
docker image rm -f ${IMAGE}:$$*_$1 2>/dev/null
124+
rm -f cache/$$*/docker_$1.tar
125+
endef
126+
127+
$(foreach stage,$(STAGES),$(eval $(call make-stage-target,$(stage))))
128+
129+
## CLEAN ##
130+
clean_targets = $(addprefix clean_, $(DISTROS))
131+
.PHONY: clean $(clean_targets)
132+
clean: $(clean_targets)
133+
docker container prune -f
134+
docker image prune -f
135+
-rmdir cache
136+
$(clean_targets): clean_%: $(addprefix clean_%_, $(STAGES))
137+
-rmdir cache/$*
138+
139+
.PHONY: distclean
140+
distclean: clean
141+
-docker container rm -f $$(docker container ls -aq)
142+
-docker image rm -f $$(docker image ls -aq)

ci/docker/alpine/Dockerfile

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Create a virtual environment with all tools installed
2+
# ref: https://hub.docker.com/_/alpine
3+
FROM alpine:edge AS env
4+
LABEL maintainer="corentinl@google.com"
5+
# Install system build dependencies
6+
ENV PATH=$PATH:/usr/local/bin
7+
RUN apk add --no-cache git build-base linux-headers cmake
8+
9+
RUN cd /tmp \
10+
&& git clone -b stable/2.11 https://github.com/Mizux/CoinUtils.git \
11+
&& cd CoinUtils \
12+
&& cmake -S. -Bbuild \
13+
&& cmake --build build --target install \
14+
&& cd .. \
15+
&& rm -rf CoinUtils
16+
17+
RUN cd /tmp \
18+
&& git clone -b stable/0.108 https://github.com/Mizux/Osi.git \
19+
&& cd Osi \
20+
&& cmake -S. -Bbuild \
21+
&& cmake --build build --target install \
22+
&& cd .. \
23+
&& rm -rf Osi
24+
25+
RUN cd /tmp \
26+
&& git clone -b stable/1.17 https://github.com/Mizux/Clp.git \
27+
&& cd Clp \
28+
&& cmake -S. -Bbuild \
29+
&& cmake --build build --target install \
30+
&& cd .. \
31+
&& rm -rf Clp
32+
33+
# Add the library src to our build env
34+
FROM env AS devel
35+
WORKDIR /home/project
36+
COPY . .
37+
38+
FROM devel AS build
39+
RUN cmake --version
40+
RUN cmake -S. -Bbuild
41+
RUN cmake --build build --target all -v
42+
RUN cmake --build build --target install -v
43+
44+
FROM build AS test
45+
RUN cmake --build build --target test -v
46+
47+
# Test install rules
48+
FROM env AS install_env
49+
COPY --from=build /usr/local /usr/local/
50+
51+
FROM install_env AS install_devel
52+
WORKDIR /home/sample
53+
COPY ci/sample .
54+
55+
FROM install_devel AS install_build
56+
RUN cmake -S. -Bbuild
57+
RUN cmake --build build --target all -v
58+
59+
FROM install_build AS install_test
60+
RUN cmake --build build --target test -v
61+

ci/docker/archlinux/Dockerfile

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Create a virtual environment with all tools installed
2+
# ref: https://hub.docker.com/_/archlinux/
3+
FROM archlinux:latest AS env
4+
LABEL maintainer="corentinl@google.com"
5+
# Install system build dependencies
6+
ENV PATH=$PATH:/usr/local/bin
7+
RUN pacman -Syu --noconfirm base-devel git cmake
8+
9+
RUN cd /tmp \
10+
&& git clone -b stable/2.11 https://github.com/Mizux/CoinUtils.git \
11+
&& cd CoinUtils \
12+
&& cmake -S. -Bbuild \
13+
&& cmake --build build --target install \
14+
&& cd .. \
15+
&& rm -rf CoinUtils
16+
17+
RUN cd /tmp \
18+
&& git clone -b stable/0.108 https://github.com/Mizux/Osi.git \
19+
&& cd Osi \
20+
&& cmake -S. -Bbuild \
21+
&& cmake --build build --target install \
22+
&& cd .. \
23+
&& rm -rf Osi
24+
25+
RUN cd /tmp \
26+
&& git clone -b stable/1.17 https://github.com/Mizux/Clp.git \
27+
&& cd Clp \
28+
&& cmake -S. -Bbuild \
29+
&& cmake --build build --target install \
30+
&& cd .. \
31+
&& rm -rf Clp
32+
33+
# Add the library src to our build env
34+
FROM env AS devel
35+
WORKDIR /home/project
36+
COPY . .
37+
38+
FROM devel AS build
39+
RUN cmake --version
40+
RUN cmake -S. -Bbuild
41+
RUN cmake --build build --target all -v
42+
RUN cmake --build build --target install -v
43+
44+
FROM build AS test
45+
RUN cmake --build build --target test -v
46+
47+
# Test install rules
48+
FROM env AS install_env
49+
COPY --from=build /usr/local /usr/local/
50+
51+
FROM install_env AS install_devel
52+
WORKDIR /home/sample
53+
COPY ci/sample .
54+
55+
FROM install_devel AS install_build
56+
RUN cmake -S. -Bbuild
57+
RUN cmake --build build --target all -v
58+
59+
FROM install_build AS install_test
60+
RUN cmake --build build --target test -v
61+

ci/docker/centos/Dockerfile

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Create a virtual environment with all tools installed
2+
# ref: https://hub.docker.com/_/centos
3+
FROM centos:latest AS env
4+
LABEL maintainer="corentinl@google.com"
5+
# Install system build dependencies
6+
ENV PATH=$PATH:/usr/local/bin
7+
RUN yum -y update \
8+
&& yum -y groupinstall "Development Tools" \
9+
&& yum -y install epel-release \
10+
&& yum -y install cmake3 \
11+
&& ln -s /usr/bin/cmake3 /usr/local/bin/cmake \
12+
&& yum clean all \
13+
&& rm -rf /var/cache/yum
14+
15+
RUN cd /tmp \
16+
&& git clone -b stable/2.11 https://github.com/Mizux/CoinUtils.git \
17+
&& cd CoinUtils \
18+
&& cmake -S. -Bbuild \
19+
&& cmake --build build --target install \
20+
&& cd .. \
21+
&& rm -rf CoinUtils
22+
23+
RUN cd /tmp \
24+
&& git clone -b stable/0.108 https://github.com/Mizux/Osi.git \
25+
&& cd Osi \
26+
&& cmake -S. -Bbuild \
27+
&& cmake --build build --target install \
28+
&& cd .. \
29+
&& rm -rf Osi
30+
31+
RUN cd /tmp \
32+
&& git clone -b stable/1.17 https://github.com/Mizux/Clp.git \
33+
&& cd Clp \
34+
&& cmake -S. -Bbuild \
35+
&& cmake --build build --target install \
36+
&& cd .. \
37+
&& rm -rf Clp
38+
39+
# Add the library src to our build env
40+
FROM env AS devel
41+
WORKDIR /home/project
42+
COPY . .
43+
44+
FROM devel AS build
45+
RUN cmake --version
46+
RUN cmake -S. -Bbuild
47+
RUN cmake --build build --target all -v
48+
RUN cmake --build build --target install -v
49+
50+
FROM build AS test
51+
RUN cmake --build build --target test -v
52+
53+
# Test install rules
54+
FROM env AS install_env
55+
COPY --from=build /usr/local /usr/local/
56+
57+
FROM install_env AS install_devel
58+
WORKDIR /home/sample
59+
COPY ci/sample .
60+
61+
FROM install_devel AS install_build
62+
RUN cmake -S. -Bbuild
63+
RUN cmake --build build --target all -v
64+
65+
FROM install_build AS install_test
66+
RUN cmake --build build --target test -v
67+

0 commit comments

Comments
 (0)