-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
195 lines (152 loc) · 6.82 KB
/
Makefile
File metadata and controls
195 lines (152 loc) · 6.82 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# Image URL to use all building/pushing image targets
IMG ?= qalisa/github-actions-secrets-operator:latest
#
EXPECTED_GH_PRIV_KEY_FILE = $(shell pwd)/src/github-privateKey.pem
CLUSTER_NAME = operator-dev
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.PHONY: all
all: build
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk command is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development Setup
.PHONY: setup-dev
setup-dev: install-go install-kubebuilder install-tools ## Install all development dependencies
.PHONY: install-go
install-go: ## Install Go using brew
brew install go
.PHONY: install-kubebuilder
install-kubebuilder: install-go ## Install Kubebuilder
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/$$(go env GOOS)/$$(go env GOARCH) && \
chmod +x kubebuilder && \
sudo mv kubebuilder /usr/local/bin/
.PHONY: install-tools
install-tools: ## Install required tools using brew
brew install kind golangci-lint helm
.PHONY: lint
lint: ## Run golangci-lint
cd src && golangci-lint run
##@ Development
.PHONY: generate-all
generate-all: generate-helpers generate-crds
.PHONY: generate-crds
generate-crds: controller-gen ## Generate CRDs (only run this when API changes)
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./src/..." output:crd:artifacts:config=charts/github-actions-secrets-operator/crds
.PHONY: generate-helpers
generate-helpers: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="./src/hack/boilerplate.go.txt" paths="./src/..."
.PHONY: fmt
fmt: ## Run go fmt against code.
cd src && go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
cd src && go vet ./...
##@ Build
.PHONY: build
build: fmt vet ## Build manager binary.
cd src && go build -o bin/manager cmd/main.go
.PHONY: pre-run
pre-run: # checks
@if [ ! -f src/.env ]; then \
echo "Error: src/.env file is required" >&2; \
exit 1; \
fi
@if ! grep -q "GITHUB_APP_ID=" src/.env || \
! grep -q "GITHUB_INSTALLATION_ID=" src/.env ; then \
echo "Error: .env must contain GITHUB_APP_ID and GITHUB_INSTALLATION_ID" >&2; \
exit 1; \
fi
@if [ ! -f ${EXPECTED_GH_PRIV_KEY_FILE} ]; then \
echo "Error: Private key is expected in ${EXPECTED_GH_PRIV_KEY_FILE}" >&2; \
exit 1; \
fi
.PHONY: run
run: pre-run fmt vet ## Run a controller from your host.
source src/.env && cd src && GITHUB_PRIVATE_KEY_PATH=${EXPECTED_GH_PRIV_KEY_FILE} go run ./cmd/main.go
# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
cd src && docker build -t ${IMG} .
.PHONY: kind-create
kind-create: ## Create kind cluster for local development
@if kind get clusters | grep -q "^${CLUSTER_NAME}$$"; then \
echo "Cluster '${CLUSTER_NAME}' already exists. Skipping creation."; \
else \
kind create cluster --name ${CLUSTER_NAME} --config kind-config.yaml || true; \
fi
.PHONY: kind-delete
kind-delete: ## Delete kind cluster
kind delete cluster --name ${CLUSTER_NAME}
.PHONY: docker-load
docker-load: docker-build ## Load docker image into kind cluster.
kind load docker-image ${IMG} --name ${CLUSTER_NAME}
.PHONY: docker-push
docker-push: docker-build ## Push docker image with the manager.
docker push ${IMG}
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: install-crds
install-crds: ## Install CRDs into the K8s cluster specified in ~/.kube/config.
kubectl apply -f charts/github-actions-secrets-operator/crds/
.PHONY: uninstall-crds
uninstall-crds: ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
kubectl delete --ignore-not-found=$(ignore-not-found) -f charts/github-actions-secrets-operator/crds/
.PHONY: deploy-without-image
deploy-without-image: kind-create generate-all install-crds
.PHONY: deploy
deploy: pre-run deploy-without-image docker-load ## Deploy controller to the K8s cluster specified in ~/.kube/config.
source src/.env && helm upgrade --install github-actions-secrets-operator charts/github-actions-secrets-operator \
--set image.repository=$(shell echo ${IMG} | cut -f1 -d:) \
--set image.tag=$(shell echo ${IMG} | cut -f2 -d:) \
--set github.appId="$$GITHUB_APP_ID" \
--set github.installationId="$$GITHUB_INSTALLATION_ID" \
--set github.privateKey.explicit="$$(cat ${EXPECTED_GH_PRIV_KEY_FILE})"
.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
helm uninstall github-actions-secrets-operator
##@ Build Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/src/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.17.2
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: helm-docs
helm-docs: ## Generate Helm chart documentation
docker run --rm --volume "$(PWD):/helm-docs" -u $(shell id -u) jnorwood/helm-docs:latest
##@ Samples
.PHONY: apply-samples
apply-samples: ## Apply sample CRDs to the cluster
kubectl apply -f config/samples/ns.yaml
kubectl apply -f config/samples/