Skip to content

Commit 83d9edd

Browse files
committed
Project Infrastructure
Updating Makefile targers accordingly and introducing new hack script to download external CRD files.
1 parent 2c49525 commit 83d9edd

File tree

5 files changed

+183
-25
lines changed

5 files changed

+183
-25
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
*.test
2-
triggers
1+
/bin/
2+
/*.out
3+
/*.test
4+
/triggers

.ko.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
defaultBaseImage: registry.access.redhat.com/ubi9/ubi-minimal:latest

Makefile

Lines changed: 99 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,131 @@
11
APP = triggers
22

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
310
IMAGE_BASE ?= ghcr.io/shipwright-io
411
IMAGE_TAG ?= latest
512

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
817

18+
# deployment target namespace, same default than Shipwright Build project
919
NAMESPACE ?= shipwright-build
1020

21+
# ko base image repository and options
1122
KO_DOCKER_REPO ?= $(IMAGE_BASE)
1223
KO_OPTS ?= --base-import-paths --tags=${IMAGE_TAG}
1324

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
1536

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
1940

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:
2148

2249
default: build
2350

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
2486
.PHONY: container-build
87+
container-build: CGO_ENABLED=0
2588
container-build:
26-
ko build --push=false ${KO_OPTS} .
89+
ko build --push=false $(KO_OPTS) $(ARGS) .
2790

91+
# uses helm to render kubernetes manifests and ko for the container image
2892
.PHONY: deploy
93+
deploy: CGO_ENABLED=0
2994
deploy:
3095
helm template \
3196
--namespace=$(NAMESPACE) \
3297
--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 -
35101

102+
# runs the unit tests, with optional arguments
36103
.PHONY: test-unit
104+
test-unit: CGO_ENABLED=1
37105
test-unit:
38-
go test $(GOFLAGS_TEST) ./...
106+
go test $(GOFLAGS_TEST) $(ARGS) ./pkg/... ./controllers/...
39107

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
40124
.PHONY: test-e2e
41125
test-e2e:
42126
echo "Not implemented"
43127

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)

PROJECT

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
projectName: triggers
3+
domain: triggers.shipwright.io
4+
repo: github.com/shipwright-io/triggers
5+
layout:
6+
- go.kubebuilder.io/v3
7+
version: "3"

hack/download-crds.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Downloads the Custom Resource Definitions direcly from the Build and Tekton's GitHub repositories,
4+
# using `curl` to manage this task.
5+
#
6+
7+
set -eu -o pipefail
8+
9+
# target shipwright version, by default uses the `main` revision
10+
SHIPWRIGHT_VERSION="${SHIPWRIGHT_VERSION:-main}"
11+
# target tekton version, by default uses the `main` revision
12+
TEKTON_VERSION="${TEKTON_VERSION:-main}"
13+
14+
# diretory where the files will be stored
15+
CRD_DIR="${CRD_DIR:-/var/tmp}"
16+
17+
readonly REPO_HOST="raw.githubusercontent.com"
18+
readonly SHIPWRIGHT_REPO_PATH="shipwright-io/build/${SHIPWRIGHT_VERSION}/deploy/crds"
19+
readonly TEKTON_REPO_PATH="tektoncd/pipeline/${TEKTON_VERSION}/config"
20+
21+
# list of shipwright crd files to be downloaded from the repository
22+
declare -a SHIPWRIGHT_CRD_FILES=(
23+
shipwright.io_buildruns.yaml
24+
shipwright.io_buildstrategies.yaml
25+
shipwright.io_builds.yaml
26+
shipwright.io_clusterbuildstrategies.yaml
27+
)
28+
29+
# list of tekton crd files to be downloaded from the repository
30+
declare -a TEKTON_CRD_FILES=(
31+
300-clustertask.yaml
32+
300-pipelinerun.yaml
33+
300-pipeline.yaml
34+
300-resolutionrequest.yaml
35+
300-resource.yaml
36+
300-run.yaml
37+
300-taskrun.yaml
38+
300-task.yaml
39+
)
40+
41+
# executes curl with flags against the informed url, saves the payload on the output directory
42+
function do_curl() {
43+
local URL_BASE="${1}"
44+
local FILENAME="${2}"
45+
curl \
46+
--location \
47+
--output "${CRD_DIR}/${FILENAME}" \
48+
--remote-header-name \
49+
--remote-name \
50+
--silent \
51+
"${URL_BASE}/${FILENAME}"
52+
}
53+
54+
# creates teh output directory, when it does not exists
55+
[[ -d "${CRD_DIR}" ]] || mkdir -p "${CRD_DIR}"
56+
57+
echo "# Shipwright '${SHIPWRIGHT_VERSION}' CRDs stored at: '${CRD_DIR}'"
58+
59+
for f in ${SHIPWRIGHT_CRD_FILES[@]}; do
60+
URL_BASE="https://${REPO_HOST}/${SHIPWRIGHT_REPO_PATH}"
61+
echo "# - ${URL_BASE}/${f}"
62+
do_curl "${URL_BASE}" "${f}"
63+
done
64+
65+
echo "# Tekton '${TEKTON_VERSION}' CRDs stored at: '${CRD_DIR}'"
66+
67+
for f in ${TEKTON_CRD_FILES[@]}; do
68+
URL_BASE="https://${REPO_HOST}/${TEKTON_REPO_PATH}"
69+
echo "# - ${URL_BASE}/${f}"
70+
do_curl "${URL_BASE}" "${f}"
71+
done

0 commit comments

Comments
 (0)