From 0280ef1a16e539571dfff5c48df9f6b583d3b92e Mon Sep 17 00:00:00 2001 From: weedge Date: Thu, 7 Sep 2023 02:38: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 | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 15 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..67a7f73 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,73 @@ 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 + +docker_img_list: + docker image list | grep redisxslot + +# run docker reidisxslot container, (taolu)so easy~ +# tips: +# if container not a pod or vpc network, +# need config iner container access outside network. +docker_img_run: + docker run -itd \ + --name redisxslot \ + -p 17100:17000 \ + redisxslot:latest_$(REDISXSLOT_SONAME) +docker_img_run1: + docker run -itd \ + --name redisxslot1 \ + -p 17101:17000 \ + redisxslot:latest_$(REDISXSLOT_SONAME) +docker_img_run_v6.0: + docker run -itd \ + --name redisxslot_6.0.20_$(REDISXSLOT_SONAME) \ + -p 16100:16001 \ + redisxslot:6.0.20_$(REDISXSLOT_SONAME) +docker_img_run1_v6.0: + docker run -itd \ + --name redisxslot1_6.0.20_$(REDISXSLOT_SONAME) \ + -p 16101:16001 \ + redisxslot:6.0.20_$(REDISXSLOT_SONAME) +docker_img_run_v6.2: + docker run -itd \ + --name redisxslot_6.2.13_$(REDISXSLOT_SONAME) \ + -p 16200:16002 \ + redisxslot:6.2.13_$(REDISXSLOT_SONAME) +docker_img_run1_v6.2: + docker run -itd \ + --name redisxslot1_6.2.13_$(REDISXSLOT_SONAME) \ + -p 16201:16002 \ + redisxslot:6.2.13_$(REDISXSLOT_SONAME) +docker_img_run_v7.0: + docker run -itd \ + --name redisxslot_7.0.12_$(REDISXSLOT_SONAME) \ + -p 16300:16003 \ + redisxslot:7.0.12_$(REDISXSLOT_SONAME) +docker_img_run1_v7.0: + docker run -itd \ + --name redisxslot1_7.0.12_$(REDISXSLOT_SONAME) \ + -p 16301:16003 \ + redisxslot:7.0.12_$(REDISXSLOT_SONAME) +docker_img_run_v7.2: + docker run -itd \ + --name redisxslot_7.2.0_$(REDISXSLOT_SONAME)\ + -p 16400:16004 \ + redisxslot:7.2.0_$(REDISXSLOT_SONAME) +docker_img_run1_v7.2: + docker run -itd \ + --name redisxslot1_7.2.0_$(REDISXSLOT_SONAME)\ + -p 16401:16004 \ + redisxslot:7.2.0_$(REDISXSLOT_SONAME) \ No newline at end of file