From f066e99dee38232210af1e1ae66241d0721a65e9 Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Fri, 11 Sep 2020 09:20:46 +0800 Subject: [PATCH] =?UTF-8?q?[fix:6.0]=E5=A2=9E=E5=8A=A0Makefile=EF=BC=9B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9LICENSE=E5=8F=8AREADME?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 2 +- Makefile | 63 +++++++++++++++++++++++++++++++++++++++++++++++-------- README.md | 22 +++++++++---------- 3 files changed, 66 insertions(+), 21 deletions(-) diff --git a/LICENSE b/LICENSE index b1886f9..80e3bb7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 endial +Copyright (c) 2020 Endial Fang (endial@126.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index 2dc149f..4e76259 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,62 @@ -# Ver: 1.0 by Endial Fang (endial@126.com) +# Ver: 1.4 by Endial Fang (endial@126.com) # # 当前 Docker 镜像的编译脚本 -app_name := redis -current_branch := $(shell git rev-parse --abbrev-ref HEAD) +app_name := colovu/redis + +# 生成镜像TAG,类似: +# <镜像名>:<分支名>- # Git 仓库且无文件修改直接编译 +# <镜像名>:<分支名>-<年月日>-<时分秒> # Git 仓库有文件修改后的编译 +# <镜像名>:latest-<年月日>-<时分秒> # 非 Git 仓库编译 +current_subversion:=$(shell if [[ -d .git ]]; then git rev-parse --short HEAD; else date +%y%m%d-%H%M%S; fi) +current_tag:=$(shell if [[ -d .git ]]; then git rev-parse --abbrev-ref HEAD | sed -e 's/master/latest/'; else echo "latest"; fi)-$(current_subversion) # Sources List: default / tencent / ustc / aliyun / huawei -build-arg := --build-arg apt_source=tencent +build-arg:=--build-arg apt_source=tencent # 设置本地下载服务器路径,加速调试时的本地编译速度 -#local_ip:=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d 'addr:'` -build-arg += --build-arg local_url=http://192.168.200.4/dist-files/ +local_ip:=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $$2}'|tr -d "addr:"` +build-arg+=--build-arg local_url=http://$(local_ip)/dist-files -build: - docker rmi $(app_name):$(current_branch) || true - docker build --force-rm $(build-arg) -t $(app_name):$(if $(current_branch),$(current_branch),latest) . +.PHONY: build build-debian build-alpine clean clearclean upgrade + +build-debian: + @echo "Build $(app_name):$(current_tag)-deb" + @docker build --force-rm $(build-arg) -t $(app_name):$(current_tag)-deb . + @echo "Add tag: $(app_name):latest-deb" + @docker tag $(app_name):$(current_tag)-deb $(app_name):latest-deb + +build-alpine: + @echo "Build $(app_name):$(current_tag)" + @docker build --force-rm $(build-arg) -t $(app_name):$(current_tag) ./alpine + @echo "Add tag: $(app_name):latest" + @docker tag $(app_name):$(current_tag) $(app_name):latest + +build: build-debian build-alpine + @echo "Build complete" + +# 清理悬空的镜像(无TAG)及停止的容器 +clean: + @echo "Clean untaged images and stoped containers..." + @docker ps -a | grep "Exited" | awk '{print $$1}' | xargs docker rm + @docker images | grep '' | awk '{print $$3}' | xargs docker rmi -f + +# 为了防止删除前缀名相同的镜像,在过滤条件中加入一个空格进行过滤 +clearclean: clean + @echo "Clean all images for current application..." + @docker images | grep "$(app_name) " | awk '{print $$3}' | xargs docker rmi -f + +tag: + @echo "Add tag: $(local_registory)/$(app_name):latest" + @docker tag $(app_name):latest $(local_registory)/$(app_name):latest + +push: tag + @echo "Push: $(local_registory)/$(app_name):latest" + @docker push $(local_registory)/$(app_name):latest + @echo "Push: $(app_name):latest" + @docker push $(app_name):latest + +# 更新所有 colovu 仓库的镜像 +upgrade: + @echo "Upgrade all images..." + @docker images | grep 'colovu' | grep -v '' | grep -v "latest-" | awk '{print $$1":"$$2}' | xargs -L 1 docker pull diff --git a/README.md b/README.md index 8ada384..d1b7d4f 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ **版本信息:** -- 6.0、6.0.6、latest -- 5.0、5.0.8 +- 6.0、latest +- 5.0 **镜像信息:** @@ -24,7 +24,7 @@ Docker 快速启动命令: ```shell -$ docker run -d --name redis -e ALLOW_EMPTY_PASSWORD=yes colovu/redis:latest +$ docker run -d -e ALLOW_ANONYMOUS_LOGIN=yes colovu/redis ``` Docker-Compose 快速启动命令: @@ -61,11 +61,11 @@ $ docker-compose -f docker-compose-cluster.yml up -d 镜像默认提供以下数据卷定义,默认数据分别存储在自动生成的应用名对应`redis`子目录中: ```shell -/srv/data # Redis 数据文件,主要存放Redis持久化数据;自动创建子目录redis +/srv/data # Redis 数据文件,主要存放Redis持久化数据;自动创建子目录redis /srv/datalog # Redis 数据操作日志文件;自动创建子目录redis -/srv/conf # Redis 配置文件;自动创建子目录redis -/var/log # 日志文件,日志文件名为:redis.log -/var/run # 进程运行PID文件,PID文件名为:redis_6379.pid、redis_sentinel.pid +/srv/conf # Redis 配置文件;自动创建子目录redis +/var/log # 日志文件,日志文件名为:redis.log +/var/run # 进程运行PID文件,PID文件名为:redis_6379.pid、redis_sentinel.pid ``` 如果需要持久化存储相应数据,需要**在宿主机建立本地目录**,并在使用镜像初始化容器时进行映射。宿主机相关的目录中如果不存在对应应用 Redis 的子目录或相应数据文件,则容器会在初始化时创建相应目录及文件。 @@ -77,7 +77,7 @@ $ docker-compose -f docker-compose-cluster.yml up -d 在初始化 Redis 容器时,如果没有预置配置文件,可以在命令行中设置相应环境变量对默认参数进行修改。类似命令如下: ```shell -$ docker run -d -e "REDIS_AOF_ENABLED=no" --name redis colovu/redis:latest +$ docker run -d -e "REDIS_AOF_ENABLED=no" colovu/redis ``` @@ -86,7 +86,7 @@ $ docker run -d -e "REDIS_AOF_ENABLED=no" --name redis colovu/redis:latest 常使用的环境变量主要包括: -- **ALLOW_EMPTY_PASSWORD**:默认值:**no**。设置是否允许无密码连接。如果没有设置`REDIS_PASSWORD`,则必须设置当前环境变量为 `yes` +- **ALLOW_ANONYMOUS_LOGIN**:默认值:**no**。设置是否允许无密码连接。如果没有设置`REDIS_PASSWORD`,则必须设置当前环境变量为 `yes` - **REDIS_PASSWORD**:默认值:**无**。客户端认证的密码 - **REDIS_DISABLE_COMMANDS**:默认值:**无**。设置禁用的 Redis 命令 - **REDIS_AOF_ENABLED**:默认值:**yes**。设置是否启用 Append Only File 存储 @@ -138,13 +138,13 @@ $ docker run -d -e "REDIS_AOF_ENABLED=no" --name redis colovu/redis:latest Redis 镜像默认禁用了无密码访问功能,在实际生产环境中建议使用用户名及密码控制访问;如果为了测试需要,可以使用以下环境变量启用无密码访问功能: ```shell -ALLOW_EMPTY_PASSWORD=yes +ALLOW_ANONYMOUS_LOGIN=yes ``` 通过配置环境变量`REDIS_PASSWORD`,可以启用基于密码的用户认证功能。命令行使用参考: ```shell -$ docker run -d -e REDIS_PASSWORD=colovu colovu/redis:latest +$ docker run -d -e REDIS_PASSWORD=colovu colovu/redis ``` 使用 Docker-Compose 时,`docker-compose.yml`应包含类似如下配置: