Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline the Development Environment Setup. #1057

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions Makefile
Expand Up @@ -195,3 +195,20 @@ clean: ## Clean build artifacts

# Code generation
include $(BASE_DIR)/hack/inc.Codegen.mk

# init_local_prereqs is a special target that is used to realize the prerequisites for a Triggermesh Install
# in a local Docker Desktop Kubernetes environment. It is not intended to be used in production.
init_local_prereqs:
@./hack/scripts/DockerDesktopInitPrerequisites.sh

# init_local_dev is a special target that is used to realize the prerequisites for a Triggermesh Install.
# This target first builds Triggermesh from the local files, and then deploy the stack in a local Docker
# Desktop Kubernetes environment. This is not intended to be used in production.
init_local_dev:
@./hack/scripts/DockerDesktopInitPrerequisites.sh
@ko apply -f config/

# init_local_release is a special target that is used to realize the prerequisites for a Triggermesh Install, and
# then deploy the latest release of the Triggermesh stack in a local Docker Desktop Kubernetes environment. This is not intended to be used in production.
init_local_release:
@./hack/scripts/DockerDesktopInstallLatestRelease.sh
30 changes: 30 additions & 0 deletions README.md
Expand Up @@ -36,6 +36,36 @@ kubectl apply -f https://github.com/triggermesh/triggermesh/releases/latest/down

Please refer to our [guidelines for contributors](CONTRIBUTING.md).

### Setting up a Local Development Environment For Testing and Development

The following section describes how to quickly set up a local development environment for testing and development with Docker Desktop.

**Note** In this guide/example we are using Docker Desktop as our enviorment of choice, however, any Kubernetes cluster can be used.

### Prerequisites

- golang
- kubectl
- Docker Desktop (with Kubernetes enabled)
- ko

### Deploying a Local Development Environment (From the Latest Release)

```shell
make init_local_release
```
### Deploying a Local Development Environment (From Source)

```shell
make init_local_dev
```

### Realize the Prerequisites, WIHOUT Deploying Triggermesh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Realize the Prerequisites, WIHOUT Deploying Triggermesh
### Realize the Prerequisites, WITHOUT Deploying Triggermesh


```shell
make init_local_prereqs
```

## Commercial Support

TriggerMesh Inc. offers commercial support for the TriggerMesh platform. Email us at <info@triggermesh.com> to get more
Expand Down
144 changes: 144 additions & 0 deletions hack/scripts/DockerDesktopInitPrerequisites.sh
@@ -0,0 +1,144 @@
# !/usr/bin/env bash
KNATIVE_NET=${KNATIVE_NET:-kourier}
KNATIVE_VERSION=${KNATIVE_VERSION:-1.2.2}
KNATIVE_EVENTING_VERSION=${KNATIVE_EVENTING_VERSION:-1.2.0}
NAMESPACE=${NAMESPACE:-default}
BROKER_NAME=${BROKER_NAME:-default}
KNATIVE_NET_KOURIER_VERSION=${KNATIVE_NET_KOURIER_VERSION:-1.2.0}
TRIGGERMESH_VERSION=${TRIGGERMESH_VERSION:-v1.20.0}

set -eo pipefail
set -u

echo -e "Switching to docker-desktop kubectl context"
kubectl config use-context docker-desktop

STARTTIME=$(date +%s)
echo -e "🍿 Installing Knative Serving... \033[0m"

n=0
set +e
until [ $n -ge 2 ]; do
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v${KNATIVE_VERSION}/serving-crds.yaml > /dev/null && break
echo "Serving CRDs failed to install on first try"
n=$[$n+1]
sleep 5
done
set -e
kubectl wait --for=condition=Established --all crd > /dev/null

n=0
set +e
until [ $n -ge 2 ]; do
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v${KNATIVE_VERSION}/serving-core.yaml > /dev/null && break
echo "Serving Core failed to install on first try"
n=$[$n+1]
sleep 5
done
set -e
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n knative-serving > /dev/null

echo -e "🔌 Installing Knative Serving Networking Layer ${KNATIVE_NET}... \033[0m"

## INSTALL KOURIER
n=0
until [ $n -ge 3 ]; do
kubectl apply -f https://github.com/knative-sandbox/net-kourier/releases/download/knative-v${KNATIVE_NET_KOURIER_VERSION}/kourier.yaml > /dev/null && break
echo "Kourier failed to install on first try"
n=$[$n+1]
sleep 10
done
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n kourier-system > /dev/null
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n knative-serving > /dev/null

# Configure Knative to use this ingress
kubectl patch configmap/config-network \
--namespace knative-serving \
--type merge \
--patch '{"data":{"ingress.class":"kourier.ingress.networking.knative.dev"}}'

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
name: kourier-ingress
namespace: kourier-system
labels:
networking.knative.dev/ingress-provider: kourier
spec:
type: NodePort
selector:
app: 3scale-kourier-gateway
ports:
- name: http2
nodePort: 31080
port: 80
targetPort: 8080
EOF

# Setup Knative DOMAIN DNS
INGRESS_HOST=$(kubectl -n kourier-system get service kourier -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
if [ -z $INGRESS_HOST ]; then INGRESS_HOST=$(kubectl -n kourier-system get service kourier -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'); fi
while [ -z $INGRESS_HOST ]; do
sleep 5
INGRESS_HOST=$(kubectl -n kourier-system get service kourier -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
if [ -z $INGRESS_HOST ]; then INGRESS_HOST=$(kubectl -n kourier-system get service kourier -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'); fi
done

if [ "$INGRESS_HOST" == "localhost" ]; then INGRESS_HOST=127.0.0.1; fi

KNATIVE_DOMAIN=$INGRESS_HOST.sslip.io
kubectl patch configmap -n knative-serving config-domain -p "{\"data\": {\"$KNATIVE_DOMAIN\": \"\"}}"

echo -e "🔥 Installing Knative Eventing... \033[0m"
n=0
until [ $n -ge 2 ]; do
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v${KNATIVE_EVENTING_VERSION}/eventing-crds.yaml > /dev/null && break
echo "Eventing CRDs failed to install on first try"
n=$[$n+1]
sleep 5
done
kubectl wait --for=condition=Established --all crd > /dev/null
n=0
until [ $n -ge 2 ]; do
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v${KNATIVE_EVENTING_VERSION}/eventing-core.yaml > /dev/null && break
echo "Eventing Core failed to install on first try"
n=$[$n+1]
sleep 5
done
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n knative-eventing > /dev/null
n=0
until [ $n -ge 2 ]; do
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v${KNATIVE_EVENTING_VERSION}/in-memory-channel.yaml > /dev/null && break
echo "Eventing Memory Channel failed to install on first try"
n=$[$n+1]
sleep 5
done
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n knative-eventing > /dev/null
n=0
until [ $n -ge 2 ]; do
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v${KNATIVE_EVENTING_VERSION}/mt-channel-broker.yaml > /dev/null && break
echo "Eventing MT Memory Broker failed to install on first try"
n=$[$n+1]
sleep 5
done
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n knative-eventing > /dev/null

kubectl apply -f - <<EOF
apiVersion: eventing.knative.dev/v1
kind: broker
metadata:
name: ${BROKER_NAME}
namespace: ${NAMESPACE}
EOF

echo -e "🦾 Installing Triggermesh ... \033[0m"
echo "Setting up Triggermesh"
# kubectl apply -f https://github.com/triggermesh/triggermesh/releases/download/${TRIGGERMESH_VERSION}/triggermesh-crds.yaml
# kubectl wait --for=condition=Established --all crd
# kubectl apply -f https://github.com/triggermesh/triggermesh/releases/download/${TRIGGERMESH_VERSION}/triggermesh.yaml
# kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n triggermesh
# kubectl -n ${NAMESPACE} get broker ${BROKER_NAME}
DURATION=$(($(date +%s) - $STARTTIME))
echo -e "\033[0;92m 🚀 Triggermesh prerequiste install took: $(($DURATION / 60))m$(($DURATION % 60))s \033[0m"
echo -e "\033[0;92m 🎉 Now have some fun developing Serverless and Event Driven Apps \033[0m"
144 changes: 144 additions & 0 deletions hack/scripts/DockerDesktopInstallLatestRelease.sh
@@ -0,0 +1,144 @@
# !/usr/bin/env bash
KNATIVE_NET=${KNATIVE_NET:-kourier}
KNATIVE_VERSION=${KNATIVE_VERSION:-1.2.2}
KNATIVE_EVENTING_VERSION=${KNATIVE_EVENTING_VERSION:-1.2.0}
NAMESPACE=${NAMESPACE:-default}
BROKER_NAME=${BROKER_NAME:-default}
KNATIVE_NET_KOURIER_VERSION=${KNATIVE_NET_KOURIER_VERSION:-1.2.0}
TRIGGERMESH_VERSION=${TRIGGERMESH_VERSION:-v1.20.0}

set -eo pipefail
set -u

echo -e "Switching to docker-desktop kubectl context"
kubectl config use-context docker-desktop

STARTTIME=$(date +%s)
echo -e "🍿 Installing Knative Serving... \033[0m"

n=0
set +e
until [ $n -ge 2 ]; do
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v${KNATIVE_VERSION}/serving-crds.yaml > /dev/null && break
echo "Serving CRDs failed to install on first try"
n=$[$n+1]
sleep 5
done
set -e
kubectl wait --for=condition=Established --all crd > /dev/null

n=0
set +e
until [ $n -ge 2 ]; do
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v${KNATIVE_VERSION}/serving-core.yaml > /dev/null && break
echo "Serving Core failed to install on first try"
n=$[$n+1]
sleep 5
done
set -e
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n knative-serving > /dev/null

echo -e "🔌 Installing Knative Serving Networking Layer ${KNATIVE_NET}... \033[0m"

## INSTALL KOURIER
n=0
until [ $n -ge 3 ]; do
kubectl apply -f https://github.com/knative-sandbox/net-kourier/releases/download/knative-v${KNATIVE_NET_KOURIER_VERSION}/kourier.yaml > /dev/null && break
echo "Kourier failed to install on first try"
n=$[$n+1]
sleep 10
done
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n kourier-system > /dev/null
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n knative-serving > /dev/null

# Configure Knative to use this ingress
kubectl patch configmap/config-network \
--namespace knative-serving \
--type merge \
--patch '{"data":{"ingress.class":"kourier.ingress.networking.knative.dev"}}'

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
name: kourier-ingress
namespace: kourier-system
labels:
networking.knative.dev/ingress-provider: kourier
spec:
type: NodePort
selector:
app: 3scale-kourier-gateway
ports:
- name: http2
nodePort: 31080
port: 80
targetPort: 8080
EOF

# Setup Knative DOMAIN DNS
INGRESS_HOST=$(kubectl -n kourier-system get service kourier -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
if [ -z $INGRESS_HOST ]; then INGRESS_HOST=$(kubectl -n kourier-system get service kourier -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'); fi
while [ -z $INGRESS_HOST ]; do
sleep 5
INGRESS_HOST=$(kubectl -n kourier-system get service kourier -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
if [ -z $INGRESS_HOST ]; then INGRESS_HOST=$(kubectl -n kourier-system get service kourier -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'); fi
done

if [ "$INGRESS_HOST" == "localhost" ]; then INGRESS_HOST=127.0.0.1; fi

KNATIVE_DOMAIN=$INGRESS_HOST.sslip.io
kubectl patch configmap -n knative-serving config-domain -p "{\"data\": {\"$KNATIVE_DOMAIN\": \"\"}}"

echo -e "🔥 Installing Knative Eventing... \033[0m"
n=0
until [ $n -ge 2 ]; do
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v${KNATIVE_EVENTING_VERSION}/eventing-crds.yaml > /dev/null && break
echo "Eventing CRDs failed to install on first try"
n=$[$n+1]
sleep 5
done
kubectl wait --for=condition=Established --all crd > /dev/null
n=0
until [ $n -ge 2 ]; do
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v${KNATIVE_EVENTING_VERSION}/eventing-core.yaml > /dev/null && break
echo "Eventing Core failed to install on first try"
n=$[$n+1]
sleep 5
done
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n knative-eventing > /dev/null
n=0
until [ $n -ge 2 ]; do
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v${KNATIVE_EVENTING_VERSION}/in-memory-channel.yaml > /dev/null && break
echo "Eventing Memory Channel failed to install on first try"
n=$[$n+1]
sleep 5
done
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n knative-eventing > /dev/null
n=0
until [ $n -ge 2 ]; do
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v${KNATIVE_EVENTING_VERSION}/mt-channel-broker.yaml > /dev/null && break
echo "Eventing MT Memory Broker failed to install on first try"
n=$[$n+1]
sleep 5
done
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n knative-eventing > /dev/null

kubectl apply -f - <<EOF
apiVersion: eventing.knative.dev/v1
kind: broker
metadata:
name: ${BROKER_NAME}
namespace: ${NAMESPACE}
EOF

echo -e "🦾 Installing Triggermesh ... \033[0m"
echo "Setting up Triggermesh"
kubectl apply -f https://github.com/triggermesh/triggermesh/releases/download/${TRIGGERMESH_VERSION}/triggermesh-crds.yaml
kubectl wait --for=condition=Established --all crd
kubectl apply -f https://github.com/triggermesh/triggermesh/releases/download/${TRIGGERMESH_VERSION}/triggermesh.yaml
kubectl wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n triggermesh
kubectl -n ${NAMESPACE} get broker ${BROKER_NAME}
DURATION=$(($(date +%s) - $STARTTIME))
echo -e "\033[0;92m 🚀 Triggermesh prerequiste install took: $(($DURATION / 60))m$(($DURATION % 60))s \033[0m"
echo -e "\033[0;92m 🎉 Now have some fun developing Serverless and Event Driven Apps \033[0m"