forked from blacktop/docker-kibana-alpine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
79 lines (60 loc) · 3.12 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
.PHONY: build size tags test tar push run ssh stop circle
REPO=blacktop/kibana
ORG=blacktop
NAME=kibana
# build info
BUILD ?=$(shell cat LATEST)
LATEST ?=$(shell cat LATEST)
VERSION=$(shell cat "$(BUILD)/Dockerfile" | grep '^ENV VERSION' | cut -d" " -f3)
# tarball info
DOWNLOAD_URL=https://artifacts.elastic.co/downloads/$(NAME)
SHA_URL=$(DOWNLOAD_URL)/$(NAME)-$(VERSION)-linux-x86_64.tar.gz.sha512
TARBALL_SHA=$(shell curl -s "$(SHA_URL)")
all: build size test
dockerfile: ## Update Dockerfiles
@echo "===> Getting $(NAME) tarball sha1 for version: $(VERSION)"
@echo " * TARBALL_SHA=$(TARBALL_SHA)"
sed -i.bu 's/TARBALL_SHA "[0-9a-f.]\{128\}"/TARBALL_SHA "$(TARBALL_SHA)"/' $(BUILD)/Dockerfile
build: dockerfile ## Build docker image
cd $(BUILD); docker build -t $(ORG)/$(NAME):$(BUILD) .
size: build ## Get built image size
ifeq "$(BUILD)" "$(LATEST)"
sed -i.bu 's/docker%20image-.*-blue/docker%20image-$(shell docker images --format "{{.Size}}" $(ORG)/$(NAME):$(BUILD)| cut -d' ' -f1)-blue/' README.md
sed -i.bu '/latest/ s/[0-9.]\{3,5\}MB/$(shell docker images --format "{{.Size}}" $(ORG)/$(NAME):$(BUILD))/' README.md
endif
sed -i.bu '/$(BUILD)/ s/[0-9.]\{3,5\}MB/$(shell docker images --format "{{.Size}}" $(ORG)/$(NAME):$(BUILD))/' README.md
tags:
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" $(ORG)/$(NAME)
test: stop ## Test docker image
@docker run --init -d --name elasticsearch -p 9200:9200 blacktop/elasticsearch:$(BUILD); sleep 10;
@docker run --init -d --name $(NAME) --link elasticsearch -p 5601:5601 $(ORG)/$(NAME):$(BUILD)
@docker logs $(NAME)
tar: ## Export tar of docker image
docker save $(ORG)/$(NAME):$(BUILD) -o $(NAME).tar
push: build ## Push docker image to docker registry
@echo "===> Pushing $(ORG)/$(NAME):$(BUILD) to docker hub..."
@docker push $(ORG)/$(NAME):$(BUILD)
run: stop ## Run docker container
@docker run --init -d --name $(NAME) -p 5601:5601 $(ORG)/$(NAME):$(BUILD)
ssh: ## SSH into docker image
@docker run --init -it --rm --entrypoint=sh $(ORG)/$(NAME):$(BUILD)
stop: ## Kill running malice-engine docker containers
@docker rm -f $(NAME) || true
@docker rm -f elasticsearch || true
circle: ci-size ## Get docker image size from CircleCI
@sed -i.bu 's/docker%20image-.*-blue/docker%20image-$(shell cat .circleci/SIZE)-blue/' README.md
@echo "===> Image size is: $(shell cat .circleci/SIZE)"
ci-build:
@echo "===> Getting CircleCI build number"
@http https://circleci.com/api/v1.1/project/github/${REPO} | jq '.[0].build_num' > .circleci/build_num
ci-size: ci-build
@echo "===> Getting image build size from CircleCI"
@http "$(shell http https://circleci.com/api/v1.1/project/github/${REPO}/$(shell cat .circleci/build_num)/artifacts circle-token==${CIRCLE_TOKEN} | jq '.[].url')" > .circleci/SIZE
clean: ## Clean docker image and stop all running containers
docker-clean stop
docker rmi $(ORG)/$(NAME):$(BUILD) || true
rm -rf malice/build
# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help