This repository has been archived by the owner on Jan 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
68 lines (53 loc) · 2.18 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
REPO=blacktop/docker-filebeat
ORG=blacktop
NAME=filebeat
BUILD ?=$(shell cat LATEST)
LATEST ?=$(shell cat LATEST)
all: build size test
build: ## Build docker image
docker build --build-arg VERSION=${LATEST} -t $(ORG)/$(NAME):$(BUILD) .
.PHONY: size
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
.PHONY: tags
tags:
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" $(ORG)/$(NAME)
test: ## Test docker image
@docker run --init -it --rm $(ORG)/$(NAME):$(BUILD) --version
.PHONY: tar
tar: ## Export tar of docker image
docker save $(ORG)/$(NAME):$(BUILD) -o $(NAME).tar
.PHONY: push
push: build ## Push docker image to docker registry
ifeq "$(BUILD)" "$(LATEST)"
@echo "===> Pushing $(ORG)/$(NAME):latest to docker hub..."
@docker tag $(ORG)/$(NAME):$(BUILD) $(ORG)/$(NAME):latest
@docker push $(ORG)/$(NAME):latest
endif
@echo "===> Pushing $(ORG)/$(NAME):$(BUILD) to docker hub..."
@docker push $(ORG)/$(NAME):$(BUILD)
.PHONY: run
run: stop ## Run docker container
@docker run --init -d --name $(NAME) -p 9200:9200 $(ORG)/$(NAME):$(BUILD)
.PHONY: ssh
ssh: clean_pcap ## SSH into docker image
@docker run --rm -v `pwd`/pcap:/pcap --entrypoint=sh $(ORG)/$(NAME):$(BUILD)
.PHONY: stop
stop: ## Kill running docker containers
@docker rm -f $(NAME) || true
@docker rm -f elasticsearch || true
@docker rm -f kibana || true
.PHONY: stop-all
stop-all: ## Kill ALL running docker containers
@docker-clean stop
clean: ## Clean docker image and stop all running containers
docker-clean stop
docker rmi $(ORG)/$(NAME):$(BUILD) || true
# 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