forked from mattermost/mattermost-push-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
177 lines (137 loc) · 5.21 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
.PHONY: all dist build build-release build-local package test clean run update-dependencies golangci-lint
GOFLAGS ?= $(GOFLAGS:)
LDFLAGS ?= $(LDFLAGS:)
export GOBIN = $(PWD)/bin
GO=go
# Set version variables for LDFLAGS
GIT_VERSION ?= $(shell git describe --tags --always --dirty)
GIT_HASH ?= $(shell git rev-parse HEAD)
DATE_FMT = +'%Y-%m-%dT%H:%M:%SZ'
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct)
ifdef SOURCE_DATE_EPOCH
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
else
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
endif
GIT_TREESTATE = "clean"
DIFF = $(shell git diff --quiet >/dev/null 2>&1; if [ $$? -eq 1 ]; then echo "1"; fi)
ifeq ($(DIFF), 1)
GIT_TREESTATE = "dirty"
endif
PP_PKG=github.com/skymailbr/proxy-push-notification/internal/version
LDFLAGS="-X $(PP_PKG).gitVersion=$(GIT_VERSION) -X $(PP_PKG).gitCommit=$(GIT_HASH) -X $(PP_PKG).gitTreeState=$(GIT_TREESTATE) -X $(PP_PKG).buildDate=$(BUILD_DATE)"
DIST_ROOT=dist
DIST_PATH=$(DIST_ROOT)/talk-push-proxy
all: dist
dist: | build-release test package
update-dependencies:
$(GO) get -u ./...
$(GO) mod tidy
check-deps:
$(GO) mod tidy -v
@if [ -n "$$(command git --no-pager diff --exit-code go.mod go.sum)" ]; then \
echo "There are unused dependencies that should be removed. Please execute `go mod tidy` to fix it."; \
exit 1; \
fi
build-release:
@echo Building proxy push server
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -o $(GOBIN)/talk-push-proxy-linux-amd64 -trimpath -ldflags $(LDFLAGS) $(GOFLAGS)
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -o $(GOBIN)/talk-push-proxy-linux-arm64 -trimpath -ldflags $(LDFLAGS) $(GOFLAGS)
build-local: # build push proxy for the current arch
@echo Building proxy push server
env CGO_ENABLED=0 $(GO) build -o $(GOBIN) -trimpath -ldflags $(LDFLAGS) $(GOFLAGS)
golangci-lint: ## Run golangci-lint on codebase
# https://stackoverflow.com/a/677212/1027058 (check if a command exists or not)
@if ! [ -x "$$(command -v golangci-lint)" ]; then \
echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions."; \
exit 1; \
fi; \
@echo Running golangci-lint
golangci-lint run ./...
package-linux-amd64:
@ echo Packaging push proxy for linux amd64
mkdir -p $(DIST_PATH)/bin
cp $(GOBIN)/talk-push-proxy-linux-amd64 $(DIST_PATH)/bin/talk-push-proxy
cp -RL config $(DIST_PATH)/config
touch $(DIST_PATH)/config/build.txt
echo $(BUILD_NUMBER) | tee -a $(DIST_PATH)/config/build.txt
mkdir -p $(DIST_PATH)/logs
cp LICENSE.txt $(DIST_PATH)
cp NOTICE.txt $(DIST_PATH)
cp README.md $(DIST_PATH)
tar -C dist -czf $(DIST_PATH)-linux-amd64.tar.gz talk-push-proxy
rm -rf $(DIST_PATH)
package-linux-arm64:
@ echo Packaging push proxy for linux arm64
mkdir -p $(DIST_PATH)/bin
cp $(GOBIN)/talk-push-proxy-linux-arm64 $(DIST_PATH)/bin/talk-push-proxy
cp -RL config $(DIST_PATH)/config
touch $(DIST_PATH)/config/build.txt
echo $(BUILD_NUMBER) | tee -a $(DIST_PATH)/config/build.txt
mkdir -p $(DIST_PATH)/logs
cp LICENSE.txt $(DIST_PATH)
cp NOTICE.txt $(DIST_PATH)
cp README.md $(DIST_PATH)
tar -C dist -czf $(DIST_PATH)-linux-arm64.tar.gz talk-push-proxy
package: build-release package-linux-arm64 package-linux-amd64
cd dist \
sha256sum talk-push-proxy-linux-amd64.tar.gz >> checksums.txt \
&& sha256sum talk-push-proxy-linux-arm64.tar.gz >> checksums.txt
package-image: build-release
mkdir -p $(DIST_PATH)/bin
cp -RL config $(DIST_PATH)/config
touch $(DIST_PATH)/config/build.txt
echo $(BUILD_NUMBER) | tee -a $(DIST_PATH)/config/build.txt
mkdir -p $(DIST_PATH)/logs
cp LICENSE.txt $(DIST_PATH)
cp NOTICE.txt $(DIST_PATH)
cp README.md $(DIST_PATH)
PLATFORMS ?= linux/amd64 linux/arm64
ARCHS = $(patsubst linux/%,%,$(PLATFORMS))
IMAGE ?= skymailbr/proxy-push-notification
TAG ?= $(shell git describe --tags --always --dirty)
# build with buildx
.PHONY: container
container: package-image init-docker-buildx
@for platform in $(PLATFORMS); do \
echo "Starting build for $${platform} platform"; \
docker buildx build \
--load \
--progress plain \
--platform $${platform} \
--build-arg=ARCH=$${platform##*/} \
--tag $(IMAGE)-$${platform##*/}:$(TAG) \
--file docker/Dockerfile \
.; \
done
.PHONY: push
push: container
echo "Pushing $(IMGNAME) tags"
@for platform in $(PLATFORMS); do \
echo "Pushing tags for $${platform} platform"; \
docker push $(IMAGE)-$${platform##*/}:$(TAG); \
done
.PHONY: manifest
manifest: push
docker manifest create --amend $(IMAGE):$(TAG) $(shell echo $(ARCHS) | sed -e "s~[^ ]*~$(IMAGE)\-&:$(TAG)~g")
@for platform in $(ARCHS); do docker manifest annotate --arch "$${platform}" ${IMAGE}:${TAG} ${IMAGE}-$${platform}:${TAG}; done
docker manifest push --purge $(IMAGE):$(TAG)
# enable buildx
.PHONY: init-docker-buildx
init-docker-buildx:
./hack/init-buildx.sh
test:
$(GO) test $(GOFLAGS) -v -timeout=180s ./...
clean:
@echo Cleaning
rm -Rf $(DIST_ROOT)
go clean $(GOFLAGS) -i ./...
run:
@echo Starting go web server
$(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' main.go
build-swagger:
npm run validate
npm run build
serve-swagger:
npm run validate
npm run serve