forked from uniget-org/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
172 lines (160 loc) · 7.16 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
M = $(shell printf "\033[34;1m▶\033[0m")
SHELL := /bin/bash
GIT_BRANCH ?= $(shell git branch --show-current)
GIT_COMMIT_SHA = $(shell git rev-parse HEAD)
#VERSION ?= $(patsubst v%,%,$(GIT_BRANCH))
VERSION ?= main
DOCKER_TAG ?= $(subst /,-,$(VERSION))
TOOLS_DIR = tools
ALL_TOOLS = $(shell find tools -type f -wholename \*/manifest.yaml | cut -d/ -f1-2 | sort)
ALL_TOOLS_RAW = $(subst tools/,,$(ALL_TOOLS))
TOOLS ?= $(shell find tools -type f -wholename \*/manifest.yaml | cut -d/ -f1-2 | sort)
TOOLS_RAW ?= $(subst tools/,,$(TOOLS))
PREFIX ?= /uniget_bootstrap
TARGET ?= /usr/local
# Pre-defined colors: https://github.com/moby/buildkit/blob/master/util/progress/progressui/colors.go
BUILDKIT_COLORS ?= run=light-blue:warning=yellow:error=red:cancel=255,165,0
NO_COLOR ?= ""
OWNER ?= uniget-org
PROJECT ?= tools
REGISTRY ?= ghcr.io
REPOSITORY_PREFIX ?= $(OWNER)/$(PROJECT)/
HELPER = helper
BIN = $(HELPER)/usr/local/bin
export PATH := $(BIN):$(PATH)
SUPPORTED_ARCH := x86_64 aarch64
SUPPORTED_ALT_ARCH := amd64 arm64
ARCH ?= $(shell uname -m)
ifeq ($(ARCH),x86_64)
ALT_ARCH := amd64
endif
ifeq ($(ARCH),aarch64)
ALT_ARCH := arm64
endif
ifndef ALT_ARCH
$(error ERROR: Unable to determine alternative name for architecture ($(ARCH)))
endif
check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Undefined $1$(if $2, ($2))))
.PHONY:
all: $(ALL_TOOLS_RAW)
.PHONY:
info: ; $(info $(M) Runtime info...)
@echo "BUILDKIT_COLORS: $(BUILDKIT_COLORS)"
@echo "NO_COLOR: $(NO_COLOR)"
@echo "GIT_BRANCH: $(GIT_BRANCH)"
@echo "GIT_COMMIT_SHA: $(GIT_COMMIT_SHA)"
@echo "VERSION: $(VERSION)"
@echo "DOCKER_TAG: $(DOCKER_TAG)"
@echo "OWNER: $(OWNER)"
@echo "PROJECT: $(PROJECT)"
@echo "REGISTRY: $(REGISTRY)"
@echo "REPOSITORY_PREFIX: $(REPOSITORY_PREFIX)"
@echo "TOOLS_RAW: $(TOOLS_RAW)"
@echo "SUPPORTED_ARCH: $(SUPPORTED_ARCH)"
@echo "SUPPORTED_ALT_ARCH: $(SUPPORTED_ALT_ARCH)"
@echo "ARCH: $(ARCH)"
@echo "ALT_ARCH: $(ALT_ARCH)"
.PHONY:
help:
@echo
@echo "General targets:"
@echo " all (default) Build all tools"
@echo " help Display help for targets"
@echo " clean Remove all temporary files"
@echo " metadata.json Generate inventory from tools/*/manifest.json"
@echo " metadata.json--build Build metadata image from @metadata/ and metadata.json"
@echo " metadata.json--push Push metadata image"
@echo " metadata.json--show Push metadata image"
@echo
@echo "Dependency management:"
@echo " renovate.json Generate from tools/*/manifest.json"
@echo " tools/<tool>/manifest.json Generate from tools/*/manifest.yaml"
@echo
@echo "Reflection:"
@echo " info Display configuration data"
@echo " list List available tools"
@echo " size Display storage usage"
@echo " <tool>--show Display directory contents"
@echo
@echo "Building:"
@echo " tools/<tool>/Dockerfile Generate from tools/*/Dockerfile.template"
@echo " base Build base container image for all tool installations"
@echo " <tool> Build container image for specific tool"
@echo " <tool>--debug Build container image specific tool and enter shell"
@echo " <tool>--test Test a tool in a container image"
@echo " <tool>--deep Build container image including all dependencies"
@echo " debug Enter shell in base image"
@echo " push Push all container images"
@echo " <tool>--push Push container image for specific tool"
@echo " <tool>--inspect Inspect pushed container image for specific tool"
@echo " tag-usage Show how many times the tag is used"
@echo " assert-no-hardcoded-version Display tools with hardcoded versions"
@echo
@echo "Security:"
@echo " cosign.key Create cosign key pair"
@echo " metadata.json--sign Sign metadata container image"
@echo " sign Sign all container images"
@echo " <tool>--sign Sign container image for specific tool"
@echo " sbom Create SBoM for all tools"
@echo " <tool>--sbom Create SBoM for a specific tool"
@echo " tools/<tool>/sbom.json Create SBoM for specific tool"
@echo " <tool>--scan Scan SBoM for vulnerabilities"
@echo " attest Attest SBoM for all tools"
@echo " <tool>--attest Attest SBoM for specific tool"
@echo " install Push, sign and attest all container images"
@echo " <tool>--install Push, sign and attest container image for specific tool"
@echo
@echo "Git operations:"
@echo " recent Show tools changed in the last 3 days"
@echo " recent-days--<N> Show tools changed in the last <N> days"
@echo
@echo "Helper tools:"
@echo " $(HELPER)/var/lib/uniget/manifests/<tool>.json"
@echo " Install specified tool to helper/"
@echo
@echo "GHCR:"
@echo " clean-registry-untagged Remove all untagged container images"
@echo " clean-ghcr-unused--<tool> Remove a tag on all container images"
@echo " ghcr-orphaned List container image without a tools/<tool>/manifest.yaml"
@echo " ghcr-exists--<tool> Check is a container image exists"
@echo " ghcr-exists Check if all container images exist"
@echo " ghcr-inspect List tags for all container images"
@echo " <tool>--ghcr-tags Display tags for a container image"
@echo " <tool>--ghcr-inspect Display API object for a container image"
@echo " delete-ghcr--<tool> Delete container image"
@echo " ghcr-private List all private container images"
@echo
@echo "Reminder: foo-% => \$$@=foo-bar \$$*=bar"
@echo
@echo "Only some tools: TOOLS_RAW=\$$(jq -r '.tools[].name' metadata.json | grep ^k | xargs echo) make info"
@echo
.PHONY:
clean:
@set -o errexit; \
rm -f metadata.json; \
rm -rf helper; \
for TOOL in $(ALL_TOOLS_RAW); do \
rm -f \
$(TOOLS_DIR)/$${TOOL}/manifest.json \
$(TOOLS_DIR)/$${TOOL}/Dockerfile \
$(TOOLS_DIR)/$${TOOL}/build.log \
$(TOOLS_DIR)/$${TOOL}/sbom.json; \
done
.PHONY:
list:
@echo "$(ALL_TOOLS_RAW)"
.PHONY:
$(addsuffix --show,$(ALL_TOOLS_RAW)):%--show: $(TOOLS_DIR)/$*
@ls -l $(TOOLS_DIR)/$*
-include .env.mk
include make/dev.mk
include make/metadata.mk
include make/tool.mk
include make/sbom.mk
include make/ghcr.mk
include make/helper.mk