-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
57 lines (42 loc) · 1.37 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
DOCKER := docker
SED := sed
GIT := git
IMAGE_VARIANT := core # core | devel
DOCKER_BUILD_FLAGS := --build-arg VARIANT=$(IMAGE_VARIANT)
SPACE=$() $()
COMMA=,
TAG_LATEST=true
REPOSITORY := openvpn-ivpn
GIT_BRANCH := $(shell $(GIT) rev-parse --abbrev-ref HEAD | $(SED) 's/[^a-zA-Z0-9-]//g') # Sanitize
GIT_HASH := $(shell $(GIT) rev-parse HEAD)
override TAGS += branch-$(GIT_BRANCH) \
git-$(GIT_HASH)
# Tag image with 'latest' by default
ifeq ($(TAG_LATEST),true)
override TAGS += latest
endif
# Auto enable buildx when available
BUILDX_ENABLED := $(shell docker buildx version > /dev/null 2>&1 && printf true || printf false)
BUILDX_PLATFORMS := linux/amd64 linux/arm64
BUILDX_FLAGS :=
ifdef REPOSITORY_PREFIX
override REPOSITORY := $(REPOSITORY_PREFIX)/$(REPOSITORY)
endif
ifdef TAGS
TAG_PREFIX := --tag $(REPOSITORY):
override DOCKER_BUILD_FLAGS += $(TAG_PREFIX)$(subst $(SPACE),$(SPACE)$(TAG_PREFIX),$(strip $(TAGS)))
endif
ifeq ($(BUILDX_ENABLED),true)
override DOCKER := $(DOCKER) buildx
override DOCKER_BUILD_FLAGS += --platform $(subst $(SPACE),$(COMMA),$(BUILDX_PLATFORMS))
endif
$(info Docker buildx enabled: $(BUILDX_ENABLED))
.PHONY: image image-push
image:
$(DOCKER) build . $(DOCKER_BUILD_FLAGS)
image-push:
ifeq ($(BUILDX_ENABLED),true)
$(MAKE) image DOCKER_BUILD_FLAGS+="--push"
else
$(DOCKER) push $(REPOSITORY) --all-tags
endif