-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
53 lines (40 loc) · 1.29 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
DOCKER := docker
SED := sed
GIT := git
SPACE=$() $()
COMMA=,
TAG_LATEST=true
REPOSITORY := homebase
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 linux/arm/v7 linux/arm/v6
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