Skip to content

Commit 6aad71c

Browse files
committed
updt: fix dockerfile && add docker build img run for diff redis stable version to makefile
Signed-off-by: weedge <[email protected]>
1 parent 5b92951 commit 6aad71c

File tree

3 files changed

+128
-17
lines changed

3 files changed

+128
-17
lines changed

Dockerfile

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
# docker build arg
2-
ARG REDISXSLOT_ARGS="1024 0 async"
3-
ARG REDIS_IMG_TAG=latest
4-
1+
# https://vsupalov.com/docker-arg-env-variable-guide/
2+
# docker build arg to all FROM
3+
ARG A_REDIS_IMG_TAG=latest
54

65
# dockerhub img https://hub.docker.com/_/redis
76
# https://github.com/docker-library/redis
8-
FROM redis:${REDIS_IMG_TAG}
7+
FROM redis:${A_REDIS_IMG_TAG}
98

109
# docker img meta
1110
LABEL redisxslot.image.authors="weedge"
1211

12+
# docker build arg after each FROM
13+
ARG A_REDISXSLOT_ARGS="1024 0 async"
14+
ARG A_REDIS_SERVER_PORT=6379
15+
1316
# container env
14-
ENV REDISXSLOT_URL https://github.com/weedge/redisxslot.git
15-
ENV REDIS_IMG_TAG ${REDIS_IMG_TAG}
16-
ENV REDISXSLOT_ARGS ${REDISXSLOT_ARGS}
17+
ENV E_REDISXSLOT_URL=https://github.com/weedge/redisxslot.git
18+
ENV E_REDISXSLOT_ARGS=${A_REDISXSLOT_ARGS}
19+
ENV E_REDIS_SERVER_PORT=${A_REDIS_SERVER_PORT}
1720

18-
# prepare layer
21+
# build prepare layer, use arg/env
1922
RUN set -eux; \
2023
\
2124
apt-get update; \
@@ -39,7 +42,7 @@ RUN set -eux; \
3942
cp /usr/src/redis/redis.conf /usr/local/etc/redis/; \
4043
rm redis.tar.gz; \
4144
\
42-
git clone ${REDISXSLOT_URL} /usr/src/redisxslot; \
45+
git clone ${E_REDISXSLOT_URL} /usr/src/redisxslot; \
4346
make -C /usr/src/redisxslot RM_INCLUDE_DIR=/usr/src/redis/src BUILD_TYPE=Release; \
4447
mv /usr/src/redisxslot/redisxslot.so /usr/local/lib/redisxslot_module.so; \
4548
\
@@ -50,11 +53,12 @@ RUN set -eux; \
5053
# Custom cache invalidation
5154
ARG CACHEBUST=1
5255

53-
# config layer
54-
RUN sed -i '1i loadmodule /usr/local/lib/redisxslot_module.so ${REDISXSLOT_ARGS}' /usr/local/etc/redis/redis.conf; \
56+
# build config layer, use arg/env
57+
RUN sed -i "1i loadmodule /usr/local/lib/redisxslot_module.so ${E_REDISXSLOT_ARGS}" /usr/local/etc/redis/redis.conf; \
5558
chmod 644 /usr/local/etc/redis/redis.conf; \
5659
sed -i 's/^bind 127.0.0.1/#bind 127.0.0.1/g' /usr/local/etc/redis/redis.conf; \
57-
sed -i 's/^protected-mode yes/protected-mode no/g' /usr/local/etc/redis/redis.conf
60+
sed -i 's/^protected-mode yes/protected-mode no/g' /usr/local/etc/redis/redis.conf; \
61+
sed -i "s/^port 6379/port ${E_REDIS_SERVER_PORT}/g" /usr/local/etc/redis/redis.conf
5862

59-
# after docker container runtime
63+
# docker run container runtime, use env
6064
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]

Makefile

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ help:
117117
@echo "HIREDIS_USE_DYLIB=1, linker with use hiredis.so"
118118
@echo "HIREDIS_USE_DYLIB=1 HIREDIS_RUNTIME_DIR=/usr/local/lib ,if pkg install hiredis, linker with HIREDIS_RUNTIME_DIR use hiredis.so"
119119
@echo "REDIS_VERSION=6000, default 6000(6.0.0), use 70200(7.2.0) inlcude 7.2.0+ redismodule.h to use feature api"
120+
@echo "make docker_img to build latest redis-server load redisxslot module img"
121+
@echo "make docker_img_run to run latest redisxslot module docker img container"
122+
@echo "have fun :)"
120123

121124
init:
122125
@git submodule init
@@ -175,5 +178,88 @@ clean:
175178
rm -rvf $(SOURCEDIR)/redisxslot.so.$(REDISXSLOT_SONAME)
176179
rm -rvf $(SOURCEDIR)/redisxslot.dylib.$(REDISXSLOT_SONAME)
177180

181+
# build docker img with redis stable version https://hub.docker.com/_/redis/
182+
# (v6.0)6.0.20 (v6.2)6.2.13 (v7.0)7.0.12 (v7.2)7.2.0
178183
docker_img:
179-
docker build -t redisxslot:latest . --build-arg REDIS_IMG_TAG=latest
184+
docker build -t redisxslot:latest_$(REDISXSLOT_SONAME) . --build-arg A_REDIS_IMG_TAG=latest --build-arg A_REDIS_SERVER_PORT=17000
185+
docker_img_v6.0:
186+
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
187+
docker_img_v6.2:
188+
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
189+
docker_img_v7.0:
190+
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
191+
docker_img_v7.2:
192+
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
193+
194+
# create bridge docker network
195+
docker_network:
196+
docker network create -d bridge redisxslot-net
197+
198+
docker_img_list:
199+
docker image list | grep redisxslot
200+
201+
# run docker reidisxslot container, (taolu)so easy~
202+
# just through bridge docker network for container inner run redis-cli
203+
# tips:
204+
# if container not a pod or vpc network,
205+
# need config inner container access outside network.
206+
docker_img_run:
207+
docker run -itd \
208+
--name redisxslot \
209+
--network redisxslot-net \
210+
-p 17100:17000 \
211+
redisxslot:latest_$(REDISXSLOT_SONAME)
212+
docker_img_run1:
213+
docker run -itd \
214+
--name redisxslot1 \
215+
--network redisxslot-net \
216+
-p 17101:17000 \
217+
redisxslot:latest_$(REDISXSLOT_SONAME)
218+
docker_img_run_v6.0:
219+
docker run -itd \
220+
--name redisxslot_6.0.20_$(REDISXSLOT_SONAME) \
221+
--network redisxslot-net \
222+
-p 16100:16001 \
223+
redisxslot:6.0.20_$(REDISXSLOT_SONAME)
224+
docker_img_run1_v6.0:
225+
docker run -itd \
226+
--name redisxslot1_6.0.20_$(REDISXSLOT_SONAME) \
227+
--network redisxslot-net \
228+
-p 16101:16001 \
229+
redisxslot:6.0.20_$(REDISXSLOT_SONAME)
230+
docker_img_run_v6.2:
231+
docker run -itd \
232+
--name redisxslot_6.2.13_$(REDISXSLOT_SONAME) \
233+
--network redisxslot-net \
234+
-p 16200:16002 \
235+
redisxslot:6.2.13_$(REDISXSLOT_SONAME)
236+
docker_img_run1_v6.2:
237+
docker run -itd \
238+
--name redisxslot1_6.2.13_$(REDISXSLOT_SONAME) \
239+
--network redisxslot-net \
240+
-p 16201:16002 \
241+
redisxslot:6.2.13_$(REDISXSLOT_SONAME)
242+
docker_img_run_v7.0:
243+
docker run -itd \
244+
--name redisxslot_7.0.12_$(REDISXSLOT_SONAME) \
245+
--network redisxslot-net \
246+
-p 16300:16003 \
247+
redisxslot:7.0.12_$(REDISXSLOT_SONAME)
248+
docker_img_run1_v7.0:
249+
docker run -itd \
250+
--name redisxslot1_7.0.12_$(REDISXSLOT_SONAME) \
251+
--network redisxslot-net \
252+
-p 16301:16003 \
253+
redisxslot:7.0.12_$(REDISXSLOT_SONAME)
254+
docker_img_run_v7.2:
255+
docker run -itd \
256+
--name redisxslot_7.2.0_$(REDISXSLOT_SONAME)\
257+
--network redisxslot-net \
258+
-p 16400:16004 \
259+
redisxslot:7.2.0_$(REDISXSLOT_SONAME)
260+
docker_img_run1_v7.2:
261+
docker run -itd \
262+
--name redisxslot1_7.2.0_$(REDISXSLOT_SONAME)\
263+
--network redisxslot-net \
264+
-p 16401:16004 \
265+
redisxslot:7.2.0_$(REDISXSLOT_SONAME)

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ use conanfile py script todo ci with makefile release.
4343
1. use `redis/src/redis-benchmark` add test data, test 1m data mgrt, see [doc/test.md](./docs/test.md).
4444
2. need use redis tcl script `test_helper.tcl` to run test case;run `bash -x tests/run_test.sh`, so easy~
4545
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)
46+
# Docker
47+
1. run in local docker
48+
```shell
49+
# build redisxslot with latest redis stable version
50+
make docker_img
51+
# run redisxslot with latest redis stable version
52+
make docker_run
53+
# then run redis-cli in container with bridge docker network for mgrt between container
54+
```
55+
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:
56+
```shell
57+
# login
58+
docker login
59+
# tag a docker hub name
60+
#docker image tag {taghash} weedge/redisxslot:latest_0.1.0
61+
docker image tag redisxslot:latest_0.1.0 weedge/redisxslot:latest_0.1.0
62+
# push your docker hub
63+
docker push weedge/redisxslot:latest_0.1.0
64+
# then pull this remote img to run, u can use it~ :)
65+
docker run -itd --name weedge-redisxslot -p 16379:17000 weedge/redisxslot:latest_0.1.0
66+
```
4667
# Cmd Case
4768
```shell
4869
127.0.0.1:6660> setex 122{tag} 86400 v3
@@ -61,7 +82,7 @@ OK
6182
1) (integer) 899
6283
127.0.0.1:6660> slotsinfo 899 1
6384
1) 1) (integer) 899
64-
2) (integer) 6
85+
1) (integer) 6
6586
127.0.0.1:6660> SLOTSMGRTTAGSLOT 127.0.0.1 6666 3000 899
6687
1) (integer) 6
6788
2) (integer) 0
@@ -72,7 +93,7 @@ OK
7293
```shell
7394
127.0.0.1:6666> slotsinfo 0 1024
7495
1) 1) (integer) 899
75-
2) (integer) 6
96+
1) (integer) 6
7697
127.0.0.1:6666> get 122{tag}
7798
"v3"
7899
127.0.0.1:6666> ttl 122{tag}

0 commit comments

Comments
 (0)