Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (117 loc) · 6.96 KB
/
Copy pathMakefile
File metadata and controls
138 lines (117 loc) · 6.96 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# ynf: your named factory.
# make help this list
# make deps check the prerequisites (Go, golangci-lint) and download the modules
# make check format, vet, lint, tests with the race detector, and the coverage gate
# make build bin/ynf
# make install bin/ynf and its linux builds into $(INSTALL_DIR) (~/.ynf/bin, as ynh and ynm
# use ~/.ynh/bin and ~/.ynm/bin); put it on your PATH
# make docs serve the documentation at http://localhost:$(DOCS_PORT) (ctrl-c to stop)
# make conformance ynr conformance (ynr ADR-008) against ynf's own scenarios, offline; ynr must
# be on your PATH, at the version CI pins (YNR_VERSION in .github/workflows/ci.yml); with ynm
# on PATH too (YNM_VERSION in images/factory/versions.env) rule 13 runs as well
# make fullchain the full-chain check (.ynr/fullchain): a ynf step runs a ynh lane with the relay
# on, and what ynr serve ships is one trace with the run's records stamped; ynr and
# ynh must be on your PATH, at the versions CI pins (YNR_VERSION, YNH_VERSION)
# make e2e the factory acceptance test against the live sandbox (sandbox/Makefile)
# make factory-image ynf's factory image (ADR-009): ynh's image with ynf and ynm, at the
# versions in images/factory/versions.env, and this checkout's ynf. To try dev
# builds: YNH_SRC=<ynh checkout> builds its ynh in; YNM_SRC=<ynm checkout> builds
# its ynm (pnpm). FACTORY_IMAGE names it (default ynf-factory:dev).
# As ynh stamps its builds: a release tag when built exactly at one with nothing changed, otherwise
# dev-<branch>-<commit>, and -dirty with uncommitted changes. Releases are stamped by GoReleaser.
DEV_VERSION := dev-$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null | tr '/' '-' || echo unknown)-$(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)$(shell git diff --quiet 2>/dev/null || echo '-dirty')
VERSION ?= $(shell git diff --quiet 2>/dev/null && git describe --tags --exact-match 2>/dev/null || echo "$(DEV_VERSION)")
LDFLAGS := -s -w -X github.com/eyelock/ynf.Version=$(VERSION)
INSTALL_DIR ?= $(HOME)/.ynf/bin
COVERAGE ?= 80
DOCS_PORT ?= 3100
CONFORMANCE_FORMAT ?= text
include images/factory/versions.env
FACTORY_IMAGE ?= ynf-factory:dev
YNH_SRC ?=
YNM_SRC ?=
.PHONY: help deps docs check build install test cover lint vet fmt fmt-check conformance fullchain e2e calibrate clean factory-image
check: fmt-check vet lint cover
help:
@sed -n '2,/^$$/p' Makefile | sed -e 's/^# \{0,1\}//'
deps:
@command -v go >/dev/null 2>&1 || { echo "Installing Go..."; brew install go; }
@command -v golangci-lint >/dev/null 2>&1 || { echo "Installing golangci-lint..."; brew install golangci-lint; }
go mod download
cd sandbox/e2e && go mod download
@echo "All prerequisites installed."
# bin/ynf for this machine, plus static linux builds the docker executor runs as its egress proxy.
build:
go build -trimpath -ldflags "$(LDFLAGS)" -o bin/ynf ./cmd/ynf
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/ynf-linux-arm64 ./cmd/ynf
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/ynf-linux-amd64 ./cmd/ynf
install: build
@mkdir -p $(INSTALL_DIR)
@# Copy to a temporary name, then rename over the old binary. Overwriting a binary in place
@# keeps the same file, and on macOS the kernel's cached code-signature check for it can go
@# stale: the next launch is killed with SIGKILL (exit 137) and no message. A rename puts a
@# new file in place.
@for f in ynf ynf-linux-arm64 ynf-linux-amd64; do \
cp bin/$$f $(INSTALL_DIR)/.$$f.tmp && mv -f $(INSTALL_DIR)/.$$f.tmp $(INSTALL_DIR)/$$f; \
done
@echo "installed ynf $(VERSION) to $(INSTALL_DIR)"
test:
go test -race -count=1 ./...
cover:
@scripts/coverage.sh $(COVERAGE)
lint:
golangci-lint run ./...
vet:
go vet ./...
fmt:
gofmt -w .
fmt-check:
@out=$$(gofmt -l . | grep -v '^sandbox/seed/' || true); if [ -n "$$out" ]; then echo "gofmt needed:"; echo "$$out"; exit 1; fi
# docs/index.html loads docsify from a CDN, so a static server is all it needs.
docs:
@echo "docs at http://localhost:$(DOCS_PORT) (ctrl-c to stop)"
@python3 -m http.server $(DOCS_PORT) --directory docs
# ynr conformance runs .ynr/conformance.yaml against bin/ynf and the offline forge in .ynr/fakeforge,
# both first on the PATH for the run: no network, no model, and nothing of yours is touched.
conformance:
@command -v ynr >/dev/null 2>&1 || { echo "ynr is not on your PATH: see docs/how-to/see-ynf-in-opentelemetry.md"; exit 1; }
@go build -trimpath -ldflags "$(LDFLAGS)" -o bin/ynf ./cmd/ynf
@go build -trimpath -o bin/fakeforge ./.ynr/fakeforge
@PATH="$(CURDIR)/bin:$$PATH" ynr conformance --file .ynr/conformance.yaml --format $(CONFORMANCE_FORMAT)
# The full-chain check runs bin/ynf, ynr, ynh and ynr's stub vendor on a local repository and an
# offline forge, in a temporary directory with its own HOME: no network, no model, no docker.
fullchain:
@for t in ynr ynh; do command -v $$t >/dev/null 2>&1 || { echo "$$t is not on your PATH: see docs/how-to/see-ynf-in-opentelemetry.md"; exit 1; }; done
@go build -trimpath -ldflags "$(LDFLAGS)" -o bin/ynf ./cmd/ynf
@go build -trimpath -o bin/fakeforge ./.ynr/fakeforge
@go build -trimpath -o bin/fullchain ./.ynr/fullchain
@PATH="$(CURDIR)/bin:$$PATH" fullchain
e2e:
$(MAKE) -C sandbox e2e
calibrate:
$(MAKE) -C sandbox calibrate
clean:
rm -rf bin
# The factory image, for docker's architecture. Each tool is a release unless a checkout is given.
factory-image:
@set -e; arch=$$(docker version --format '{{.Server.Arch}}'); ctx=$$(mktemp -d); \
trap 'rm -rf "$$ctx"' EXIT; \
cp images/factory/Dockerfile "$$ctx/"; mkdir -p "$$ctx/ynh" "$$ctx/ynm"; \
echo "ynf $(VERSION) from this checkout"; \
CGO_ENABLED=0 GOOS=linux GOARCH=$$arch go build -trimpath -ldflags "$(LDFLAGS)" -o "$$ctx/ynf-linux-$$arch" ./cmd/ynf; \
if [ -n "$(YNH_SRC)" ]; then \
echo "ynh from $(YNH_SRC), over ghcr.io/eyelock/ynh:$(YNH_VERSION)"; \
(cd "$(YNH_SRC)" && CGO_ENABLED=0 GOOS=linux GOARCH=$$arch go build -trimpath -o "$$ctx/ynh/ynh" ./cmd/ynh); \
else echo "ynh $(YNH_VERSION)"; fi; \
if [ -n "$(YNM_SRC)" ]; then \
echo "ynm from $(YNM_SRC)"; \
(cd "$(YNM_SRC)" && pnpm -s build >/dev/null && node scripts/release/build-slim.mjs dev >/dev/null); \
tar -xzf "$(YNM_SRC)/dist-release/ynm_dev_slim.tar.gz" -C "$$ctx/ynm"; \
else \
echo "ynm $(YNM_VERSION)"; \
gh release download v$(YNM_VERSION) -R eyelock/ynm -p 'ynm_$(YNM_VERSION)_slim.tar.gz' -D "$$ctx"; \
tar -xzf "$$ctx/ynm_$(YNM_VERSION)_slim.tar.gz" -C "$$ctx/ynm"; \
fi; \
docker build -q --build-arg YNH_BASE=ghcr.io/eyelock/ynh:$(YNH_VERSION) --build-arg YNF_VERSION=$(VERSION) -t $(FACTORY_IMAGE) "$$ctx" >/dev/null; \
echo "built $(FACTORY_IMAGE):"; \
docker run --rm --entrypoint sh $(FACTORY_IMAGE) -c 'printf " ynf %s\n ynh %s\n ynm %s\n" "$$(ynf version)" "$$(ynh version)" "$$(ynm --version 2>/dev/null | tail -1)"'