From 6aad71c4c1adda56f3b200c5a7cae3e8ec7788ee Mon Sep 17 00:00:00 2001 From: weedge Date: Thu, 7 Sep 2023 03:41:20 +0800 Subject: [PATCH] updt: fix dockerfile && add docker build img run for diff redis stable version to makefile Signed-off-by: weedge --- Dockerfile | 32 +++++++++++--------- Makefile | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++- README.md | 25 ++++++++++++++-- 3 files changed, 128 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 27615a2..8a834c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,24 @@ -# docker build arg -ARG REDISXSLOT_ARGS="1024 0 async" -ARG REDIS_IMG_TAG=latest - +# https://vsupalov.com/docker-arg-env-variable-guide/ +# docker build arg to all FROM +ARG A_REDIS_IMG_TAG=latest # dockerhub img https://hub.docker.com/_/redis # https://github.com/docker-library/redis -FROM redis:${REDIS_IMG_TAG} +FROM redis:${A_REDIS_IMG_TAG} # docker img meta LABEL redisxslot.image.authors="weedge" +# docker build arg after each FROM +ARG A_REDISXSLOT_ARGS="1024 0 async" +ARG A_REDIS_SERVER_PORT=6379 + # container env -ENV REDISXSLOT_URL https://github.com/weedge/redisxslot.git -ENV REDIS_IMG_TAG ${REDIS_IMG_TAG} -ENV REDISXSLOT_ARGS ${REDISXSLOT_ARGS} +ENV E_REDISXSLOT_URL=https://github.com/weedge/redisxslot.git +ENV E_REDISXSLOT_ARGS=${A_REDISXSLOT_ARGS} +ENV E_REDIS_SERVER_PORT=${A_REDIS_SERVER_PORT} -# prepare layer +# build prepare layer, use arg/env RUN set -eux; \ \ apt-get update; \ @@ -39,7 +42,7 @@ RUN set -eux; \ cp /usr/src/redis/redis.conf /usr/local/etc/redis/; \ rm redis.tar.gz; \ \ - git clone ${REDISXSLOT_URL} /usr/src/redisxslot; \ + git clone ${E_REDISXSLOT_URL} /usr/src/redisxslot; \ make -C /usr/src/redisxslot RM_INCLUDE_DIR=/usr/src/redis/src BUILD_TYPE=Release; \ mv /usr/src/redisxslot/redisxslot.so /usr/local/lib/redisxslot_module.so; \ \ @@ -50,11 +53,12 @@ RUN set -eux; \ # Custom cache invalidation ARG CACHEBUST=1 -# config layer -RUN sed -i '1i loadmodule /usr/local/lib/redisxslot_module.so ${REDISXSLOT_ARGS}' /usr/local/etc/redis/redis.conf; \ +# build config layer, use arg/env +RUN sed -i "1i loadmodule /usr/local/lib/redisxslot_module.so ${E_REDISXSLOT_ARGS}" /usr/local/etc/redis/redis.conf; \ chmod 644 /usr/local/etc/redis/redis.conf; \ sed -i 's/^bind 127.0.0.1/#bind 127.0.0.1/g' /usr/local/etc/redis/redis.conf; \ - sed -i 's/^protected-mode yes/protected-mode no/g' /usr/local/etc/redis/redis.conf + sed -i 's/^protected-mode yes/protected-mode no/g' /usr/local/etc/redis/redis.conf; \ + sed -i "s/^port 6379/port ${E_REDIS_SERVER_PORT}/g" /usr/local/etc/redis/redis.conf -# after docker container runtime +# docker run container runtime, use env CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ] \ No newline at end of file diff --git a/Makefile b/Makefile index 1dc6d16..070d740 100644 --- a/Makefile +++ b/Makefile @@ -117,6 +117,9 @@ help: @echo "HIREDIS_USE_DYLIB=1, linker with use hiredis.so" @echo "HIREDIS_USE_DYLIB=1 HIREDIS_RUNTIME_DIR=/usr/local/lib ,if pkg install hiredis, linker with HIREDIS_RUNTIME_DIR use hiredis.so" @echo "REDIS_VERSION=6000, default 6000(6.0.0), use 70200(7.2.0) inlcude 7.2.0+ redismodule.h to use feature api" + @echo "make docker_img to build latest redis-server load redisxslot module img" + @echo "make docker_img_run to run latest redisxslot module docker img container" + @echo "have fun :)" init: @git submodule init @@ -175,5 +178,88 @@ clean: rm -rvf $(SOURCEDIR)/redisxslot.so.$(REDISXSLOT_SONAME) rm -rvf $(SOURCEDIR)/redisxslot.dylib.$(REDISXSLOT_SONAME) +# build docker img with redis stable version https://hub.docker.com/_/redis/ +# (v6.0)6.0.20 (v6.2)6.2.13 (v7.0)7.0.12 (v7.2)7.2.0 docker_img: - docker build -t redisxslot:latest . --build-arg REDIS_IMG_TAG=latest + docker build -t redisxslot:latest_$(REDISXSLOT_SONAME) . --build-arg A_REDIS_IMG_TAG=latest --build-arg A_REDIS_SERVER_PORT=17000 +docker_img_v6.0: + docker build -t redisxslot:6.0.20_$(REDISXSLOT_SONAME) . --build-arg A_REDIS_IMG_TAG=6.0.20 --build-arg A_REDIS_SERVER_PORT=16001 +docker_img_v6.2: + docker build -t redisxslot:6.2.13_$(REDISXSLOT_SONAME) . --build-arg A_REDIS_IMG_TAG=6.2.13 --build-arg A_REDIS_SERVER_PORT=16002 +docker_img_v7.0: + docker build -t redisxslot:7.0.12_$(REDISXSLOT_SONAME) . --build-arg A_REDIS_IMG_TAG=7.0.12 --build-arg A_REDIS_SERVER_PORT=16003 +docker_img_v7.2: + docker build -t redisxslot:7.2.0_$(REDISXSLOT_SONAME) . --build-arg A_REDIS_IMG_TAG=7.2.0 --build-arg A_REDIS_SERVER_PORT=16004 + +# create bridge docker network +docker_network: + docker network create -d bridge redisxslot-net + +docker_img_list: + docker image list | grep redisxslot + +# run docker reidisxslot container, (taolu)so easy~ +# just through bridge docker network for container inner run redis-cli +# tips: +# if container not a pod or vpc network, +# need config inner container access outside network. +docker_img_run: + docker run -itd \ + --name redisxslot \ + --network redisxslot-net \ + -p 17100:17000 \ + redisxslot:latest_$(REDISXSLOT_SONAME) +docker_img_run1: + docker run -itd \ + --name redisxslot1 \ + --network redisxslot-net \ + -p 17101:17000 \ + redisxslot:latest_$(REDISXSLOT_SONAME) +docker_img_run_v6.0: + docker run -itd \ + --name redisxslot_6.0.20_$(REDISXSLOT_SONAME) \ + --network redisxslot-net \ + -p 16100:16001 \ + redisxslot:6.0.20_$(REDISXSLOT_SONAME) +docker_img_run1_v6.0: + docker run -itd \ + --name redisxslot1_6.0.20_$(REDISXSLOT_SONAME) \ + --network redisxslot-net \ + -p 16101:16001 \ + redisxslot:6.0.20_$(REDISXSLOT_SONAME) +docker_img_run_v6.2: + docker run -itd \ + --name redisxslot_6.2.13_$(REDISXSLOT_SONAME) \ + --network redisxslot-net \ + -p 16200:16002 \ + redisxslot:6.2.13_$(REDISXSLOT_SONAME) +docker_img_run1_v6.2: + docker run -itd \ + --name redisxslot1_6.2.13_$(REDISXSLOT_SONAME) \ + --network redisxslot-net \ + -p 16201:16002 \ + redisxslot:6.2.13_$(REDISXSLOT_SONAME) +docker_img_run_v7.0: + docker run -itd \ + --name redisxslot_7.0.12_$(REDISXSLOT_SONAME) \ + --network redisxslot-net \ + -p 16300:16003 \ + redisxslot:7.0.12_$(REDISXSLOT_SONAME) +docker_img_run1_v7.0: + docker run -itd \ + --name redisxslot1_7.0.12_$(REDISXSLOT_SONAME) \ + --network redisxslot-net \ + -p 16301:16003 \ + redisxslot:7.0.12_$(REDISXSLOT_SONAME) +docker_img_run_v7.2: + docker run -itd \ + --name redisxslot_7.2.0_$(REDISXSLOT_SONAME)\ + --network redisxslot-net \ + -p 16400:16004 \ + redisxslot:7.2.0_$(REDISXSLOT_SONAME) +docker_img_run1_v7.2: + docker run -itd \ + --name redisxslot1_7.2.0_$(REDISXSLOT_SONAME)\ + --network redisxslot-net \ + -p 16401:16004 \ + redisxslot:7.2.0_$(REDISXSLOT_SONAME) \ No newline at end of file diff --git a/README.md b/README.md index f3a58cd..8a33c3e 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,27 @@ use conanfile py script todo ci with makefile release. 1. use `redis/src/redis-benchmark` add test data, test 1m data mgrt, see [doc/test.md](./docs/test.md). 2. need use redis tcl script `test_helper.tcl` to run test case;run `bash -x tests/run_test.sh`, so easy~ 3. ci loadmodule use test case to Redis test suite and run all test case. if new feat, add some test case in [tests/redisxslot.tcl](./tests/redisxslot.tcl) +# Docker +1. run in local docker +```shell +# build redisxslot with latest redis stable version +make docker_img +# run redisxslot with latest redis stable version +make docker_run +# then run redis-cli in container with bridge docker network for mgrt between container +``` +2. if docker img is ok, u can push build's img to inner/cloud img hub or docker hub for ci/cd, like this: +```shell +# login +docker login +# tag a docker hub name +#docker image tag {taghash} weedge/redisxslot:latest_0.1.0 +docker image tag redisxslot:latest_0.1.0 weedge/redisxslot:latest_0.1.0 +# push your docker hub +docker push weedge/redisxslot:latest_0.1.0 +# then pull this remote img to run, u can use it~ :) +docker run -itd --name weedge-redisxslot -p 16379:17000 weedge/redisxslot:latest_0.1.0 +``` # Cmd Case ```shell 127.0.0.1:6660> setex 122{tag} 86400 v3 @@ -61,7 +82,7 @@ OK 1) (integer) 899 127.0.0.1:6660> slotsinfo 899 1 1) 1) (integer) 899 - 2) (integer) 6 + 1) (integer) 6 127.0.0.1:6660> SLOTSMGRTTAGSLOT 127.0.0.1 6666 3000 899 1) (integer) 6 2) (integer) 0 @@ -72,7 +93,7 @@ OK ```shell 127.0.0.1:6666> slotsinfo 0 1024 1) 1) (integer) 899 - 2) (integer) 6 + 1) (integer) 6 127.0.0.1:6666> get 122{tag} "v3" 127.0.0.1:6666> ttl 122{tag}