Skip to content

Commit f181b61

Browse files
committed
Add CMake CI
- Based on Docker for environment and Make for orchestration
1 parent e9c9cf7 commit f181b61

File tree

11 files changed

+469
-0
lines changed

11 files changed

+469
-0
lines changed

.dockerignore

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

ci/Makefile

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
PROJECT := coinutils
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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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="[email protected]"
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+
# Add the library src to our build env
10+
FROM env AS devel
11+
WORKDIR /home/project
12+
COPY . .
13+
14+
FROM devel AS build
15+
RUN cmake --version
16+
RUN cmake -S. -Bbuild
17+
RUN cmake --build build --target all -v
18+
RUN cmake --build build --target install -v
19+
20+
FROM build AS test
21+
RUN cmake --build build --target test -v
22+
23+
# Test install rules
24+
FROM env AS install_env
25+
COPY --from=build /usr/local /usr/local/
26+
27+
FROM install_env AS install_devel
28+
WORKDIR /home/sample
29+
COPY ci/sample .
30+
31+
FROM install_devel AS install_build
32+
RUN cmake -S. -Bbuild
33+
RUN cmake --build build --target all -v
34+
35+
FROM install_build AS install_test
36+
RUN cmake --build build --target test -v
37+

ci/docker/archlinux/Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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="[email protected]"
5+
# Install system build dependencies
6+
ENV PATH=$PATH:/usr/local/bin
7+
RUN pacman -Syu --noconfirm base-devel git cmake
8+
9+
# Add the library src to our build env
10+
FROM env AS devel
11+
WORKDIR /home/project
12+
COPY . .
13+
14+
FROM devel AS build
15+
RUN cmake --version
16+
RUN cmake -S. -Bbuild
17+
RUN cmake --build build --target all -v
18+
RUN cmake --build build --target install -v
19+
20+
FROM build AS test
21+
RUN cmake --build build --target test -v
22+
23+
# Test install rules
24+
FROM env AS install_env
25+
COPY --from=build /usr/local /usr/local/
26+
27+
FROM install_env AS install_devel
28+
WORKDIR /home/sample
29+
COPY ci/sample .
30+
31+
FROM install_devel AS install_build
32+
RUN cmake -S. -Bbuild
33+
RUN cmake --build build --target all -v
34+
35+
FROM install_build AS install_test
36+
RUN cmake --build build --target test -v
37+

ci/docker/centos/Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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="[email protected]"
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+
# Add the library src to our build env
16+
FROM env AS devel
17+
WORKDIR /home/project
18+
COPY . .
19+
20+
FROM devel AS build
21+
RUN cmake --version
22+
RUN cmake -S. -Bbuild
23+
RUN cmake --build build --target all -v
24+
RUN cmake --build build --target install -v
25+
26+
FROM build AS test
27+
RUN cmake --build build --target test -v
28+
29+
# Test install rules
30+
FROM env AS install_env
31+
COPY --from=build /usr/local /usr/local/
32+
33+
FROM install_env AS install_devel
34+
WORKDIR /home/sample
35+
COPY ci/sample .
36+
37+
FROM install_devel AS install_build
38+
RUN cmake -S. -Bbuild
39+
RUN cmake --build build --target all -v
40+
41+
FROM install_build AS install_test
42+
RUN cmake --build build --target test -v
43+

ci/docker/debian/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Create a virtual environment with all tools installed
2+
# ref: https://hub.docker.com/_/debian
3+
FROM debian:latest AS env
4+
LABEL maintainer="[email protected]"
5+
# Install system build dependencies
6+
ENV PATH=$PATH:/usr/local/bin
7+
RUN apt-get update -q \
8+
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq git build-essential cmake \
9+
&& apt-get clean \
10+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
11+
12+
# Add the library src to our build env
13+
FROM env AS devel
14+
WORKDIR /home/project
15+
COPY . .
16+
17+
FROM devel AS build
18+
RUN cmake --version
19+
RUN cmake -S. -Bbuild
20+
RUN cmake --build build --target all -v
21+
RUN cmake --build build --target install -v
22+
23+
FROM build AS test
24+
RUN cmake --build build --target test -v
25+
26+
# Test install rules
27+
FROM env AS install_env
28+
COPY --from=build /usr/local /usr/local/
29+
30+
FROM install_env AS install_devel
31+
WORKDIR /home/sample
32+
COPY ci/sample .
33+
34+
FROM install_devel AS install_build
35+
RUN cmake -S. -Bbuild
36+
RUN cmake --build build --target all -v
37+
38+
FROM install_build AS install_test
39+
RUN cmake --build build --target test -v
40+

ci/docker/fedora/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Create a virtual environment with all tools installed
2+
# ref: https://hub.docker.com/_/fedora
3+
FROM fedora:latest AS env
4+
LABEL maintainer="[email protected]"
5+
# Install system build dependencies
6+
ENV PATH=$PATH:/usr/local/bin
7+
RUN dnf -y update \
8+
&& dnf -y groupinstall "Development Tools" \
9+
&& dnf -y install cmake gcc-c++ \
10+
&& dnf clean all
11+
12+
# Add the library src to our build env
13+
FROM env AS devel
14+
WORKDIR /home/project
15+
COPY . .
16+
17+
FROM devel AS build
18+
RUN cmake --version
19+
RUN cmake -S. -Bbuild
20+
RUN cmake --build build --target all -v
21+
RUN cmake --build build --target install -v
22+
23+
FROM build AS test
24+
RUN cmake --build build --target test -v
25+
26+
# Test install rules
27+
FROM env AS install_env
28+
COPY --from=build /usr/local /usr/local/
29+
30+
FROM install_env AS install_devel
31+
WORKDIR /home/sample
32+
COPY ci/sample .
33+
34+
FROM install_devel AS install_build
35+
RUN cmake -S. -Bbuild
36+
RUN cmake --build build --target all -v
37+
38+
FROM install_build AS install_test
39+
RUN cmake --build build --target test -v
40+

0 commit comments

Comments
 (0)