This repository has been archived by the owner on May 2, 2020. It is now read-only.
forked from geerlingguy/docker-ubuntu1404-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
58 lines (46 loc) · 1.73 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
.PHONY: pull build _run _test _fail _clean clean-local test-local clean-hub test-hub
THIS := $(lastword $(MAKEFILE_LIST))
OPTS := -f $(THIS) --no-print-directory
CURDIR := $(dir $(realpath $(THIS)))
ifndef IMAGE
IMAGE := $(notdir $(basename $(CURDIR:%/=%)))-$(subst ubuntu:,,$(lastword $(shell head Dockerfile -n 1)))
endif
CONTAINER := $(notdir $(basename $(IMAGE)-container))
G = "\033[92m"
R = "\033[91m"
Y = "\033[93m"
N = "\033[0m"
IMAGES := $(shell docker images -q $(IMAGE))
RUNNING := $(shell docker ps --all --quiet --filter ancestor=$(IMAGE))
pull:
docker pull yawpitch/$(IMAGE):latest
build:
docker build -t $(IMAGE) $(CURDIR)
_run:
@ echo Running $(Y)$(CONTAINER)$(N)
@ docker run --name $(CONTAINER) --detach --privileged --rm \
--volume=/sys/fs/cgroup:/sys/fs/cgroup:ro $(IMAGE):latest
_test: _run
@ docker exec --tty $(CONTAINER) env TERM=xterm ansible --version
@ echo $(G)ANSIBLE SUCCESS!$(N)
@ echo Stopping $(Y)$(CONTAINER)$(N)
@ docker stop -t 0 $(CONTAINER)
_fail:
@ echo $(R)ANSIBLE FAIL!$(N)
@ echo Stopping $(Y)$(CONTAINER)$(N)
@ docker stop -t 0 $(CONTAINER)
_clean:
@ if [ "$(RUNNING)" ]; then echo $(Y)Removing containers based on $(IMAGE)$(N); fi
@ if [ "$(RUNNING)" ]; then docker rm --force --volumes $(RUNNING); fi
@ if [ "$(IMAGES)" ]; then echo $(Y)Removing images from repo $(IMAGE)$(N); fi
@ if [ "$(IMAGES)" ]; then docker rmi --force $(IMAGES); fi
clean-local:
@ $(MAKE) $(OPTS) _clean IMAGE=$(IMAGE)
test-local: build
@ $(MAKE) $(OPTS) _test IMAGE=$(IMAGE) \
|| ($(MAKE) $(OPTS) _fail IMAGE=$(IMAGE) && exit 1)
clean-hub:
@ $(MAKE) $(OPTS) _clean IMAGE=yawpitch/$(IMAGE)
test-hub: pull
@ $(MAKE) $(OPTS) _test IMAGE=yawpitch/$(IMAGE) \
|| ($(MAKE) $(OPTS) _fail IMAGE=yawpitch/$(IMAGE) && exit 1)