-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
86 lines (66 loc) · 2.25 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
BIN_OUTPUT_PATH = bin
TOOL_BIN = bin/gotools/$(shell uname -s)-$(shell uname -m)
DPKG_ARCH ?= $(shell dpkg --print-architecture)
ifeq ($(DPKG_ARCH),armhf)
DOCKER_ARCH ?= arm
else ifeq ($(DPKG_ARCH),arm64)
DOCKER_ARCH ?= arm64
else
DOCKER_ARCH ?= unknown
endif
OUTPUT_PATH = $(BIN_OUTPUT_PATH)/raspberry-pi-$(DOCKER_ARCH)
IMAGE_NAME = ghcr.io/viam-modules/raspberry-pi
.PHONY: module
module: build-$(DOCKER_ARCH)
rm -f $(BIN_OUTPUT_PATH)/raspberry-pi-module.tar.gz
cp $(BIN_OUTPUT_PATH)/raspberry-pi-$(DOCKER_ARCH) $(BIN_OUTPUT_PATH)/raspberry-pi
tar czf $(BIN_OUTPUT_PATH)/raspberry-pi-module.tar.gz $(BIN_OUTPUT_PATH)/raspberry-pi-$(DOCKER_ARCH) run.sh meta.json
.PHONY: build-$(DOCKER_ARCH)
build-$(DOCKER_ARCH):
go build -o $(BIN_OUTPUT_PATH)/raspberry-pi-$(DOCKER_ARCH) main.go
.PHONY: update-rdk
update-rdk:
go get go.viam.com/rdk@latest
go mod tidy
.PHONY: test
test:
go test -c -o $(BIN_OUTPUT_PATH)/raspberry-pi-tests-$(DOCKER_ARCH)/ ./...
for test in $$(ls $(BIN_OUTPUT_PATH)/raspberry-pi-tests-$(DOCKER_ARCH)/*.test) ; do \
sudo $$test -test.v || exit $?; \
done
.PHONY: tool-install
tool-install: $(TOOL_BIN)/golangci-lint
$(TOOL_BIN)/golangci-lint:
GOBIN=`pwd`/$(TOOL_BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint
.PHONY: lint
lint: $(TOOL_BIN)/golangci-lint
go mod tidy
$(TOOL_BIN)/golangci-lint run -v --fix --config=./etc/.golangci.yaml --timeout 5m
.PHONY: docker-all
docker-all: docker-build-64 docker-build-32
.PHONY: docker-build
docker-build:
cd docker && docker buildx build --load --no-cache --platform linux/$(DOCKER_ARCH) -t $(IMAGE_NAME):$(DOCKER_ARCH) .
.PHONY: docker-build-64
docker-build-64:
DOCKER_ARCH=arm64 make docker-build
.PHONY: docker-build-32
docker-build-32:
DOCKER_ARCH=arm make docker-build
.PHONY: docker-upload-all
docker-upload-all: docker-push-arm32 docker-push-arm64 docker-manifest
.PHONY: docker-push-arm32
docker-push-arm32:
docker push $(IMAGE_NAME):arm
.PHONY: docker-push-arm64
docker-push-arm64:
docker push $(IMAGE_NAME):arm64
.PHONY: docker-manifest
docker-manifest:
docker manifest create --amend $(IMAGE_NAME):latest $(IMAGE_NAME):arm $(IMAGE_NAME):arm64
docker manifest push $(IMAGE_NAME):latest
.PHONY: setup
setup:
sudo apt-get install -qqy pigpio
clean:
rm -rf $(BIN_OUTPUT_PATH)