Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
49 lines (40 loc) · 1.84 KB
/
Copy pathMakefile
File metadata and controls
49 lines (40 loc) · 1.84 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
GO ?= go
BUILD_DIR ?= build
IMAGE ?= localhost/sunbeam:dev
SUNBEAM_BINARY := $(BUILD_DIR)/sunbeam
SUNBEAM_STATE_DIR := $(BUILD_DIR)/sunbeam-state
SUNBEAM_SOURCES := $(shell find cmd/sunbeam internal/gen/sunbeam internal/modules/routing -name '*.go') go.mod go.sum Makefile
D2_SOURCES := docs/diagrams/architecture.d2 $(wildcard docs/diagrams/icons/*.svg)
PROTOC_GEN_GO := $(shell $(GO) tool -n protoc-gen-go)
PROTOC_GEN_CONNECT_GO := $(shell $(GO) tool -n protoc-gen-connect-go)
PROTO_SOURCES := $(wildcard api/sunbeam/v1/*.proto)
.PHONY: all clean generate image sunbeam
all: docs/diagrams/architecture.png
sunbeam: $(SUNBEAM_BINARY)
$(SUNBEAM_BINARY): $(SUNBEAM_SOURCES)
mkdir -p "$(@D)"
CGO_ENABLED=0 GOOS=linux $(GO) build -trimpath -ldflags='-s -w' -o "$@" ./cmd/sunbeam
image: sunbeam
@set -eu; \
container=""; \
trap 'if [ -n "$$container" ]; then buildah rm "$$container" >/dev/null 2>&1 || true; fi' EXIT HUP INT TERM; \
mkdir -p "$(SUNBEAM_STATE_DIR)"; \
container="$$(buildah from scratch)"; \
buildah copy "$$container" "$(SUNBEAM_BINARY)" /sunbeam >/dev/null; \
buildah copy --chown 65532:65532 "$$container" "$(SUNBEAM_STATE_DIR)" /var/lib/sunbeam >/dev/null; \
buildah config --entrypoint '["/sunbeam"]' --user 65532:65532 --port 8080/tcp --volume /var/lib/sunbeam "$$container"; \
buildah commit --rm "$$container" "$(IMAGE)" >/dev/null; \
container=""; \
echo "Built $(IMAGE)"
clean:
rm -rf -- "$(BUILD_DIR)"
generate:
protoc -I api -I third_party/googleapis -I /usr/include \
--plugin=protoc-gen-go=$(PROTOC_GEN_GO) \
--plugin=protoc-gen-connect-go=$(PROTOC_GEN_CONNECT_GO) \
--go_out=. --go_opt=module=github.com/goevery/sunstone \
--connect-go_out=. --connect-go_opt=module=github.com/goevery/sunstone \
$(PROTO_SOURCES)
$(GO) tool mockery
docs/diagrams/architecture.png: $(D2_SOURCES)
$(GO) tool d2 docs/diagrams/architecture.d2 $@