-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
158 lines (122 loc) · 5.48 KB
/
Copy pathMakefile
File metadata and controls
158 lines (122 loc) · 5.48 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
SERVER_VERSION ?= 1.18.0
GO_VERSION ?= 1.27.0
DATETIME := $(shell date -u +%Y-%m-%dT%T.%2NZ)
REGISTRY := quay.io
ORG := appzygy
ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
CHART_VERSION := $(shell grep '^version:' ${ROOT}/charts/ociregistry/Chart.yaml | awk '{print $$2}')
.PHONY : all
all:
@echo Run 'make help' to see a list of available targets
.PHONY: vartest
vartest:
@echo SERVER_VERSION=$(SERVER_VERSION)
@echo GO_VERSION=$(GO_VERSION)
@echo CHART_VERSION=$(CHART_VERSION)
.PHONY: go-install
go-install:
go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest
go install github.com/vladopajic/go-test-coverage/v2@latest
go install golang.org/x/vuln/cmd/govulncheck@latest
.PHONY: oapi-codegen # requires go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest
oapi-codegen:
oapi-codegen -config $(ROOT)/api/server.cfg.yaml $(ROOT)/api/ociregistry.yaml
oapi-codegen -config $(ROOT)/api/models.cfg.yaml $(ROOT)/api/ociregistry.yaml
.PHONY: test
test:
go test $(ROOT)/cmd/... $(ROOT)/impl/... $(ROOT)/mock/...\
-coverpkg ./... -covermode=atomic\
-v -cover -coverprofile=$(ROOT)/cover.out
.PHONY: coverage
coverage:
go tool cover -html=$(ROOT)/cover.out
.PHONY: update-modules
update-modules:
go get -u ./...
rm go.sum
sed -i '/\/\/ indirect/d' go.mod
go mod tidy
.PHONY: coverage-rpt
coverage-rpt: # requires go install github.com/vladopajic/go-test-coverage/v2@latest
go-test-coverage --config=$(ROOT)/.testcoverage.yml
.PHONY: vet
vet:
go vet $(ROOT)/cmd $(ROOT)/impl/... $(ROOT)/mock
.PHONY: vulncheck # requires go install golang.org/x/vuln/cmd/govulncheck@latest
vulncheck:
govulncheck -show verbose $(ROOT)/cmd/... $(ROOT)/impl/...
.PHONY: gocyclo
gocyclo:
gocyclo -over 15 -ignore "merge.go|_test|ociregistry.go" $(ROOT)/cmd $(ROOT)/impl/
.PHONY: server
server:
CGO_ENABLED=0 go build -ldflags "-X 'main.buildVer=$(SERVER_VERSION)' -X 'main.buildDtm=$(DATETIME)'"\
-a -o $(ROOT)/bin/ociregistry $(ROOT)/cmd/*.go
.PHONY: image
image:
docker buildx inspect ociregistry > /dev/null 2>&1 && docker buildx rm ociregistry || :
docker buildx create --name ociregistry --driver docker-container
docker buildx build --platform linux/arm64,linux/amd64\
--builder=ociregistry\
--push --provenance=false --sbom=false\
--tag $(REGISTRY)/$(ORG)/ociregistry:$(SERVER_VERSION)\
--build-arg SERVER_VERSION=$(SERVER_VERSION)\
--build-arg DATETIME=$(DATETIME)\
--build-arg GO_VERSION=$(GO_VERSION)\
$(ROOT)
.PHONY: old-image # save this for desktop testing
old-image:
docker buildx build --tag $(REGISTRY)/$(ORG)/ociregistry:$(SERVER_VERSION)\
--build-arg SERVER_VERSION=$(SERVER_VERSION)\
--build-arg DATETIME=$(DATETIME)\
--build-arg GO_VERSION=$(GO_VERSION)\
$(ROOT)
.PHONY: helm-docs # requires https://github.com/norwoodj/helm-docs
helm-docs:
helm-docs --chart-search-root $(ROOT)/charts
.PHONY: helm-package
helm-package:
helm package $(ROOT)/charts/ociregistry
.PHONY: helm-push
helm-push:
helm push $(ROOT)/ociregistry-$(CHART_VERSION).tgz oci://quay.io/appzygy/helm-charts
.PHONY: helm-artifacthub # requires https://oras.land/docs/installation/#linux
helm-artifacthub:
oras push\
quay.io/appzygy/helm-charts/ociregistry:artifacthub.io\
--config /dev/null:application/vnd.cncf.artifacthub.config.v1+yaml\
$(ROOT)/charts/artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml
.PHONY : help
help:
@echo "$$HELPTEXT"
export HELPTEXT
define HELPTEXT
This make file provides the following targets:
test Runs the unit tests.
vet Runs go vet.
go-install Runs go install for components needed locally.
vulncheck Runs govulncheck.
Requires 'go install golang.org/x/vuln/cmd/govulncheck@latest'.
gocyclo Runs gocyclo.
coverage Runs 'go tool cover' to show coverage of the most recent test run in a browser
window. (Does not run the unit tests.)
update-modules Runs 'go get -u' and 'go mod tidy'
coverage-rpt Creates a coverage report of the most recent test run. (Does not run the unit tests.)
Requires 'go install github.com/vladopajic/go-test-coverage/v2@latest'
oapi-codegen Generates go code in the 'api' directory from the 'ociregistry.yaml' open API
schema and configuration files in that directory.
Requires 'go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest'.
server Builds the server binary on your desktop. After building then run the server
on your desktop: 'bin/ociregistry --help' for testing. You can also run the server
binary as a systemd service. See the 'systemd-service' directory for more details.
image Builds the server '$(SERVER_VERSION)' OCI image and and pushes it to the
'$(REGISTRY)' OCI distribution server, in the '$(ORG)' user/org.
Requires the appropriate push permissions, of course.
helm-docs Builds the Helm chart README from values and the README template.
Requires 'go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest'.
helm-package Builds the Helm chart tarball.
helm-push Publishes the Helm chart to Quay.
helm-artifacthub Pushes Artifact hub verified publisher file to Quay.
Requires https://oras.land/docs/installation/#linux.
endef