-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
53 lines (38 loc) · 1.74 KB
/
Makefile
File metadata and controls
53 lines (38 loc) · 1.74 KB
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
LAMBDA_HANDLER := bootstrap
BIN_DIR := .bin
PKG_DIR := package
CMD_DIR := cmd/codedeploy-trigger
TAG := $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
BRANCH := $(if $(TAG),$(TAG),$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null))
HASH := $(shell git rev-parse --short=7 HEAD 2>/dev/null)
TIMESTAMP := $(shell git log -1 --format=%ct HEAD 2>/dev/null | xargs -I{} date -u -r {} +%Y%m%dT%H%M%S)
GIT_REV := $(shell printf "%s-%s-%s" "$(BRANCH)" "$(HASH)" "$(TIMESTAMP)")
REV := $(if $(filter --,$(GIT_REV)),latest,$(GIT_REV))
LDFLAGS := -ldflags "-X main.revision=$(REV) -s -w"
.PHONY: all build build-amd64 build-arm64 package package-amd64 package-arm64 test fmt vet tidy clean
all: package
build:
cd $(CMD_DIR) && CGO_ENABLED=0 go build -mod=vendor $(LDFLAGS) -o ../../$(BIN_DIR)/codedeploy-trigger
build-amd64:
mkdir -p $(BIN_DIR)/linux_amd64
cd $(CMD_DIR) && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -mod=vendor $(LDFLAGS) -o ../../$(BIN_DIR)/linux_amd64/$(LAMBDA_HANDLER)
build-arm64:
mkdir -p $(BIN_DIR)/linux_arm64
cd $(CMD_DIR) && GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -mod=vendor $(LDFLAGS) -o ../../$(BIN_DIR)/linux_arm64/$(LAMBDA_HANDLER)
package: package-amd64 package-arm64
package-amd64: build-amd64
mkdir -p $(PKG_DIR)
cd $(BIN_DIR)/linux_amd64 && zip -9 -r ../../$(PKG_DIR)/lambda-codedeploy-trigger_linux_amd64.zip $(LAMBDA_HANDLER)
package-arm64: build-arm64
mkdir -p $(PKG_DIR)
cd $(BIN_DIR)/linux_arm64 && zip -9 -r ../../$(PKG_DIR)/lambda-codedeploy-trigger_linux_arm64.zip $(LAMBDA_HANDLER)
test:
go test -mod=vendor -race -count=1 -timeout=60s ./...
fmt:
go fmt ./...
vet:
go vet -mod=vendor ./...
tidy:
go mod tidy
clean:
rm -rf $(BIN_DIR) $(PKG_DIR)