forked from eual8/ephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
186 lines (127 loc) · 4.19 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
182
183
184
185
186
###############################
# Common defaults/definitions #
###############################
comma := ,
# Checks two given strings for equality.
eq = $(if $(or $(1),$(2)),$(and $(findstring $(1),$(2)),\
$(findstring $(2),$(1))),1)
######################
# Project parameters #
######################
IMAGE_NAME ?= allatra/ephyr
IMAGE_TAG ?= dev
GH_REPO ?= ALLATRA-IT/ephyr
###########
# Aliases #
###########
fmt: cargo.fmt
image: docker.image
##################
# Cargo commands #
##################
# Format Rust sources with rustfmt.
#
# Usage:
# make cargo.fmt [check=(no|yes)]
cargo.fmt:
cargo +nightly fmt --all $(if $(call eq,$(check),yes),-- --check,)
###################
# Docker commands #
###################
docker-comp = $(if $(call eq,$(comp),),restreamer,$(comp))
# Stop project in Docker Compose development environment
# and remove all related containers.
#
# Usage:
# make docker.down [app=(mix|vod)]
docker.down:
docker-compose --file=$(docker-compose-file) down --rmi=local -v
# Build project Docker image.
#
# Usage:
# make docker.image [comp=(restreamer|vod-meta-server)]
# [tag=($(IMAGE_TAG)|<tag>)]
# [no-cache=(no|yes)]
docker-image-tag = $(if $(call eq,$(tag),),$(IMAGE_TAG),$(tag))
docker.image:
ifeq ($(docker-comp),restreamer)
@cd components/$(docker-comp)/ && make docker.image tag=$(tag)
else
docker build --network=host --force-rm \
$(if $(call eq,$(no-cache),yes),--no-cache --pull,) \
--file=components/$(docker-comp)/Dockerfile \
-t $(IMAGE_NAME):$(docker-comp)$(if \
$(call eq,$(docker-image-tag),latest),,-$(docker-image-tag)) \
./
endif
# Push project Docker images to Container Registry.
#
# Usage:
# make docker.push [tags=($(IMAGE_TAG)|<t1>[,<t2>...])]
# [comp=(restreamer|vod-meta-server)]
docker-push-tags = $(if $(call eq,$(tags),),$(IMAGE_TAG),$(tags))
docker.push:
$(foreach t,$(subst $(comma), ,$(docker-push-tags)),\
$(call docker.push.do,\
$(IMAGE_NAME):$(docker-comp)$(if $(call eq,$(t),latest),,-$(t))))
define docker.push.do
$(eval image-full := $(strip $(1)))
docker push $(image-full)
endef
# Tag project Docker image with given tags.
#
# Usage:
# make docker.tag [of=($(IMAGE_TAG)|<tag>)]
# [tags=($(IMAGE_TAG)|<with-t1>[,<with-t2>...])]
# [comp=(restreamer|vod-meta-server)]
docker-tag-of = $(if $(call eq,$(of),),$(IMAGE_TAG),$(of))
docker-tag-with = $(if $(call eq,$(tags),),$(IMAGE_TAG),$(tags))
docker.tag:
$(foreach tag,$(subst $(comma), ,$(docker-tag-with)),\
$(call docker.tag.do,$(tag)))
define docker.tag.do
$(eval tag := $(strip $(1)))
docker tag \
$(IMAGE_NAME):$(docker-comp)-$(docker-tag-of) \
$(IMAGE_NAME):$(docker-comp)$(if $(call eq,$(tag),latest),,-$(tag))
endef
# Save project Docker images to a tarball file.
#
# Usage:
# make docker.tar [to-file=(.cache/image.tar|<file-path>)]
# [comp=(restreamer|vod-meta-server)]
# [tags=($(IMAGE_TAG)|<t1>[,<t2>...])]
docker-tar-file = $(if $(call eq,$(to-file),),.cache/image.tar,$(to-file))
docker-tar-tags = $(if $(call eq,$(tags),),$(IMAGE_TAG),$(tags))
docker.tar:
@mkdir -p $(dir $(docker-tar-file))
docker save -o $(docker-tar-file) \
$(foreach tag,$(subst $(comma), ,$(docker-tar-tags)),\
$(IMAGE_NAME):$(docker-comp)$(if $(call eq,$(tag),latest),,-$(tag)))
# Load project Docker images from a tarball file.
#
# Usage:
# make docker.untar [from-file=(.cache/image.tar|<file-path>)]
docker.untar:
docker load -i $(if $(call eq,$(from-file),),.cache/image.tar,$(from-file))
###########################
# .Github Actions section #
###########################
# Clear Github Acions usage cache.
#
# Need to install github cli first [https://cli.github.com/] and authorize
#
# Usage:
# make gh.clear
gh.clear:
gh api -H "Accept: application/vnd.github+json" \
/repos/$(GH_REPO)/actions/caches \
| for ID in `jq '.actions_caches[].id'`; \
do echo "Deleting $$ID"; \
gh api --method DELETE /repos/$(GH_REPO)/actions/caches/$$ID | echo; done
##################
# .PHONY section #
##################
.PHONY: fmt image \
cargo.fmt \
docker.image docker.push docker.tag docker.tar docker.untar