-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmeta.mk
61 lines (46 loc) · 1.9 KB
/
meta.mk
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
DOCKER ?= sudo docker
REV ?= $(shell git describe --always)
BUILD_FLAGS ?= -no-cache=true -rm=true
PROJECT ?= $(shell basename $(PWD))
REGISTRY ?= quay.io/modcloth
LATEST ?= $(shell $(DOCKER) images | grep $(REGISTRY)/$(PROJECT) | head -n 1 | awk '{print $$3}' )
export DOCKER
export REV
export BUILD_FLAGS
export PROJECT
export REGISTRY
export LATEST
all:
@echo "Available targets:"
@echo " * clean - remove all build artifact files for $(PROJECT)"
@echo " * clean-images - remove all images and tags for $(PROJECT)"
@echo " * container - build a Docker container for $(PROJECT)"
@echo " * latest - builds and tags the latest container for $(PROJECT) as 'latest'"
@echo " * pull - pull down previous docker builds of $(REGISTRY)/$(PROJECT)"
@echo " * push - push $(REGISTRY)/$(PROJECT)"
@echo " * tag - tags the lastest image as 'latest'"
container: .latest_container Dockerfile
latest: build-and-tag
tag: delete-current-tag .latest_tagged
push: .latest_pushed
delete-current-tag:
rm -f .latest_tagged
clean:
rm -f .latest_container .latest_tagged .latest_pushed .container_output
clean-images:
export IMAGES="$(shell $(DOCKER) images | grep $(REGISTRY)/$(PROJECTS))" ; \
test -z "$$IMAGES" || echo $$IMAGES | awk '{ print $$3 }' | \
sort | uniq | xargs $(DOCKER) rmi
.latest_container: pull
rm -f $@
$(DOCKER) build -t $(REGISTRY)/$(PROJECT):$(REV) $(BUILD_FLAGS) . | tee .container_output
awk '/^Successfully built/ { print $$NF }' .container_output | tail -1 > $@
.latest_tagged:
( test -z "$(LATEST)" && echo 'Nothing to tag!' ) || $(DOCKER) tag $(LATEST) $(REGISTRY)/$(PROJECT):latest && touch $@
build-and-tag: .latest_container tag
pull:
$(DOCKER) pull $(REGISTRY)/$(PROJECT) || true
.latest_pushed: .latest_tagged
$(DOCKER) push $(REGISTRY)/$(PROJECT)
.PHONY: container latest push clean clean-images tag pull
.PHONY: delete-current-tag build-and-tag