-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
81 lines (70 loc) · 2.24 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
ifndef BUILD_SCOPE
BUILD_SCOPE=v1.21.5-dev
endif
PROJECT_BASE=vungle/golang
VERSION := $(patsubst v%,%,$(BUILD_SCOPE))
LABEL_PARTS ?= $(subst -, ,$(VERSION))
VERSION_PARTS := $(subst ., ,$(word 1,$(LABEL_PARTS)))
MAJOR := $(word 1,$(VERSION_PARTS))
MINOR := $(word 2,$(VERSION_PARTS))
PATCH := $(word 3,$(VERSION_PARTS))
LABEL := $(word 2,$(LABEL_PARTS))
ifdef LABEL
LABEL := -$(LABEL)
endif
ifeq ($(PUSH_MULTIARCH), true)
BUILDX_ARG_PUSH = '--push'
endif
.PHONY: all test clean
build-native:
@echo "Build options: $(BUILD_OPTS)"
@docker build \
$(BUILD_OPTS) \
-t $(PROJECT_BASE):$(VERSION) \
-t $(PROJECT_BASE):$(MAJOR).$(MINOR)$(LABEL) \
.
@docker build \
$(BUILD_OPTS) \
-t $(PROJECT_BASE):$(VERSION)-alpine \
-t $(PROJECT_BASE):$(MAJOR).$(MINOR)$(LABEL)-alpine \
-f Dockerfile.alpine \
.
build-multiarch: _prepare-multiarch
@echo "Build multiarch options: $(BUILD_OPTS)"
@docker buildx build \
$(BUILD_OPTS) \
--platform linux/amd64,linux/arm64 \
$(BUILDX_ARG_PUSH) \
-t "$(PROJECT_BASE):$(VERSION)-ma" \
-t "$(PROJECT_BASE):$(MAJOR).$(MINOR)$(LABEL)-ma" \
.
@docker buildx build \
$(BUILD_OPTS) \
--platform linux/amd64,linux/arm64 \
$(BUILDX_ARG_PUSH) \
-t "$(PROJECT_BASE):$(VERSION)-alpine-ma" \
-t "$(PROJECT_BASE):$(MAJOR).$(MINOR)$(LABEL)-alpine-ma" \
-f Dockerfile.alpine \
.
build: build-native build-multiarch
test:
@echo "Testing standard image..."
docker run --rm \
-v `pwd`/test:/var/test \
$(PROJECT_BASE):$(VERSION) \
go run /var/test/mustcompile/mustcompile.go -version="$(MAJOR).$(MINOR).$(PATCH)"
@echo "Testing alpine image..."
docker run --rm \
-v `pwd`/test:/var/test \
$(PROJECT_BASE):$(VERSION)-alpine \
go run /var/test/mustcompile/mustcompile.go -version="$(MAJOR).$(MINOR).$(PATCH)"
publish:
@docker push $(PROJECT_BASE):$(VERSION)
@docker push $(PROJECT_BASE):$(MAJOR).$(MINOR)$(LABEL)
@docker push $(PROJECT_BASE):$(VERSION)-alpine
@docker push $(PROJECT_BASE):$(MAJOR).$(MINOR)$(LABEL)-alpine
################
# Helper rules #
################
_prepare-multiarch:
docker buildx inspect | grep 'Driver:' | grep 'docker-container' > /dev/null || { docker buildx create --use --name multiarch-builder; docker buildx inspect --bootstrap; }