forked from desotech-it/whoami
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
113 lines (90 loc) · 2.88 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
GOCMD ?= go
GOFMT ?= gofmt
PACKAGE := $(shell $(GOCMD) list)
NAME := $(notdir $(PACKAGE))
FULLCOMMIT := $(shell git rev-parse HEAD)
TAG := $(shell git describe --tags --dirty)
VERSION := $(TAG:v%=%)
BUILD_VERSION := $(subst -,.,$(VERSION))
GOOS := $(shell $(GOCMD) env GOOS)
GOARCH := $(shell $(GOCMD) env GOARCH)
GOARM := $(shell $(GOCMD) env GOARM)
GOEXE := $(shell $(GOCMD) env GOEXE)
BASENAME = $(NAME)-$(BUILD_VERSION)-$(GOOS)-$(GOARCH)$(GOARM)
OUTPUT_BINARY = $(BASENAME)$(GOEXE)
OUTPUT_LINK = $(NAME)$(GOEXE)
OUTPUT_BIN_DIR = bin
OUTPUT_DIST_DIR = dist
DOCKER_REGISTRY ?= r.deso.tech
DOCKER_PROJECT ?= whoami
DOCKER_IMAGE := $(DOCKER_REGISTRY)/$(DOCKER_PROJECT)/$(NAME)
ifeq ($(GOOS), windows)
ARCHIVE_EXT := .zip
else
ARCHIVE_EXT := .tar.gz
endif
OUTPUT_ARCHIVE=$(BASENAME)$(ARCHIVE_EXT)
EXTRA_ASSETS := 'static' 'template'
ifeq ($(OS), Windows_NT)
include windows.mk
else
include unix.mk
endif
LDFLAGS = $(ADDITIONAL_LDFLAGS) -s -w \
-X '$(PACKAGE)/app.version=$(VERSION)' \
-X '$(PACKAGE)/app.commit=$(FULLCOMMIT)' \
-X '$(PACKAGE)/app.date=$(DATE)'
BUILD_FLAGS = -trimpath -ldflags "$(LDFLAGS)" -o '$(OUTPUT_BIN_DIR)/$(OUTPUT_BINARY)'
GOBUILD = $(GOCMD) build $(BUILD_FLAGS)
ifeq ($(ARCHIVE_EXT), .tar.gz)
COMPRESSCMD := $(TARGZCMD)
else
COMPRESSCMD := 7z a -bso0 -bsp0 -tzip '$(OUTPUT_DIST_DIR)/$(OUTPUT_ARCHIVE)' $(EXTRA_ASSETS) '$(OUTPUT_BIN_DIR)/$(OUTPUT_BINARY)' ; \
7z rn -bso0 -bsp0 '$(OUTPUT_DIST_DIR)/$(OUTPUT_ARCHIVE)' '$(OUTPUT_BIN_DIR)/$(OUTPUT_BINARY)' '$(OUTPUT_LINK)'
endif
.DEFAULT_GOAL := link
.PHONY: build
build:
$(GOBUILD)
.PHONY: xbuild
xbuild:
$(XBUILDCMD)
.PHONY: link
link: build
$(LINKCMD)
.PHONY: compress
compress: build
$(MKDIRCMD) '$(OUTPUT_DIST_DIR)'
$(COMPRESSCMD)
.PHONY: xcompress
xcompress:
$(XCOMPRESSCMD)
.PHONY: clean
clean:
$(GOCMD) clean
$(RMCMD) '$(OUTPUT_BIN_DIR)'
$(RMCMD) '$(OUTPUT_DIST_DIR)'
.PHONY: fmt
fmt:
$(GOFMT) -s -w .
.PHONY: docker-linux
docker-linux:
docker buildx build --push --platform linux/amd64 -t '$(DOCKER_IMAGE):amd64-$(VERSION)' -t '$(DOCKER_IMAGE):amd64' .
docker buildx build --push --platform linux/arm64/v8 -t '$(DOCKER_IMAGE):arm64v8-$(VERSION)' -t '$(DOCKER_IMAGE):arm64v8' .
.PHONY: docker-windows
docker-windows:
docker build -t '$(DOCKER_IMAGE):$(VERSION)-windowsservercore' -t '$(DOCKER_IMAGE):windowsservercore' -f windows.dockerfile .
docker push '$(DOCKER_IMAGE):$(VERSION)-windowsservercore'
docker push '$(DOCKER_IMAGE):windowsservercore'
.PHONY: docker-shared
docker-shared:
docker manifest create '$(DOCKER_IMAGE):$(VERSION)' \
'$(DOCKER_IMAGE):amd64-$(VERSION)' \
'$(DOCKER_IMAGE):arm64v8-$(VERSION)' \
'$(DOCKER_IMAGE):$(VERSION)-windowsservercore'
docker manifest push '$(DOCKER_IMAGE):$(VERSION)'
docker manifest create '$(DOCKER_IMAGE):latest' \
'$(DOCKER_IMAGE):amd64' \
'$(DOCKER_IMAGE):arm64v8' \
'$(DOCKER_IMAGE):windowsservercore'
docker manifest push '$(DOCKER_IMAGE):latest'