|
1 | 1 | APP = triggers
|
2 | 2 |
|
| 3 | +# temporary directory to store auxiliary tools |
| 4 | +LOCAL_BIN ?= $(shell pwd)/bin |
| 5 | + |
| 6 | +# full path to the application executable |
| 7 | +BIN ?= $(LOCAL_BIN)/$(APP) |
| 8 | + |
| 9 | +# container image prefix, the final part and tag are appended afterwards |
3 | 10 | IMAGE_BASE ?= ghcr.io/shipwright-io
|
4 | 11 | IMAGE_TAG ?= latest
|
5 | 12 |
|
6 |
| -GOFLAGS ?= -v -mod=vendor -race |
7 |
| -GOFLAGS_TEST ?= -v -cover -race |
| 13 | +# golang flags and settings |
| 14 | +GOFLAGS ?= -v -a |
| 15 | +GOFLAGS_TEST ?= -v -race -cover |
| 16 | +CGO_ENABLED ?= 0 |
8 | 17 |
|
| 18 | +# deployment target namespace, same default than Shipwright Build project |
9 | 19 | NAMESPACE ?= shipwright-build
|
10 | 20 |
|
| 21 | +# ko base image repository and options |
11 | 22 | KO_DOCKER_REPO ?= $(IMAGE_BASE)
|
12 | 23 | KO_OPTS ?= --base-import-paths --tags=${IMAGE_TAG}
|
13 | 24 |
|
14 |
| -.EXPORT_ALL_VARIABLES: |
| 25 | +# controller-gen version and full path to the executable |
| 26 | +CONTROLLER_TOOLS_VERSION ?= v0.10.0 |
| 27 | +CONTROLLER_GEN ?= $(LOCAL_BIN)/controller-gen |
| 28 | + |
| 29 | +# envtest version and full path to the executable |
| 30 | +ENVTEST_K8S_VERSION ?= 1.23 |
| 31 | +ENVTEST ?= $(LOCAL_BIN)/setup-envtest |
| 32 | + |
| 33 | +# chart base directory and path to the "templates" folder |
| 34 | +CHART_DIR ?= ./chart |
| 35 | +MANIFEST_DIR ?= $(CHART_DIR)/generated |
15 | 36 |
|
16 |
| -.PHONY: $(APP) |
17 |
| -$(APP): |
18 |
| - go build . |
| 37 | +# shipwright and tekton target versions to download upstream crd resources |
| 38 | +SHIPWRIGHT_VERSION ?= v0.11.0 |
| 39 | +TEKTON_VERSION ?= v0.38.3 |
19 | 40 |
|
20 |
| -build: $(APP) |
| 41 | +# full path to the directory where the crds are downloaded |
| 42 | +CRD_DIR ?= $(LOCAL_BIN)/crds |
| 43 | + |
| 44 | +# generic arguments used on certain targets |
| 45 | +ARGS ?= |
| 46 | + |
| 47 | +.EXPORT_ALL_VARIABLES: |
21 | 48 |
|
22 | 49 | default: build
|
23 | 50 |
|
| 51 | +# ensure that the local "bin" directory exists |
| 52 | +$(LOCAL_BIN): |
| 53 | + @mkdir -p $(LOCAL_BIN) || true |
| 54 | + |
| 55 | +# builds the primary application executable |
| 56 | +.PHONY: $(BIN) |
| 57 | +build: $(BIN) |
| 58 | +$(BIN): $(LOCAL_BIN) |
| 59 | + go build -o $(BIN) . |
| 60 | + |
| 61 | +# downloads shipwright crds from upstream repository |
| 62 | +download-crds: $(CRD_DIR) |
| 63 | +$(CRD_DIR): |
| 64 | + ./hack/download-crds.sh |
| 65 | + |
| 66 | +# installs controller-gen in the local bin folder |
| 67 | +.PHONY: controller-gen |
| 68 | +controller-gen: GOBIN=$(LOCAL_BIN) |
| 69 | +controller-gen: $(CONTROLLER_GEN) |
| 70 | +$(CONTROLLER_GEN): |
| 71 | + go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) |
| 72 | + |
| 73 | +# generates all Kubernetes releated resources in the project |
| 74 | +.PHONY: manifests |
| 75 | +manifests: controller-gen |
| 76 | + $(CONTROLLER_GEN) \ |
| 77 | + rbac:roleName=shipwright-trigger crd paths="./..." \ |
| 78 | + output:dir=$(MANIFEST_DIR) |
| 79 | + |
| 80 | +# runs the manager from your host |
| 81 | +.PHONY: run |
| 82 | +run: manifests |
| 83 | + go run ./main.go $(ARGS) |
| 84 | + |
| 85 | +# builds the container image with ko without push to registry |
24 | 86 | .PHONY: container-build
|
| 87 | +container-build: CGO_ENABLED=0 |
25 | 88 | container-build:
|
26 |
| - ko build --push=false ${KO_OPTS} . |
| 89 | + ko build --push=false $(KO_OPTS) $(ARGS) . |
27 | 90 |
|
| 91 | +# uses helm to render kubernetes manifests and ko for the container image |
28 | 92 | .PHONY: deploy
|
| 93 | +deploy: CGO_ENABLED=0 |
29 | 94 | deploy:
|
30 | 95 | helm template \
|
31 | 96 | --namespace=$(NAMESPACE) \
|
32 | 97 | --set="image.name=ko://github.com/shipwright-io/triggers" \
|
33 |
| - ./chart | \ |
34 |
| - ko apply ${KO_OPTS} --filename - |
| 98 | + shipwright-triggers \ |
| 99 | + $(CHART_DIR) | \ |
| 100 | + ko apply $(KO_OPTS) $(ARGS) --filename - |
35 | 101 |
|
| 102 | +# runs the unit tests, with optional arguments |
36 | 103 | .PHONY: test-unit
|
| 104 | +test-unit: CGO_ENABLED=1 |
37 | 105 | test-unit:
|
38 |
| - go test $(GOFLAGS_TEST) ./... |
| 106 | + go test $(GOFLAGS_TEST) $(ARGS) ./pkg/... ./controllers/... |
39 | 107 |
|
| 108 | +# installs latest envtest-setup, if necessary |
| 109 | +.PHONY: envtest |
| 110 | +envtest: GOBIN=$(LOCAL_BIN) |
| 111 | +envtest: $(ENVTEST) |
| 112 | +$(ENVTEST): |
| 113 | + go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest |
| 114 | + |
| 115 | +# run integration tests, with optional arguments |
| 116 | +.PHONY: test-integration |
| 117 | +test-integration: CGO_ENABLED=1 |
| 118 | +test-integration: download-crds manifests envtest |
| 119 | + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" \ |
| 120 | + go test $(GOFLAGS_TEST) ./test/integration/... \ |
| 121 | + -coverprofile=integration.out -ginkgo.v $(ARGS) |
| 122 | + |
| 123 | +# run end-to-end tests |
40 | 124 | .PHONY: test-e2e
|
41 | 125 | test-e2e:
|
42 | 126 | echo "Not implemented"
|
43 | 127 |
|
44 |
| -.PHONY: verify-kind |
45 |
| -verify-kind: |
46 |
| - ./hack/verify-kind.sh |
47 |
| - |
48 |
| -.PHONY: install-registry |
49 |
| -install-registry: |
50 |
| - ./hack/install-registry.sh |
51 |
| - |
52 |
| -.PHONY: install-shipwright |
53 |
| -install-shipwright: |
54 |
| - ./hack/install-tekton.sh |
55 |
| - ./hack/install-shipwright.sh |
| 128 | +# runs act, with optional arguments |
| 129 | +.PHONY: act |
| 130 | +act: |
| 131 | + @act --secret="GITHUB_TOKEN=${GITHUB_TOKEN}" $(ARGS) |
0 commit comments