diff --git a/Makefile b/Makefile index c2649ad..4407ee7 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,14 @@ # # 当前 Docker 镜像的编译脚本 -app_name := colovu/openjre +app_name :=colovu/openjre # 生成镜像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) +current_subversion:=$(shell if [ ! `git status >/dev/null 2>&1` ]; then git rev-parse --short HEAD; else date +%y%m%d-%H%M%S; fi) +current_tag:=$(shell if [ ! `git status >/dev/null 2>&1` ]; 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 @@ -20,33 +20,33 @@ build-arg+=--build-arg local_url=http://$(local_ip)/dist-files .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: build-alpine build-debian + @echo "Build complete" -build-alpine: +build-debian: @echo "Build $(app_name):$(current_tag)" - @docker build --force-rm $(build-arg) -t $(app_name):$(current_tag) ./alpine + @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 -build: build-debian build-alpine - @echo "Build complete" +build-alpine: + @echo "Build $(app_name):$(current_tag)-alpine" + @docker build --force-rm $(build-arg) -t $(app_name):$(current_tag)-alpine ./alpine + @echo "Add tag: $(app_name):latest-alpine" + @docker tag $(app_name):$(current_tag)-alpine $(app_name):latest-alpine # 清理悬空的镜像(无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 | : + @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 | : + @docker images | grep "$(app_name) " | awk '{print $$3}' | xargs docker rmi -f # 更新所有 colovu 仓库的镜像 upgrade: @echo "Upgrade all images..." - @docker images | grep 'colovu' | grep -v '' | grep -v "latest-" | awk '{print $$1":"$$2}' | xargs -L 1 docker pull + @docker images | grep 'colovu' | grep -v '' | grep -v "latest-" | awk '{print $$1":"$$2}' | sort -u | xargs -L 1 docker pull