-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
182 lines (144 loc) · 3.94 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#
# Standard version level Makefile used to build a Docker container for MickMake projects.
#
# Determine whether we use "nodeJS" or "JQ".
JSONCMD := $(shell jq -r '.project' ./container.json)
ifneq ($(JSONCMD),)
define GetFromPkg
$(shell jq -r ".$(1)" ./container.json)
endef
else
JSONCMD := $(shell node -p "require('./container.json').project")
ifneq ($(JSONCMD),)
define GetFromPkg
$(shell node -p "require('./container.json').$(1)")
endef
else
$(shell )
endif
endif
# Set global variables from container file.
PROJECT := $(call GetFromPkg,project)
NAME := $(call GetFromPkg,name)
VERSION := $(call GetFromPkg,version)
MAJORVERSION := $(call GetFromPkg,majorversion)
LATEST := $(call GetFromPkg,latest)
NETWORK := $(call GetFromPkg,network)
PORTS := $(call GetFromPkg,ports)
VOLUMES := $(call GetFromPkg,volumes)
RESTART := $(call GetFromPkg,restart)
ARGS := $(call GetFromPkg,args)
ENV := $(call GetFromPkg,env)
IMAGE_NAME ?= $(PROJECT)/$(NAME)
CONTAINER_NAME ?= $(NAME)-$(VERSION)
.PHONY: build push release reallyclean clean test shell run start stop rm
################################################################################
# Image related commands.
default: build
build: Dockerfile
ifeq ($(PROJECT),)
@echo "MickMake: ERROR - You need to install JQ or NodeJS."
else
clear; clear; make reallyclean; docker build -t $(IMAGE_NAME):$(VERSION) --build-arg $(ENV)=$(VERSION) .
ifneq ($(MAJORVERSION),)
-docker build -t $(IMAGE_NAME):$(MAJORVERSION) --build-arg $(ENV)=$(MAJORVERSION) .
endif
ifeq ($(LATEST),1)
docker build -t $(IMAGE_NAME):latest --build-arg $(ENV)=latest .
endif
endif
push:
ifeq ($(PROJECT),)
@echo "MickMake: ERROR - You need to install JQ or NodeJS."
else
-docker push $(IMAGE_NAME):$(VERSION)
ifneq ($(MAJORVERSION),)
-docker push $(IMAGE_NAME):$(MAJORVERSION)
endif
ifeq ($(LATEST),1)
docker push $(IMAGE_NAME):latest
endif
endif
release: build
ifeq ($(PROJECT),)
@echo "MickMake: ERROR - You need to install JQ or NodeJS."
else
make build
make push
endif
reallyclean:
make rm; make clean
clean:
ifeq ($(PROJECT),)
@echo "MickMake: ERROR - You need to install JQ or NodeJS."
else
docker image rm $(IMAGE_NAME):$(VERSION)
ifneq ($(MAJORVERSION),)
docker image rm $(IMAGE_NAME):$(MAJORVERSION)
endif
ifeq ($(LATEST),1)
docker image rm $(IMAGE_NAME):latest
endif
endif
list:
ifeq ($(PROJECT),)
@echo "MickMake: ERROR - You need to install JQ or NodeJS."
else
docker image ls $(IMAGE_NAME):$(VERSION)
ifneq ($(MAJORVERSION),)
docker image ls $(IMAGE_NAME):$(MAJORVERSION)
endif
ifeq ($(LATEST),1)
docker image ls $(IMAGE_NAME):latest
endif
endif
################################################################################
# Container related commands.
test:
ifeq ($(PROJECT),)
@echo "MickMake: ERROR - You need to install JQ or NodeJS."
else
make stop
make rm
make clean
make build
-make create
-make start
endif
shell:
ifeq ($(PROJECT),)
@echo "MickMake: ERROR - You need to install JQ or NodeJS."
else
docker run --rm -i -t $(NETWORK) $(PORTS) $(ARGS) $(VOLUMES) $(IMAGE_NAME):$(VERSION) /bin/bash
endif
run:
ifeq ($(PROJECT),)
@echo "MickMake: ERROR - You need to install JQ or NodeJS."
else
docker run --rm -i -t --name $(CONTAINER_NAME) $(NETWORK) $(PORTS) $(ARGS) $(VOLUMES) $(IMAGE_NAME):$(VERSION)
endif
create:
ifeq ($(PROJECT),)
@echo "MickMake: ERROR - You need to install JQ or NodeJS."
else
docker create --name $(CONTAINER_NAME) $(RESTART) $(NETWORK) $(PORTS) $(ARGS) $(VOLUMES) $(IMAGE_NAME):$(VERSION)
endif
start:
ifeq ($(PROJECT),)
@echo "MickMake: ERROR - You need to install JQ or NodeJS."
else
docker start $(CONTAINER_NAME)
endif
stop:
ifeq ($(PROJECT),)
@echo "MickMake: ERROR - You need to install JQ or NodeJS."
else
docker stop $(CONTAINER_NAME)
endif
rm:
ifeq ($(PROJECT),)
@echo "MickMake: ERROR - You need to install JQ or NodeJS."
else
docker container rm $(CONTAINER_NAME)
endif
################################################################################