Skip to content

Commit 544acec

Browse files
rafielantiga
authored andcommitted
Makefile: added pack and test targets (#169)
* Makefile: added pack and test targets * Added deps/readies and system-setup.py * Fixed docker functionality, fixed tests, setup changes - Added deps/readies and system-setup.py to provide standard system setup, - Docker: load all backends, - Tests: load backends upfront to avoid rdb problems, - Removed Python virtual environment setup in Makefile to avoid setup nightmares in various platforms, - Docker: build using debian:buster, then copy binaries into redis:latest. * CircleCI: refactoring * CircleCI: refactoring #2 * CircleCI: github ssh keys for git lfs * CircleCI: revert to old image * CircleCI: disabled cache restore * CircleCI: added sudo * CircleCI: fixed git lfs handling * CircleCI: try redis:5.0.5-buster image once again * CircleCI: so maybe python:3.7.4-buster * Moved Paella to Python 3, bumped version to 0.3.2 * Added getpy to readies/paella * Build fix #1 * Build fix #2 * Dockerfile sh syntax, DEBUG flag in Makefile * system-setup: added popen.communicate() * Build: better cpu/gpu separation * Docker fixes * Build fix #3 * Build fix #4 * Fixes from review, updated README * Fixes from review #2 - Restored README.md - Moved Makefile and system-setup.py to automation/ - Removed setup and show-setup from Makefile - Removed LD_LIBRARY_PATH from Makefile - Moved deps/readies into automation/ - Will provice automation/README.md in a subsequent PR - Added default value to DEVICE in CMakeLists.txt * Fixes from review #3 * Fixes from review #4 * Fixes from review #5 * Fixes from review #6 * Fixes from review #7 * CircleCI cache hacking * CircleCI cache: cancelled fallback
1 parent 1f9db0b commit 544acec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1352
-234
lines changed

.circleci/config.yml

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
version: 2
1+
version: 2.1
22
jobs:
33
build:
44
docker:
5-
- image: circleci/python:3.6.8
5+
- image: circleci/python:3.7.4-buster
66

77
steps:
88
- checkout
@@ -12,58 +12,38 @@ jobs:
1212
keys:
1313
- v1-dependencies-{{ checksum "get_deps.sh" }}
1414
# fallback to using the latest cache if no exact match is found
15-
- v1-dependencies-
15+
# - v1-dependencies-
1616

1717
- run:
1818
name: install dependencies
1919
command: |
20-
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
21-
sudo apt-get install -y git-lfs patchelf
22-
git lfs install
23-
curl -o cmake-3.12.4-Linux-x86_64.sh https://cmake.org/files/v3.12/cmake-3.12.4-Linux-x86_64.sh
24-
mkdir /home/circleci/project/cmake-bin
25-
sh cmake-3.12.4-Linux-x86_64.sh --prefix=/home/circleci/project/cmake-bin --skip-license
26-
sudo ln -s /home/circleci/project/cmake-bin/bin/cmake /usr/local/bin/cmake
27-
echo `cmake --version`
28-
rm -rf /home/circleci/project/deps
29-
bash get_deps.sh cpu
20+
sudo ./automation/readies/bin/getpy
21+
sudo ./automation/system-setup.py
22+
./get_deps.sh cpu
3023
git clone git://github.com/antirez/redis.git --branch 5.0.3
3124
(cd redis && make malloc=libc -j4 && sudo make install)
3225
3326
- save_cache:
3427
paths:
3528
- deps
36-
key: v1-dependencies-{{ checksum "get_deps.sh" }}
29+
key: v2-dependencies-{{ checksum "get_deps.sh" }}
3730

3831
- run:
3932
name: Build
4033
command: |
41-
rm -rf build
42-
mkdir build
43-
cd build
44-
cmake -DDEPS_PATH=../deps/install ..
45-
make && make install
46-
cd ..
47-
make rlec_runpath_fix
34+
make -C automation all
35+
make -C automation pack
4836
4937
- run:
5038
name: Test
51-
command: |
52-
python3 -m venv venv
53-
. venv/bin/activate
54-
pip -q uninstall -y RLTest || true
55-
pip -q install git+https://github.com/RedisLabsModules/RLTest@py3
56-
pip -q install -r test/test_requirements.txt
57-
git lfs pull
58-
python3 -m RLTest --test test/basic_tests.py --module install/redisai.so
39+
command: make -C automation test
5940

6041
- run:
6142
name: Persist Artifacts
6243
command: |
6344
mkdir -p ~/workspace/build
64-
cp install/ramp/$MODULE_ARTIFACT ~/workspace/
65-
# cp deps/install/lib/*.so* ~/workspace/
66-
cp -r install/backends ~/workspace/
45+
cp install-cpu/$MODULE_ARTIFACT ~/workspace/
46+
cp -r install-cpu/backends ~/workspace/
6747
cp ramp.yml ~/workspace/
6848
- persist_to_workspace:
6949
root: ~/workspace

.dockerignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
deps/*
2-
install/*
1+
/deps/
2+
/build/
3+
/install*/
34
**/*.o
4-
**/*.so
5+
**/*.so
6+
.venv/
7+
venv*/

.gitignore

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ __pycache__
77
*.pyc
88

99
# Dirs
10-
install/
11-
deps/
12-
build/
10+
/install*/
11+
/deps/*
12+
/build/
1313
examples/js/node_modules/
1414
examples/js/package-lock.json
15+
/test/venv/
16+
/test/logs/
17+
/1/
18+
/venv/
19+
/.venv/
1520

1621
# Eclipse (if that's your jam...)
1722
.project

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ IF (NOT DEPS_PATH)
77
# MESSAGE(FATAL_ERROR "DEPS PATH Missing!")
88
ENDIF()
99

10+
IF (NOT DEVICE)
11+
SET(DEVICE cpu)
12+
ENDIF()
13+
1014
FUNCTION(ADD_LDFLAGS _TARGET NEW_FLAGS)
1115
GET_TARGET_PROPERTY(LD_FLAGS ${_TARGET} LINK_FLAGS)
1216
IF(LD_FLAGS)
@@ -19,6 +23,8 @@ GET_FILENAME_COMPONENT(depsAbs
1923
"${DEPS_PATH}" REALPATH
2024
BASE_DIR "${CMAKE_BINARY_DIR}")
2125

26+
# SET(CUDA_TOOLKIT_ROOT_DIR /usr/local/cuda-9.0)
27+
2228
INCLUDE_DIRECTORIES(${depsAbs}/dlpack/include)
2329
INCLUDE_DIRECTORIES(${depsAbs}/libtensorflow/include)
2430
INCLUDE_DIRECTORIES(${depsAbs}/libtorch/include)
@@ -60,7 +66,7 @@ IF (APPLE)
6066
LINK_FLAGS "-undefined dynamic_lookup")
6167
ENDIF()
6268

63-
SET(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install)
69+
SET(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install-${DEVICE})
6470

6571
INSTALL(TARGETS redisai LIBRARY DESTINATION .)
6672

Dockerfile

100644100755
Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,38 @@
1-
FROM redis AS builder
1+
ARG OS=debian:buster
22

3-
ENV DEPS "build-essential git ca-certificates curl unzip wget libgomp1 patchelf"
3+
#----------------------------------------------------------------------------------------------
4+
FROM redis AS redis
5+
FROM ${OS} AS builder
46

5-
# install latest cmake
6-
ADD https://cmake.org/files/v3.12/cmake-3.12.4-Linux-x86_64.sh /cmake-3.12.4-Linux-x86_64.sh
7-
RUN mkdir /opt/cmake
8-
RUN sh /cmake-3.12.4-Linux-x86_64.sh --prefix=/opt/cmake --skip-license
9-
RUN ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
10-
RUN cmake --version
7+
WORKDIR /redisai
8+
COPY --from=redis /usr/local/ /usr/local/
119

12-
# Set up a build environment
13-
RUN set -ex;\
14-
deps="$DEPS";\
15-
apt-get update;\
16-
apt-get install -y --no-install-recommends $deps
10+
COPY ./automation/ automation/
11+
COPY ./test/test_requirements.txt test/
12+
13+
RUN ./automation/readies/bin/getpy
14+
RUN ./automation/system-setup.py
15+
16+
COPY ./get_deps.sh .
17+
RUN ./get_deps.sh cpu
1718

18-
# Get the dependencies
19-
WORKDIR /redisai
2019
ADD ./ /redisai
21-
RUN set -ex;\
22-
mkdir -p deps;\
23-
DEPS_DIRECTORY=deps bash ./get_deps.sh cpu
24-
25-
# Build the source
26-
RUN set -ex;\
27-
rm -rf build;\
28-
mkdir -p build;\
29-
cd build;\
30-
cmake -DDEPS_PATH=../deps/install ..;\
31-
make && make install;\
32-
cd ..
33-
34-
# Package the runner
20+
RUN make -C automation all
21+
22+
ARG PACK=0
23+
ARG TEST=0
24+
25+
RUN if [ "$PACK" = "1" ]; then make -C automation pack; fi
26+
RUN if [ "$TEST" = "1" ]; then make -C automation test; fi
27+
28+
#----------------------------------------------------------------------------------------------
3529
FROM redis
3630

3731
RUN set -e; apt-get -qq update; apt-get install -y libgomp1
3832

39-
RUN set -ex;\
40-
mkdir -p /usr/lib/redis/modules/;
33+
RUN mkdir -p /usr/lib/redis/modules/
4134

42-
COPY --from=builder /redisai/install/ /usr/lib/redis/modules/
35+
COPY --from=builder /redisai/install-cpu/ /usr/lib/redis/modules/
4336

4437
WORKDIR /data
4538
EXPOSE 6379

Makefile

Lines changed: 0 additions & 67 deletions
This file was deleted.

automation/Makefile

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
2+
ROOT:=..
3+
4+
override GPU:=$(or $(findstring $(CUDA),1),$(findstring $(GPU),1))
5+
6+
ifeq ($(GPU),1)
7+
ifeq ($(CPU),1)
8+
$(error CPU=1 and GPU=1 (or CUDA=1) are conflicting)
9+
endif
10+
DEPS_FLAGS=gpu
11+
DEVICE=gpu
12+
else
13+
DEPS_FLAGS=cpu
14+
DEVICE=cpu
15+
endif
16+
17+
GIT_BRANCH:=$(shell git rev-parse --abbrev-ref HEAD)
18+
GIT_COMMIT:=$(shell git describe --always --abbrev=7 --dirty="+")
19+
20+
ifeq ($(VERSION),)
21+
PACK_VER:=$(GIT_BRANCH)-$(GIT_COMMIT)
22+
else
23+
PACK_VER:=$(VERSION)
24+
endif
25+
26+
BINDIR=$(PWD)/build
27+
INSTALL_DIR=$(PWD)/install-$(DEVICE)
28+
29+
BACKENDS_PATH ?= $(INSTALL_DIR)/backends
30+
31+
RAMP:=ramp
32+
33+
ifeq ($(DEBUG),1)
34+
CMAKE_FLAGS += -DCMAKE_BUILD_TYPE=Debug
35+
endif
36+
37+
#----------------------------------------------------------------------------------------------
38+
39+
.PHONY: all setup build clean deps pack pack_ramp pack_deps test
40+
41+
all: build
42+
43+
build:
44+
ifeq ($(wildcard build/Makefile),)
45+
mkdir -p $(ROOT)/build
46+
cd $(ROOT)/build; \
47+
cmake -DDEVICE=$(DEVICE) -DDEPS_PATH=$(ROOT)/deps/install $(CMAKE_FLAGS) $(ROOT)
48+
endif
49+
$(MAKE) -C $(ROOT)/build
50+
$(MAKE) -C $(ROOT)/build install
51+
cd $(ROOT) ;\
52+
[ ! -e install ] && ln -sf install-$(DEVICE) install
53+
54+
clean:
55+
ifeq ($(ALL),1)
56+
cd $(ROOT) ;\
57+
rm -rf build install deps/dlpack deps/install-$(DEVICE) deps/*.tar.gz deps/*.zip deps/*.tgz
58+
else
59+
$(MAKE) -C $(ROOT)/build clean
60+
endif
61+
62+
deps fetch:
63+
@echo Fetching dependencies...
64+
$(ROOT)/get_deps.sh $(DEPS_FLAGS)
65+
66+
pack: pack_ramp pack_deps
67+
68+
pack_ramp:
69+
@[ ! -z `command -v redis-server` ] || { echo "Cannot find redis-server - aborting."; exit 1; }
70+
@echo "Building RAMP file ..."
71+
@set -e ;\
72+
cd $(ROOT) ;\
73+
RAMPOUT=$$(mktemp /tmp/ramp.XXXXXX) ;\
74+
$(RAMP) pack -m $(PWD)/ramp.yml -o "build/redisai.{os}-{architecture}.{semantic_version}.zip" $(INSTALL_DIR)/redisai.so 2> /dev/null | grep '.zip' > $$RAMPOUT ;\
75+
tail -1 $$RAMPOUT > $(BINDIR)/PACKAGE ;\
76+
cat $(BINDIR)/PACKAGE | sed -e "s/[^.]*\.[^.]*\.\(.*\)\.zip/\1/" > $(BINDIR)/VERSION ;\
77+
VERSION=$$(cat $(BINDIR)/VERSION) ;\
78+
$(RAMP) pack -m $(PWD)/ramp.yml -o "build/redisai.{os}-{architecture}.{semantic_version}.zip" \
79+
-c "BACKENDSPATH /opt/redislabs/lib/redisai-cpu-$$VERSION/backends" $(INSTALL_DIR)/redisai.so 2> /dev/null | grep '.zip' > $$RAMPOUT ;\
80+
rm -f $$RAMPOUT ;\
81+
echo "Done."
82+
83+
pack_deps: pack_ramp
84+
@echo "Building dependencies file ..."
85+
@set -e ;\
86+
cd $(ROOT) ;\
87+
PACK_FNAME=$$(basename `cat $(BINDIR)/PACKAGE`) ;\
88+
ARCHOSVER=$$(echo "$$PACK_FNAME" | sed -e "s/^redisai\.\([^.]*\..*\)\.zip/\1/") ;\
89+
VERSION=$$(cat $(BINDIR)/VERSION) ;\
90+
cd install-$(DEVICE) ;\
91+
rm -rf redisai-$(DEVICE)-$$VERSION ;\
92+
mkdir redisai-$(DEVICE)-$$VERSION ;\
93+
mv backends redisai-$(DEVICE)-$$VERSION ;\
94+
ln -sf redisai-$(DEVICE)-$$VERSION/backends backends ;\
95+
find redisai-$(DEVICE)-$$VERSION -name "*.so*" | xargs tar pczf redisai-$(DEVICE)-dependencies.$$ARCHOSVER.tgz ;\
96+
echo "Done."
97+
98+
test:
99+
@git lfs install
100+
@git lfs pull
101+
@set -e ;\
102+
cd $(ROOT)/test ;\
103+
python3 -m RLTest $(TEST_ARGS) --test basic_tests.py --module $(INSTALL_DIR)/redisai.so

0 commit comments

Comments
 (0)