This repository has been archived by the owner on May 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Makefile
152 lines (112 loc) · 3.82 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
# This Makefile automates possible operations of this project.
#
# Images and description on Docker Hub will be automatically rebuilt on
# pushes to `master` branch of this repo and on updates of parent image.
#
# Note! Docker Hub `post_push` hook must be always up-to-date with default
# values of current Makefile. To update it just use:
# make post-push-hook
#
# It's still possible to build, tag and push images manually. Just use:
# make release
comma := ,
eq = $(if $(or $(1),$(2)),$(and $(findstring $(1),$(2)),\
$(findstring $(2),$(1))),1)
COTURN_VER ?= $(strip \
$(shell grep 'ARG coturn_ver=' Dockerfile | cut -d '=' -f2))
IMAGE_NAME := instrumentisto/coturn
TAGS ?= $(COTURN_VER) \
4.5 \
4 \
latest
VERSION ?= $(word 1,$(subst $(comma), ,$(TAGS)))
# Build Docker image.
#
# Usage:
# make image [tag=($(VERSION)|<docker-tag>)] [no-cache=(no|yes)]
# [COTURN_VER=<coturn-version>]
image-tag = $(if $(call eq,$(tag),),$(VERSION),$(tag))
image:
docker build --network=host --force-rm \
$(if $(call eq,$(no-cache),yes),--no-cache --pull,) \
--build-arg coturn_ver=$(COTURN_VER) \
-t $(IMAGE_NAME):$(image-tag) .
# Tag Docker image with given tags.
#
# Usage:
# make tags [for=($(VERSION)|<docker-tag>)]
# [tags=($(TAGS)|<docker-tag-1>[,<docker-tag-2>...])]
tags-for = $(if $(call eq,$(for),),$(VERSION),$(for))
tags-tags = $(if $(call eq,$(tags),),$(TAGS),$(tags))
tags:
$(foreach tag, $(subst $(comma), ,$(tags-tags)),\
$(call tags.do,$(tags-for),$(tag)))
define tags.do
$(eval from := $(strip $(1)))
$(eval to := $(strip $(2)))
docker tag $(IMAGE_NAME):$(from) $(IMAGE_NAME):$(to)
endef
# Manually push Docker images to Docker Hub.
#
# Usage:
# make push [tags=($(TAGS)|<docker-tag-1>[,<docker-tag-2>...])]
push-tags = $(if $(call eq,$(tags),),$(TAGS),$(tags))
push:
$(foreach tag, $(subst $(comma), ,$(push-tags)),\
$(call push.do, $(tag)))
define push.do
$(eval tag := $(strip $(1)))
docker push $(IMAGE_NAME):$(tag)
endef
# Make manual release of Docker images to Docker Hub.
#
# Usage:
# make release [tag=($(VERSION)|<docker-tag>)] [no-cache=(no|yes)]
# [tags=($(TAGS)|<docker-tag-1>[,<docker-tag-2>...])]
# [COTURN_VER=<coturn-version>]
release:
@make image tag=$(tag) no-cache=$(no-cache) \
COTURN_VER=$(COTURN_VER)
@make tags for=$(tag) tags=$(tags)
@make push tags=$(tags)
# Create `post_push` Docker Hub hook.
#
# When Docker Hub triggers automated build all the tags defined in `post_push`
# hook will be assigned to built image. It allows to link the same image with
# different tags, and not to build identical image for each tag separately.
# See details:
# http://windsock.io/automated-docker-image-builds-with-multiple-tags
#
# Usage:
# make post-push-hook [tags=($(TAGS)|<docker-tag-1>[,<docker-tag-2>...])]
# [out=(hooks/post_push|<file-path>)]
post-push-hook-tags = $(if $(call eq,$(tags),),$(TAGS),$(tags))
post-push-hook:
@mkdir -p hooks/
docker run --rm -v "$(PWD)/post_push.tmpl.php":/post_push.php:ro \
php:alpine php -f /post_push.php -- \
--image_tags='$(post-push-hook-tags)' \
> $(if $(call eq,$(out),),hooks/post_push,$(out))
# Run Bats tests for Docker image.
#
# Documentation of Bats:
# https://github.com/bats-core/bats-core
#
# Usage:
# make test [tag=($(VERSION)|<docker-tag>)]
test-tag = $(if $(call eq,$(tag),),$(VERSION),$(tag))
test:
ifeq ($(wildcard node_modules/.bin/bats),)
@make deps.bats
endif
IMAGE=$(IMAGE_NAME):$(test-tag) \
node_modules/.bin/bats test/suite.bats
# Resolve project dependencies for running tests with Yarn.
#
# Usage:
# make deps.bats
deps.bats:
docker run --rm --network=host -v "$(PWD)":/app -w /app \
node:alpine \
yarn install --non-interactive --no-progress
.PHONY: image tags push release post-push-hook test deps.bats