-
Notifications
You must be signed in to change notification settings - Fork 0
/
tekton_in_kind.sh
executable file
·146 lines (129 loc) · 4.89 KB
/
tekton_in_kind.sh
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
#!/usr/bin/env bash
set -e -o pipefail
declare TEKTON_PIPELINE_VERSION TEKTON_TRIGGERS_VERSION TEKTON_DASHBOARD_VERSION CONTAINER_RUNTIME
# This script deploys Tekton on a local kind cluster
# It creates a kind cluster and deploys pipeline, triggers and dashboard
# Prerequisites:
# - go 1.14+
# - podman or docker (recommended 8GB memory config)
# - kind
# Notes:
# - Latest versions will be installed if not specified
# - If a kind cluster named "tekton" already exists this will fail
# - Local access to the dashboard requires port 9097 to be locally available
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
# Read command line options
while getopts ":c:p:t:d:k" opt; do
case ${opt} in
c )
CLUSTER_NAME=$OPTARG
;;
p )
TEKTON_PIPELINE_VERSION=$OPTARG
;;
t )
TEKTON_TRIGGERS_VERSION=$OPTARG
;;
d )
TEKTON_DASHBOARD_VERSION=$OPTARG
;;
k )
CONTAINER_RUNTIME="docker"
;;
\? )
echo "Invalid option: $OPTARG" 1>&2
echo 1>&2
echo "Usage: tekton_in_kind.sh [-c cluster-name -p pipeline-version -t triggers-version -d dashboard-version [-k]"
;;
: )
echo "Invalid option: $OPTARG requires an argument" 1>&2
;;
esac
done
shift $((OPTIND -1))
# Check and defaults input params
export KIND_CLUSTER_NAME=${CLUSTER_NAME:-"tekton"}
if [ -z "$TEKTON_PIPELINE_VERSION" ]; then
TEKTON_PIPELINE_VERSION=$(get_latest_release tektoncd/pipeline)
fi
if [ -z "$TEKTON_TRIGGERS_VERSION" ]; then
TEKTON_TRIGGERS_VERSION=$(get_latest_release tektoncd/triggers)
fi
if [ -z "$TEKTON_DASHBOARD_VERSION" ]; then
TEKTON_DASHBOARD_VERSION=$(get_latest_release tektoncd/dashboard)
fi
if [ -z "$CONTAINER_RUNTIME" ]; then
CONTAINER_RUNTIME="podman"
fi
echo "===> Creating a Kind Cluster"
# create registry container unless it already exists
reg_name='kind-registry'
reg_port='5000'
running="$(${CONTAINER_RUNTIME} inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)"
if [ "${running}" != 'true' ]; then
# It may exists and not be running, so cleanup just in case
"$CONTAINER_RUNTIME" rm "${reg_name}" 2> /dev/null || true
# And start a new one
"$CONTAINER_RUNTIME" run \
-d --restart=always -p "${reg_port}:5000" --name "${reg_name}" \
registry:2
fi
# Create the kind cluster
# create a cluster with the local registry enabled in containerd
running_cluster=$(kind get clusters | grep tekton || true)
if [ "${running_cluster}" != "$KIND_CLUSTER_NAME" ]; then
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 8080
protocol: TCP
- containerPort: 443
hostPort: 8443
protocol: TCP
- role: worker
- role: worker
featureGates:
"EphemeralContainers": true
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
endpoint = ["http://${reg_name}:${reg_port}"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."${reg_name}:${reg_port}"]
endpoint = ["http://${reg_name}:${reg_port}"]
EOF
fi
# Populate the image cache in the background
for image in $(cat tekton/image-cache.txt) ; do
kind load docker-image $image --name ${KIND_CLUSTER_NAME} &> tekton/cache.log
done &
# connect the registry to the cluster network
# (the network may already be connected)
"$CONTAINER_RUNTIME" network connect "kind" "${reg_name}" || true
echo export TEKTON_PIPELINE_VERSION=$TEKTON_PIPELINE_VERSION
echo export TEKTON_TRIGGERS_VERSION=$TEKTON_TRIGGERS_VERSION
echo export TEKTON_DASHBOARD_VERSION=$TEKTON_DASHBOARD_VERSION
# Install Tekton Pipeline, Triggers and Dashboard
# kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/previous/${TEKTON_PIPELINE_VERSION}/release.yaml
# kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/previous/${TEKTON_TRIGGERS_VERSION}/release.yaml
# kubectl apply -f https://github.com/tektoncd/dashboard/releases/download/${TEKTON_DASHBOARD_VERSION}/tekton-dashboard-release.yaml
# if [ -f tekton/.secrets/icr.yaml ]; then
# kubectl create -f tekton/.secrets/icr.yaml -n tekton-pipelines || true
# kubectl patch serviceaccount tekton-pipelines-controller -n tekton-pipelines -p '{"imagePullSecrets": [{"name": "all-icr-io"}]}' || true
# fi
# # Wait until all pods are ready
# kubectl wait -n tekton-pipelines --for=condition=ready pods --all --timeout=120s
echo Tekton Dashboard available at http://localhost/dashboard/ after installation