Skip to content

Commit 2db9bc5

Browse files
committed
Add ci
1 parent b3ced54 commit 2db9bc5

File tree

11 files changed

+684
-0
lines changed

11 files changed

+684
-0
lines changed

.ci/Makefile

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
PROJECT := cbc
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}env${RESET}: build a virtual env image."
21+
@echo -e "\t${BOLD}sh_env_<distro>${RESET}: run a container using the virtual env image (debug purpose)."
22+
@echo
23+
@echo -e "\t${BOLD}devel${RESET}: build the library using all devel images."
24+
@echo -e "\t${BOLD}devel_<distro>${RESET}: build the library using a specific devel image."
25+
@echo -e "\t${BOLD}test_<distro>${RESET}: auto test using the devel image."
26+
@echo -e "\t${BOLD}sh_<distro>${RESET}: run a container using the devel image (debug purpose)."
27+
@echo
28+
@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."
29+
@echo -e "\t${BOLD}install_<distro>${RESET}: execute the cmake target ${BOLD}install${RESET} using the devel image container specified, then create an install image with it."
30+
@echo -e "\t${BOLD}test_install${RESET}: configure, build, install then test a sample project against it using all ${BOLD}install${RESET} image containers."
31+
@echo -e "\t${BOLD}test_install_<distro>${RESET}: configure, build, install then test a sample project against it using the ${BOLD}install${RESET} image container specified."
32+
@echo -e "\t${BOLD}sh_install_<distro>${RESET}: run a container using the install image (debug purpose)."
33+
@echo
34+
@echo -e "\t${BOLD}clean${RESET}: Remove cache and docker image."
35+
@echo -e "\t${BOLD}clean_<distro>${RESET}: Remove cache and docker image for the specified distro."
36+
@echo
37+
@echo -e "\t${BOLD}<distro>${RESET}:"
38+
@echo -e "\t\t${BOLD}alpine${RESET} (latest)"
39+
@echo -e "\t\t${BOLD}archlinux${RESET} (latest)"
40+
@echo -e "\t\t${BOLD}centos${RESET} (latest)"
41+
@echo -e "\t\t${BOLD}fedora${RESET} (latest)"
42+
@echo -e "\t\t${BOLD}opensuse${RESET} (tumbleweed)"
43+
@echo -e "\t\t${BOLD}debian${RESET} (latest)"
44+
@echo -e "\t\t${BOLD}ubuntu${RESET} (latest)"
45+
@echo -e "\te.g. 'make test_ubuntu'"
46+
@echo
47+
@echo -e "\t${BOLD}NOCACHE=1${RESET}: use 'docker build --no-cache' when building container (default use cache)."
48+
@echo
49+
@echo -e "branch: $(BRANCH)"
50+
@echo -e "sha1: $(SHA1)"
51+
52+
# Need to add cmd_distro to PHONY otherwise target are ignored since they do not
53+
# contain recipe (using FORCE do not work here)
54+
.PHONY: all
55+
all: devel
56+
57+
# Delete all implicit rules to speed up makefile
58+
MAKEFLAGS += --no-builtin-rules
59+
.SUFFIXES:
60+
# Remove some rules from gmake that .SUFFIXES does not remove.
61+
SUFFIXES =
62+
# Keep all intermediate files
63+
# ToDo: try to remove it later
64+
.SECONDARY:
65+
66+
# Docker image name prefix.
67+
IMAGE := ${PROJECT}
68+
69+
ifdef NOCACHE
70+
DOCKER_BUILD_CMD := docker build --no-cache
71+
else
72+
DOCKER_BUILD_CMD := docker build
73+
endif
74+
75+
DOCKER_RUN_CMD := docker run --rm --init --net=host
76+
77+
# Currently supported distro
78+
DISTROS = alpine archlinux centos fedora opensuse debian ubuntu
79+
80+
# $* stem
81+
# $< first prerequist
82+
# $@ target name
83+
84+
# ENV
85+
targets = $(addprefix env_, $(DISTROS))
86+
.PHONY: env $(targets)
87+
env: $(targets)
88+
$(targets): env_%: cache/%/docker_env.tar
89+
cache/%/docker_env.tar: docker/%/Dockerfile
90+
@docker image rm -f ${IMAGE}_$*:env 2>/dev/null
91+
${DOCKER_BUILD_CMD} --target=env --tag ${IMAGE}_$*:env -f $< docker/$*
92+
@rm -f $@
93+
mkdir -p cache/$*
94+
docker save ${IMAGE}_$*:env -o $@
95+
96+
# Run a container using the env image.
97+
targets = $(addprefix sh_env_, $(DISTROS))
98+
.PHONY: $(targets)
99+
$(targets): sh_env_%: cache/%/docker_env.tar
100+
${DOCKER_RUN_CMD} -it --name ${IMAGE}_$* ${IMAGE}_$*:env /bin/sh
101+
102+
# DEVEL
103+
targets = $(addprefix devel_, $(DISTROS))
104+
.PHONY: devel $(targets)
105+
devel: $(targets)
106+
$(targets): devel_%: cache/%/docker_devel.tar
107+
cache/%/docker_devel.tar: docker/%/Dockerfile \
108+
../CMakeLists.txt ../cmake \
109+
../src
110+
@docker image rm -f ${IMAGE}_$*:devel 2>/dev/null
111+
${DOCKER_BUILD_CMD} --target=devel --tag ${IMAGE}_$*:devel -f $< ..
112+
@rm -f $@
113+
mkdir -p cache/$*
114+
docker save ${IMAGE}_$*:devel -o $@
115+
116+
# DOCKER BASH INSTALL (debug)
117+
targets = $(addprefix sh_devel_, $(DISTROS))
118+
.PHONY: $(targets)
119+
$(targets): sh_devel_%: cache/%/docker_devel.tar
120+
${DOCKER_RUN_CMD} -it --name ${IMAGE}_$* ${IMAGE}_$*:devel /bin/sh
121+
122+
# TEST DEVEL
123+
targets = $(addprefix test_, $(DISTROS))
124+
.PHONY: test $(targets)
125+
test: $(targets)
126+
$(targets): test_%: cache/%/docker_devel.tar
127+
${DOCKER_RUN_CMD} -t --name ${IMAGE}_$* ${IMAGE}_$*:devel cmake --build build --target test
128+
129+
# INSTALL
130+
targets = $(addprefix install_, $(DISTROS))
131+
.PHONY: install $(targets)
132+
install: $(targets)
133+
$(targets): install_%: cache/%/docker_install.tar
134+
cache/%/docker_install.tar: docker/%/Dockerfile \
135+
sample
136+
@docker image rm -f ${IMAGE}_$*:install 2>/dev/null
137+
${DOCKER_BUILD_CMD} --target=install --tag ${IMAGE}_$*:install -f $< ..
138+
@rm -f $@
139+
mkdir -p cache/$*
140+
docker save ${IMAGE}_$*:install -o $@
141+
142+
# DOCKER BASH INSTALL (debug)
143+
targets = $(addprefix sh_install_, $(DISTROS))
144+
.PHONY: $(targets)
145+
$(targets): sh_install_%: cache/%/docker_install.tar
146+
${DOCKER_RUN_CMD} -it --name ${IMAGE}_$* ${IMAGE}_$*:install /bin/sh
147+
148+
# TEST INSTALL
149+
targets = $(addprefix test_install_, $(DISTROS))
150+
.PHONY: test_install $(targets)
151+
test_install: $(targets)
152+
$(targets): test_install_%: cache/%/docker_install.tar sample
153+
@docker load -i cache/$*/docker_install.tar
154+
${DOCKER_RUN_CMD} -t --name ${IMAGE}_$* ${IMAGE}_$*:install /bin/sh -c \
155+
"cmake -H. -Bbuild; \
156+
cmake --build build --target all; \
157+
cmake --build build --target test; \
158+
cmake --build build --target install"
159+
160+
# CLEAN
161+
targets = $(addprefix clean_, $(DISTROS))
162+
.PHONY: clean $(targets)
163+
clean: $(targets)
164+
-rmdir cache
165+
$(targets): clean_%:
166+
docker container prune -f
167+
docker image prune -f
168+
-docker image rm -f ${IMAGE}_$*:install 2>/dev/null
169+
-docker image rm -f ${IMAGE}_$*:devel 2>/dev/null
170+
-docker image rm -f ${IMAGE}_$*:env 2>/dev/null
171+
-rm -f cache/$*/docker_install.tar
172+
-rm -f cache/$*/docker_devel.tar
173+
-rm -f cache/$*/docker_env.tar
174+
-rmdir cache/$*
175+
176+
.PHONY: distclean
177+
distclean: clean
178+
-docker container rm -f $$(docker container ls -aq)
179+
-docker image rm -f $$(docker image ls -aq)

.ci/docker/alpine/Dockerfile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 libexecinfo-dev cmake
8+
9+
RUN cd /tmp \
10+
&& git clone https://github.com/Mizux/CoinUtils.git \
11+
&& cd CoinUtils \
12+
&& cmake -H. -Bbuild \
13+
&& cmake --build build --target install \
14+
&& cd .. \
15+
&& rm -rf CoinUtils
16+
17+
RUN cd /tmp \
18+
&& git clone https://github.com/Mizux/Osi.git \
19+
&& cd Osi \
20+
&& cmake -H. -Bbuild \
21+
&& cmake --build build --target install \
22+
&& cd .. \
23+
&& rm -rf Osi
24+
25+
RUN cd /tmp \
26+
&& git clone https://github.com/Mizux/Clp.git \
27+
&& cd Clp \
28+
&& cmake -H. -Bbuild \
29+
&& cmake --build build --target install \
30+
&& cd .. \
31+
&& rm -rf Clp
32+
33+
RUN cd /tmp \
34+
&& git clone https://github.com/Mizux/Cgl.git \
35+
&& cd Cgl \
36+
&& cmake -H. -Bbuild \
37+
&& cmake --build build --target install \
38+
&& cd .. \
39+
&& rm -rf Cgl
40+
41+
CMD [ "/bin/sh" ]
42+
43+
# Add the library src to our build env
44+
FROM env AS devel
45+
# Create lib directory
46+
WORKDIR /home/lib
47+
# Bundle lib source
48+
COPY . .
49+
# CMake configure
50+
RUN cmake -S. -Bbuild
51+
# CMake build
52+
RUN cmake --build build --target all -v
53+
# CMake build
54+
RUN cmake --build build --target install
55+
56+
# Create an install image
57+
FROM env AS install
58+
# Copy lib from devel to prod
59+
COPY --from=devel /usr/local /usr/local/
60+
# Copy sample
61+
WORKDIR /home/sample
62+
COPY .ci/sample .

.ci/docker/archlinux/Dockerfile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Create a virtual environment with all tools installed
2+
# ref: https://hub.docker.com/_/archlinux/
3+
FROM archlinux/base 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+
RUN cd /tmp \
10+
&& git clone https://github.com/Mizux/CoinUtils.git \
11+
&& cd CoinUtils \
12+
&& cmake -H. -Bbuild \
13+
&& cmake --build build --target install \
14+
&& cd .. \
15+
&& rm -rf CoinUtils
16+
17+
RUN cd /tmp \
18+
&& git clone https://github.com/Mizux/Osi.git \
19+
&& cd Osi \
20+
&& cmake -H. -Bbuild \
21+
&& cmake --build build --target install \
22+
&& cd .. \
23+
&& rm -rf Osi
24+
25+
RUN cd /tmp \
26+
&& git clone https://github.com/Mizux/Clp.git \
27+
&& cd Clp \
28+
&& cmake -H. -Bbuild \
29+
&& cmake --build build --target install \
30+
&& cd .. \
31+
&& rm -rf Clp
32+
33+
RUN cd /tmp \
34+
&& git clone https://github.com/Mizux/Cgl.git \
35+
&& cd Cgl \
36+
&& cmake -H. -Bbuild \
37+
&& cmake --build build --target install \
38+
&& cd .. \
39+
&& rm -rf Cgl
40+
41+
CMD [ "/bin/sh" ]
42+
43+
# Add the library src to our build env
44+
FROM env AS devel
45+
# Create lib directory
46+
WORKDIR /home/lib
47+
# Bundle lib source
48+
COPY . .
49+
# CMake configure
50+
RUN cmake -S. -Bbuild
51+
# CMake build
52+
RUN cmake --build build --target all -v
53+
# CMake build
54+
RUN cmake --build build --target install
55+
56+
# Create an install image
57+
FROM env AS install
58+
# Copy lib from devel to prod
59+
COPY --from=devel /usr/local /usr/local/
60+
# Copy sample
61+
WORKDIR /home/sample
62+
COPY .ci/sample .

.ci/docker/centos/Dockerfile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
RUN cd /tmp \
16+
&& git clone https://github.com/Mizux/CoinUtils.git \
17+
&& cd CoinUtils \
18+
&& cmake -H. -Bbuild \
19+
&& cmake --build build --target install \
20+
&& cd .. \
21+
&& rm -rf CoinUtils
22+
23+
RUN cd /tmp \
24+
&& git clone https://github.com/Mizux/Osi.git \
25+
&& cd Osi \
26+
&& cmake -H. -Bbuild \
27+
&& cmake --build build --target install \
28+
&& cd .. \
29+
&& rm -rf Osi
30+
31+
RUN cd /tmp \
32+
&& git clone https://github.com/Mizux/Clp.git \
33+
&& cd Clp \
34+
&& cmake -H. -Bbuild \
35+
&& cmake --build build --target install \
36+
&& cd .. \
37+
&& rm -rf Clp
38+
39+
RUN cd /tmp \
40+
&& git clone https://github.com/Mizux/Cgl.git \
41+
&& cd Cgl \
42+
&& cmake -H. -Bbuild \
43+
&& cmake --build build --target install \
44+
&& cd .. \
45+
&& rm -rf Cgl
46+
47+
CMD [ "/bin/sh" ]
48+
49+
# Add the library src to our build env
50+
FROM env AS devel
51+
# Create lib directory
52+
WORKDIR /home/lib
53+
# Bundle lib source
54+
COPY . .
55+
# CMake configure
56+
RUN cmake -H. -Bbuild
57+
# CMake build
58+
RUN cmake --build build --target all
59+
# CMake build
60+
RUN cmake --build build --target install
61+
62+
# Create an install image
63+
FROM env AS install
64+
# Copy lib from devel to prod
65+
COPY --from=devel /usr/local /usr/local/
66+
# Copy sample
67+
WORKDIR /home/sample
68+
COPY .ci/sample .

0 commit comments

Comments
 (0)