-
Notifications
You must be signed in to change notification settings - Fork 117
/
Makefile
68 lines (56 loc) · 1.83 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
GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_VERSION=$(shell git describe --tags --always --dirty 2>/dev/null)
GIT_UNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
ifneq ($(GIT_UNTRACKEDCHANGES),)
GIT_VERSION := $(GIT_VERSION)-$(shell date +"%s")
endif
LDFLAGS := "-s -w -X main.Version=$(GIT_VERSION) -X main.GitCommit=$(GIT_COMMIT)"
SERVER?=ghcr.io
OWNER?=openfaas
IMG_NAME?=of-watchdog
TAG?=$(GIT_VERSION)
export GOFLAGS=-mod=vendor
.PHONY: all
all: gofmt test dist hashgen
.PHONY: test
test:
@echo "+ $@"
@go test -v ./...
.PHONY: gofmt
gofmt:
@echo "+ $@"
@gofmt -l -d $(shell find . -type f -name '*.go' -not -path "./vendor/*")
.PHONY: build
build:
@echo "+ $@"
@docker build \
--build-arg GIT_COMMIT=${GIT_COMMIT} \
--build-arg VERSION=${GIT_VERSION} \
-t $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) .
.PHONY: hashgen
hashgen:
./ci/hashgen.sh
.PHONY: dist
dist:
@echo "+ $@"
CGO_ENABLED=0 GOOS=linux go build -mod=vendor -ldflags $(LDFLAGS) -o bin/fwatchdog-amd64
GOARM=7 GOARCH=arm CGO_ENABLED=0 GOOS=linux go build -mod=vendor -ldflags $(LDFLAGS) -o bin/fwatchdog-arm
GOARCH=arm64 CGO_ENABLED=0 GOOS=linux go build -mod=vendor -ldflags $(LDFLAGS) -o bin/fwatchdog-arm64
GOOS=windows CGO_ENABLED=0 go build -mod=vendor -ldflags $(LDFLAGS) -o bin/fwatchdog.exe
# use this with
# `./ci/copy_redist.sh $(make print-image) && ./ci/hashgen.sh`
print-image:
@echo ${.IMAGE}
# Example:
# SERVER=docker.io OWNER=alexellis2 TAG=ready make publish
.PHONY: publish
publish:
@echo $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) && \
docker buildx create --use --name=multiarch --node=multiarch && \
docker buildx build \
--platform linux/amd64,linux/arm/v7,linux/arm64 \
--push=true \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg VERSION=$(VERSION) \
--tag $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) \
.