From 0855f2882a19d122e1a841a4994a1de2750432c0 Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Wed, 19 Aug 2020 09:02:14 +0800 Subject: [PATCH] =?UTF-8?q?[fix:1.16]=E6=9B=B4=E6=96=B0Dockerfile=E4=B8=AD?= =?UTF-8?q?PCRE=E4=B8=8B=E8=BD=BD=E5=9C=B0=E5=9D=80=EF=BC=9B=E6=9B=B4?= =?UTF-8?q?=E6=96=B0Makefile=EF=BC=9B=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E5=88=A0=E9=99=A4=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 5 +++-- Makefile | 31 ++++++++++++++++++++++++------- nginx/nginx.conf | 4 ++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index cc9913d..0f30178 100644 --- a/Dockerfile +++ b/Dockerfile @@ -183,8 +183,9 @@ RUN \ # 下载需要的软件包资源。可使用 不校验、签名校验、SHA256 校验 三种方式 DIST_NAME="pcre-${PCRE_VERSION}.tar.gz"; \ DIST_URLS=" \ - ${local_url}pcre/ \ - https://nchc.dl.sourceforge.net/project/pcre/pcre/${PCRE_VERSION}/ \ + ${local_url}/pcre/ \ + https://sourceforge.net/projects/pcre/files/pcre/${PCRE_VERSION}/ \ + https://jaist.dl.sourceforge.net/project/pcre/pcre/${PCRE_VERSION}/ \ "; \ . /usr/local/scripts/libdownload.sh && download_dist "${DIST_NAME}" "${DIST_URLS}"; \ \ diff --git a/Makefile b/Makefile index 42e9fdc..9103164 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,34 @@ -# Ver: 1.0 by Endial Fang (endial@126.com) +# Ver: 1.2 by Endial Fang (endial@126.com) # # 当前 Docker 镜像的编译脚本 app_name := colovu/nginx -current_branch := $(shell git rev-parse --abbrev-ref HEAD) + +# 生成镜像TAG,类似:<镜像名>:<分支名>- 或 <镜像名>:latest-<年月日>-<时分秒> +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://$(local_ip)/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/ + +.PHONY: build clean clearclean build: - docker rmi $(app_name):$(current_branch) || true - docker build --force-rm $(build-arg) -t $(app_name):$(if $(current_branch),$(current_branch),latest) . + @echo "Build $(app_name):$(current_tag)" + @docker build --force-rm $(build-arg) -t $(app_name):$(current_tag) . + @echo "Add tag: $(app_name):latest" + @docker tag $(app_name):$(current_tag) $(app_name):latest + +# 清理悬空的镜像(无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 diff --git a/nginx/nginx.conf b/nginx/nginx.conf index f5e7acb..b21f578 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1,7 +1,7 @@ # /etc/nginx/nginx.conf -# 针对 Docker 镜像使用,不能修改为其他用户 -user nginx; +# 针对当前已使用 nginx 用户的 Docker 镜像使用时,不需要定义用户 +#user nginx; # 关闭守护进程模式。如果设置为后台守护进程模式,容器在启动应用后会退出 daemon off;