-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (50 loc) · 1.64 KB
/
Copy pathMakefile
File metadata and controls
65 lines (50 loc) · 1.64 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
54
55
56
57
58
59
60
61
62
63
64
65
BUILD_DIR := build
GO_SRCS := $(shell find . -name '*.go' -o -name 'go.mod' -o -name 'go.sum')
GOOSs := darwin linux
GOARCHs := amd64 arm64
UPDATER_BINARIES := $(foreach GOOS,$(GOOSs),$(foreach GOARCH,$(GOARCHs),$(BUILD_DIR)/photon-db-updater-$(GOOS)-$(GOARCH)))
AGENT_BINARIES := $(foreach GOOS,$(GOOSs),$(foreach GOARCH,$(GOARCHs),$(BUILD_DIR)/photon-agent-$(GOOS)-$(GOARCH)))
.PHONY: all
all: $(UPDATER_BINARIES) $(AGENT_BINARIES)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/%: $(GO_SRCS) | $(BUILD_DIR)
CGO_ENABLED=0 go build -trimpath -o $@ ./cmd/$*
define go-cross-build
$(BUILD_DIR)/$(1)-$(2)-$(3): $(GO_SRCS) | $(BUILD_DIR)
CGO_ENABLED=0 GOOS=$(2) GOARCH=$(3) \
go build -trimpath -o $$@ ./cmd/$(1)
endef
$(foreach GOOS,$(GOOSs),$(foreach GOARCH,$(GOARCHs),$(eval $(call go-cross-build,photon-db-updater,$(GOOS),$(GOARCH)))))
$(foreach GOOS,$(GOOSs),$(foreach GOARCH,$(GOARCHs),$(eval $(call go-cross-build,photon-agent,$(GOOS),$(GOARCH)))))
.PHONY: archive
archive: build.tar
build.tar: $(UPDATER_BINARIES) $(AGENT_BINARIES)
tar cf $@ $^
.PHONY: image
image: all
. ./.env && \
docker build \
-t ghcr.io/pddg/photon:latest \
--build-arg PHOTON_VERSION=$${PHOTON_VERSION} \
--build-arg PHOTON_SHA256SUM=$${PHOTON_SHA256SUM} \
--build-arg GIT_SHA=$(shell git rev-parse HEAD) \
.
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
.PHONY: lint
lint:
golangci-lint run --timeout 5m ./...
.PHONY: lint-fix
lint-fix:
golangci-lint run --fix --timeout 5m ./...
.PHONY: fmt
fmt:
golangci-lint fmt ./...
.PHONY: test
test: lint
go test -race -vet=off ./internal/...
.PHONY: test-e2e
test-e2e: image $(UPDATER_BINARIES)
go test -vet=off ./e2e/...