-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
83 lines (68 loc) · 2.38 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
# Copyright 2024 Cody Boggs
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
PROJ_DIR ?= $(shell pwd)
BIN_DIR ?= $(PROJ_DIR)/bin
BINARY := buildkit-exporter
BUILDX_BUILDER ?= local
BUILDX_BUILDER_FILE ?= ~/.docker/buildx/instances/$(BUILDX_BUILDER)
BUILDKIT_SOCKET_PATH ?= /run/buildkit/buildkitd.sock
BUILDKIT_ADDR ?= unix://$(BUILDKIT_SOCKET_PATH)
BUILDX_REMOTE_ADDR ?= $(BUILDKIT_ADDR)
EXPORTER_ARGS = --buildkit.address=$(BUILDKIT_ADDR) --web.listen-address=$(EXPORTER_ADDR)
EXPORTER_ADDR := :9220
PROMU := $(GOPATH)/bin/promu
PROMU_VERSION ?= 0.15.0
IMAGE_NAME = buildkit-exporter
all: build run
$(BUILDX_BUILDER_FILE):
docker buildx create \
--name=$(BUILDX_BUILDER) \
--use \
--bootstrap \
--driver=remote \
$(BUILDX_REMOTE_ADDR)
build: $(PROMU)
$(PROMU) build --prefix $(BIN_DIR)
run:
$(BIN_DIR)/$(BINARY) $(EXPORTER_ARGS)
docker-build: $(BUILDX_BUILDER_FILE)
docker buildx build \
--builder=$(BUILDX_BUILDER) \
--build-arg PROMU_VERSION=$(PROMU_VERSION) \
--load \
-t $(IMAGE_NAME) \
.
.PHONY: run
docker-run: docker-build
echo "ARGS: $(EXPORTER_ARGS)"
docker run \
--rm \
-it \
-v $(BUILDKIT_SOCKET_PATH):$(BUILDKIT_SOCKET_PATH) \
-e EXPORTER_ARGS=$(EXPORTER_ARGS) \
$(IMAGE_NAME)
$(PROMU):
go install github.com/prometheus/promu@v$(PROMU_VERSION)
install-promu: $(PROMU)
run-prometheus:
docker run \
--rm \
--network host \
-v $(PROJ_DIR)/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
get-histories:
@buildctl --addr $(BUILDKIT_ADDR) debug histories --format '{{json .}}' \
| jq -c '.' \
| jq -s '.[0].record '
push-ghcr: docker-build
@echo $(GITHUB_TOKEN_BUILDKIT_EXPORTER_GHCR) | docker login ghcr.io -u cboggs --password-stdin
docker tag buildkit-exporter:latest ghcr.io/confused-curmudgeon/buildkit-exporter:v0.1.0
docker push ghcr.io/confused-curmudgeon/buildkit-exporter:v0.1.0