Skip to content

Commit 43d089a

Browse files
committed
Add CMake CI
1 parent 19cac6b commit 43d089a

File tree

13 files changed

+857
-0
lines changed

13 files changed

+857
-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

.github/workflows/amd64_docker.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ref: https://github.com/docker-library/official-images
2+
name: amd64 Docker
3+
4+
on: [push, pull_request, workflow_dispatch]
5+
6+
jobs:
7+
docker:
8+
strategy:
9+
matrix:
10+
distro: [
11+
almalinux,
12+
alpine,
13+
archlinux,
14+
debian,
15+
fedora,
16+
opensuse,
17+
rockylinux,
18+
ubuntu
19+
]
20+
fail-fast: false
21+
name: amd64 • ${{ matrix.distro }}
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Check docker
26+
run: |
27+
docker info
28+
docker buildx ls
29+
- name: Build env image
30+
run: make --directory=ci amd64_${{ matrix.distro }}_env
31+
- name: Build devel project
32+
run: make --directory=ci amd64_${{ matrix.distro }}_devel
33+
- name: Build project
34+
run: make --directory=ci amd64_${{ matrix.distro }}_build
35+
- name: Test project
36+
run: make --directory=ci amd64_${{ matrix.distro }}_test
37+
38+
- name: Build install env image
39+
run: make --directory=ci amd64_${{ matrix.distro }}_install_env
40+
- name: Build install devel project
41+
run: make --directory=ci amd64_${{ matrix.distro }}_install_devel
42+
- name: Build install project
43+
run: make --directory=ci amd64_${{ matrix.distro }}_install_build
44+
- name: Test install project
45+
run: make --directory=ci amd64_${{ matrix.distro }}_install_test

ci/Makefile

+252
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
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] [VERBOSE=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 "\tBuild using docker and the host platform."
21+
@echo -e "\t${BOLD}<distro>_<stage>${RESET}: build a <stage> docker image for a specific distro."
22+
@echo -e "\t${BOLD}save_<distro>_<stage>${RESET}: Save a <stage> docker image for a specific distro."
23+
@echo -e "\t${BOLD}sh_<distro>_<stage>${RESET}: run a container using the <stage> docker image specified (debug purpose)."
24+
@echo -e "\t${BOLD}clean_<distro>_<stage>${RESET}: Remove a <stage> docker image for a specific distro."
25+
@echo -e "\t${BOLD}clean_native${RESET}: Remove ALL caches and docker images."
26+
@echo
27+
@echo -e "\tWith ${BOLD}<distro>${RESET}:"
28+
@echo -e "\t\t${BOLD}almalinux${RESET} (latest)"
29+
@echo -e "\t\t${BOLD}alpine${RESET} (edge)"
30+
@echo -e "\t\t${BOLD}archlinux${RESET} (latest)"
31+
@echo -e "\t\t${BOLD}debian${RESET} (latest)"
32+
@echo -e "\t\t${BOLD}fedora${RESET} (latest)"
33+
@echo -e "\t\t${BOLD}opensuse${RESET} (tumbleweed)"
34+
@echo -e "\t\t${BOLD}rockylinux${RESET} (9)"
35+
@echo -e "\t\t${BOLD}ubuntu${RESET} (latest)"
36+
@echo -e "\t\t${BOLD}all${RESET}: trigger ALL DISTROS."
37+
@echo
38+
@echo -e "\tWith ${BOLD}<stage>${RESET}:"
39+
@echo -e "\t\t${BOLD}env${RESET}"
40+
@echo -e "\t\t${BOLD}devel${RESET}"
41+
@echo -e "\t\t${BOLD}build${RESET}"
42+
@echo -e "\t\t${BOLD}test${RESET}"
43+
@echo -e "\t\t${BOLD}install_env${RESET}"
44+
@echo -e "\t\t${BOLD}install_devel${RESET}"
45+
@echo -e "\t\t${BOLD}install_build${RESET}"
46+
@echo -e "\t\t${BOLD}install_test${RESET}"
47+
@echo -e "\te.g. 'make ubuntu_test'"
48+
@echo
49+
@echo -e "\tBuild using docker buildx with a platform specified."
50+
@echo -e "\t${BOLD}<platform>_<stage>${RESET}: build <stage> docker images for ALL DISTROS."
51+
@echo -e "\t${BOLD}<platform>_<distro>_<stage>${RESET}: build <stage> docker image for a specific distro."
52+
@echo -e "\t${BOLD}save_<platform>_<stage>${RESET}: Save <stage> docker images for ALL DISTROS."
53+
@echo -e "\t${BOLD}save_<platform>_<distro>_<stage>${RESET}: Save the <stage> docker image for a specific distro."
54+
@echo -e "\t${BOLD}sh_<platform>_<distro>_<stage>${RESET}: run a container using the <stage> docker image specified (debug purpose)."
55+
@echo -e "\t${BOLD}clean_<platform>_<distro>_<stage>${RESET}: Remove cache and docker image."
56+
@echo -e "\t${BOLD}clean_platforms${RESET}: Remove ALL cache and docker image."
57+
@echo
58+
@echo -e "\tWith ${BOLD}<platform>${RESET}:"
59+
@echo -e "\t\t${BOLD}amd64${RESET}: linux/amd64 (x86_64)"
60+
@echo -e "\t\t${BOLD}386${RESET}: linux/386 (x86)"
61+
@echo -e "\t\t${BOLD}arm${RESET}: linux/arm (armv7)"
62+
@echo -e "\t\t${BOLD}arm64${RESET}: linux/arm64 (aarch64, arm64v8)"
63+
@echo -e "\t\t${BOLD}mips${RESET}: linux/mips (mips 32bits)"
64+
@echo -e "\t\t${BOLD}mipsle${RESET}: linux/mipsle (mips 32bits Little Endian)"
65+
@echo -e "\t\t${BOLD}mips64${RESET}: linux/mips64 (mips 64bits)"
66+
@echo -e "\t\t${BOLD}mips64le${RESET}: linux/mips64le (mips 64bits Little Endian)"
67+
@echo -e "\t\t${BOLD}ppc64${RESET}: linux/ppc64 (PowerPC 64Bits)"
68+
@echo -e "\t\t${BOLD}ppc64le${RESET}: linux/ppc64le (PowerPC 64Bits Little Endian)"
69+
@echo -e "\t\t${BOLD}riscv64${RESET}: linux/riscv64 (RISC-V 64bits)"
70+
@echo -e "\t\t${BOLD}s390x${RESET}: linux/s390x (IBM System/390x)"
71+
@echo -e "\te.g. 'make amd64_ubuntu_test'"
72+
@echo -e "\tDocker image unavailable: arm64_archlinux"
73+
@echo
74+
@echo -e "\tGlobal targets."
75+
@echo -e "\t${BOLD}clean${RESET}: Remove ALL caches and docker images."
76+
@echo -e "\t${BOLD}distclean${RESET}: Remove everything."
77+
@echo
78+
@echo -e "\t${BOLD}NOCACHE=1${RESET}: use 'docker build --no-cache' when building container (default use cache)."
79+
@echo -e "\t${BOLD}VERBOSE=1${RESET}: use 'docker build --progress=plain' when building container."
80+
@echo
81+
@echo -e "branch: $(BRANCH)"
82+
@echo -e "sha1: $(SHA1)"
83+
84+
# Need to add cmd_distro to PHONY otherwise target are ignored since they do not
85+
# contain recipe (using FORCE do not work here)
86+
.PHONY: all
87+
all: all_test
88+
89+
# Delete all implicit rules to speed up makefile
90+
MAKEFLAGS += --no-builtin-rules
91+
.SUFFIXES:
92+
# Remove some rules from gmake that .SUFFIXES does not remove.
93+
SUFFIXES :=
94+
# Keep all intermediate files
95+
# ToDo: try to remove it later
96+
.SECONDARY:
97+
98+
# Docker image name prefix.
99+
IMAGE := ${PROJECT}
100+
101+
DOCKER_BUILD_CMD := docker build
102+
DOCKER_BUILDX_CMD := docker buildx build
103+
ifdef NOCACHE
104+
DOCKER_BUILD_CMD := ${DOCKER_BUILD_CMD} --no-cache
105+
DOCKER_BUILDX_CMD := ${DOCKER_BUILDX_CMD} --no-cache
106+
endif
107+
ifdef VERBOSE
108+
DOCKER_BUILD_CMD := ${DOCKER_BUILD_CMD} --progress=plain
109+
DOCKER_BUILDX_CMD := ${DOCKER_BUILDX_CMD} --progress=plain
110+
endif
111+
DOCKER_RUN_CMD := docker run --rm --init --net=host
112+
113+
# Currently supported distro
114+
DISTROS := \
115+
almalinux \
116+
alpine \
117+
archlinux \
118+
debian \
119+
fedora \
120+
opensuse \
121+
rockylinux \
122+
ubuntu
123+
124+
# $* stem
125+
# $< first prerequist
126+
# $@ target name
127+
128+
############
129+
## STAGES ##
130+
############
131+
STAGES := env devel build test install_env install_devel install_build install_test
132+
133+
define make-stage-target =
134+
#$$(info STAGE: $1)
135+
#$$(info Create targets: all_$1 $(addsuffix _$1, $(DISTROS)).)
136+
targets_$1 := $(addsuffix _$1, $(DISTROS))
137+
.PHONY: all_$1 $$(targets_$1)
138+
all_$1: $$(targets_$1)
139+
$$(targets_$1): %_$1: docker/%/Dockerfile
140+
#@docker image rm -f ${IMAGE}:$$*_$1 2>/dev/null
141+
${DOCKER_BUILD_CMD} --target=$1 --tag ${IMAGE}:$$*_$1 -f $$< ..
142+
143+
#$$(info Create targets: save_all_$1 $(addprefix save_, $(addsuffix _$1, $(DISTROS))) (debug).)
144+
save_targets_$1 := $(addprefix save_, $(addsuffix _$1, $(DISTROS)))
145+
.PHONY: save_all_$1 $$(save_targets_$1)
146+
save_all_$1: $$(save_targets_$1)
147+
$$(save_targets_$1): save_%_$1: cache/%/docker_$1.tar
148+
cache/%/docker_$1.tar: %_$1
149+
@rm -f $$@
150+
mkdir -p cache/$$*
151+
docker save ${IMAGE}:$$*_$1 -o $$@
152+
153+
#$$(info Create targets: $(addprefix sh_, $(addsuffix _$1, $(DISTROS))) (debug).)
154+
sh_targets_$1 := $(addprefix sh_, $(addsuffix _$1, $(DISTROS)))
155+
.PHONY: $$(sh_targets_$1)
156+
$$(sh_targets_$1): sh_%_$1: %_$1
157+
${DOCKER_RUN_CMD} -it --name ${IMAGE}_$$*_$1 ${IMAGE}:$$*_$1
158+
159+
#$$(info Create targets: clean_all_$1 $(addprefix clean_, $(addsuffix _$1, $(DISTROS))).)
160+
clean_targets_$1 := $(addprefix clean_, $(addsuffix _$1, $(DISTROS)))
161+
.PHONY: clean_all_$1 $$(clean_targets_$1)
162+
clean_all_$1: $$(clean_targets_$1)
163+
$$(clean_targets_$1): clean_%_$1:
164+
docker image rm -f ${IMAGE}:$$*_$1 2>/dev/null
165+
rm -f cache/$$*/docker_$1.tar
166+
endef
167+
168+
$(foreach stage,$(STAGES),$(eval $(call make-stage-target,$(stage))))
169+
170+
## MERGE ##
171+
.PHONY: clean_all
172+
clean_all: $(addprefix clean_all_, $(STAGES))
173+
rm -f $(addprefix cache/, $(DISTROS))
174+
175+
##############
176+
## PLATFORM ##
177+
##############
178+
# ref: https://go.dev/doc/install/source#environment
179+
# ref: https://github.com/containerd/containerd/blob/269548fa27e0089a8b8278fc4fc781d7f65a939b/platforms/platforms.go#L80-L94
180+
PLATFORMS := \
181+
386 amd64 \
182+
arm arm64 \
183+
mips mipsle mips64 mips64le \
184+
ppc64 ppc64le \
185+
riscv64 \
186+
s390x
187+
188+
define make-platform-stage-target =
189+
#$$(info PLATFORM: '$1' STAGE: '$2')
190+
#$$(info Create targets: $1_all_$2 $(addprefix $1_, $(addsuffix _$2, $(DISTROS))).)
191+
targets_$1_$2 := $(addprefix $1_, $(addsuffix _$2, $(DISTROS)))
192+
.PHONY: $1_all_$2 $$(targets_$1_$2)
193+
$1_all_$2: $$(targets_$1_$2)
194+
$$(targets_$1_$2): $1_%_$2: docker/%/Dockerfile
195+
#@docker image rm -f ${IMAGE}:$1_$$*_$2 2>/dev/null
196+
${DOCKER_BUILDX_CMD} --platform linux/$1 --target=$2 --tag ${IMAGE}:$1_$$*_$2 -f $$< ..
197+
198+
#$$(info Create save targets: save_$1_all_$2 $(addprefix save_$1_, $(addsuffix _$2, $(DISTROS))) (debug).)
199+
save_targets_$1_$2 := $(addprefix save_$1_, $(addsuffix _$2, $(DISTROS)))
200+
.PHONY: save_$1_all_$2 $$(save_targets_$1_$2)
201+
save_$1_all_$2: $$(save_targets_$1_$2)
202+
$$(save_targets_$1_$2): save_$1_%_$2: cache/$1/%/docker_$2.tar
203+
cache/$1/%/docker_$2.tar: $1_%_$2
204+
@rm -f $$@
205+
mkdir -p cache/$1/$$*
206+
docker save ${IMAGE}:$1_$$*_$2 -o $$@
207+
208+
#$$(info Create sh targets: $(addprefix sh_$1_, $(addsuffix _$2, $(DISTROS))) (debug).)
209+
sh_targets_$1_$2 := $(addprefix sh_$1_, $(addsuffix _$2, $(DISTROS)))
210+
.PHONY: $$(sh_targets_$1_$2)
211+
$$(sh_targets_$1_$2): sh_$1_%_$2: $1_%_$2
212+
${DOCKER_RUN_CMD} --platform linux/$1 -it --name ${IMAGE}_$1_$$*_$2 ${IMAGE}:$1_$$*_$2
213+
214+
#$$(info Create targets: clean_$1_all_$2 $(addprefix clean_$1_, $(addsuffix _$2, $(DISTROS))).)
215+
clean_targets_$1_$2 := $(addprefix clean_$1_, $(addsuffix _$2, $(DISTROS)))
216+
.PHONY: clean_$1_all_$2 $$(clean_targets_$1_$2)
217+
clean_$1_all_$2: $$(clean_targets_$1_$2)
218+
$$(clean_targets_$1_$2): clean_$1_%_$2:
219+
docker image rm -f ${IMAGE}:$1_$$*_$2 2>/dev/null
220+
rm -f cache/$1/$$*/docker_$2.tar
221+
endef
222+
223+
define make-platform-target =
224+
#$$(info PLATFORM: $1)
225+
$(foreach stage,$(STAGES),$(eval $(call make-platform-stage-target,$1,$(stage))))
226+
227+
# merge
228+
.PHONY: clean_$1
229+
clean_$1: $(addprefix clean_$1_all_, $(STAGES))
230+
-rmdir $(addprefix cache/$1/, $(DISTROS))
231+
-rmdir cache/$1
232+
endef
233+
234+
$(foreach platform,$(PLATFORMS),$(eval $(call make-platform-target,$(platform))))
235+
236+
## MERGE ##
237+
.PHONY: clean_platforms
238+
clean_platforms: $(addprefix clean_, $(PLATFORMS))
239+
240+
###########
241+
## CLEAN ##
242+
###########
243+
.PHONY: clean
244+
clean: clean_all clean_platforms
245+
docker container prune -f
246+
docker image prune -f
247+
-rmdir cache
248+
249+
.PHONY: distclean
250+
distclean: clean
251+
-docker container rm -f $$(docker container ls -aq)
252+
-docker image rm -f $$(docker image ls -aq)

ci/docker/almalinux/Dockerfile

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

0 commit comments

Comments
 (0)