Skip to content

Commit

Permalink
Refactor makefile (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
trstringer authored Mar 9, 2024
1 parent 38976b6 commit 58278db
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 113 deletions.
179 changes: 85 additions & 94 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,72 +25,63 @@ DB_HOST=localhost
DB_APP_USER=shoppingcartuser
DB_PASSWORD=secretdbpassword123

.PHONY: build
build: build-cart build-users
.PHONY: run-local
run-local: kind-create install-tools-and-app-local

.PHONY: build-cart
build-cart:
mkdir -p ./dist
go build -o ./dist/cart ./cmd/cart
.PHONY: kind-create
kind-create:
./scripts/kind_with_registry.sh

.PHONY: build-users
build-users:
mkdir -p ./dist
go build -o ./dist/users ./cmd/users
.PHONY: stop-local
stop-local:
kind delete cluster

.PHONY: build-images
build-images: collector-custom-build
docker build -t $(CART_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.cart .
docker build -t $(COLLECTOR_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.collector .
docker build -t $(DATASEED_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.dataseed .
docker build -t $(INTERRUPTER_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.interrupter .
docker build -t $(PRICE_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.price .
docker build -t $(TRAFFICGEN_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.trafficgen .
docker build -t $(USERS_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.users .
.PHONY: stop-trafficgen
stop-trafficgen:
kubectl patch deploy trafficgen -p '{"spec": {"replicas": 0}}'

.PHONY: push-images
push-images:
docker push $(CART_IMAGE_REPO):$(IMAGE_TAG)
docker push $(USERS_IMAGE_REPO):$(IMAGE_TAG)
docker push $(PRICE_IMAGE_REPO):$(IMAGE_TAG)
docker push $(DATASEED_IMAGE_REPO):$(IMAGE_TAG)
docker push $(COLLECTOR_IMAGE_REPO):$(IMAGE_TAG)
docker push $(TRAFFICGEN_IMAGE_REPO):$(IMAGE_TAG)
docker push $(INTERRUPTER_IMAGE_REPO):$(IMAGE_TAG)
.PHONY: install-tools-and-app
install-tools-and-app: install-tools install-app

.PHONY: clean
clean: kind-clean
rm -rf ./dist
rm -rf ./collector/dist
.PHONY: install-tools-and-app-local
install-tools-and-app-local: install-tools-local install-app-local

.PHONY: run-local-database
run-local-database:
./scripts/database_run_local.sh
.PHONY: install-tools-local
install-tools-local: install-cert-manager install-jaeger install-kube-prometheus-stack install-opentelemetry-operator install-opentelemetry-collector-local

.PHONY: stop-local-database
stop-local-database:
docker kill $(DB_CONTAINER_NAME)
.PHONY: install-tools
install-tools: install-cert-manager install-jaeger install-kube-prometheus-stack install-opentelemetry-operator install-opentelemetry-collector

.PHONY: deploy
deploy: kind-deploy app-install-local
.PHONY: install-cert-manager
install-cert-manager:
./scripts/cert-manager_install.sh

.PHONY: kind-create
kind-create:
./scripts/kind_with_registry.sh
.PHONY: install-jaeger
install-jaeger:
./scripts/jaeger_install.sh

.PHONY: kind-deploy
kind-deploy: kind-create build-images push-images jaeger-deploy kube-prometheus-stack-deploy otel-deploy-local
.PHONY: install-kube-prometheus-stack
install-kube-prometheus-stack:
./scripts/kube-prometheus-stack_install.sh

.PHONY: kind-clean
kind-clean:
kind delete cluster
.PHONY: install-opentelemetry-operator
install-opentelemetry-operator:
./scripts/opentelemetry_operator_install.sh

.PHONY: app-install-local
app-install-local:
helm upgrade --install otel-shopping-cart ./charts/otel-shopping-cart
.PHONY: install-opentelemetry-collector-local
install-opentelemetry-collector-local:
helm upgrade --install otel ./collector/opentelemetry

.PHONY: install-opentelemetry-collector
install-opentelemetry-collector:
helm upgrade \
--install \
--set collector.image.repository=ghcr.io/trstringer/otel-shopping-cart-collector \
otel \
./collector/opentelemetry

.PHONY: app-install
app-install:
.PHONY: install-app
install-app:
helm upgrade \
--install \
--set cart.image.repository=ghcr.io/trstringer/otel-shopping-cart-cart \
Expand All @@ -102,52 +93,48 @@ app-install:
otel-shopping-cart \
./charts/otel-shopping-cart

.PHONY: app-install-with-tools
app-install-with-tools: jaeger-deploy kube-prometheus-stack-deploy app-install

.PHONY: collector-custom-build
collector-custom-build:
ocb --config ./collector/manifest.yaml

.PHONY: jaeger-deploy
jaeger-deploy:
./scripts/jaeger_install.sh

.PHONY: otel-install
otel-install:
./scripts/otel_install.sh
.PHONY: install-app-local
install-app-local: build-images push-images
helm upgrade --install otel-shopping-cart ./charts/otel-shopping-cart

.PHONY: otel-deploy-local
otel-deploy-local: otel-install
helm upgrade --install otel ./collector/opentelemetry
.PHONY: build-images
build-images: build-collector
docker build -t $(CART_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.cart .
docker build -t $(COLLECTOR_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.collector .
docker build -t $(DATASEED_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.dataseed .
docker build -t $(INTERRUPTER_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.interrupter .
docker build -t $(PRICE_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.price .
docker build -t $(TRAFFICGEN_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.trafficgen .
docker build -t $(USERS_IMAGE_REPO):$(IMAGE_TAG) -f ./dockerfiles/Dockerfile.users .

.PHONY: otel-deploy
otel-deploy: otel-install
helm upgrade \
--install \
--set collector.image.repository=ghcr.io/trstringer/otel-shopping-cart-collector \
otel \
./collector/opentelemetry
.PHONY: build-collector
build-collector:
ocb --config ./collector/manifest.yaml

.PHONY: kube-prometheus-stack-deploy
kube-prometheus-stack-deploy:
./scripts/kube-prometheus-stack_install.sh
.PHONY: push-images
push-images:
docker push $(CART_IMAGE_REPO):$(IMAGE_TAG)
docker push $(USERS_IMAGE_REPO):$(IMAGE_TAG)
docker push $(PRICE_IMAGE_REPO):$(IMAGE_TAG)
docker push $(DATASEED_IMAGE_REPO):$(IMAGE_TAG)
docker push $(COLLECTOR_IMAGE_REPO):$(IMAGE_TAG)
docker push $(TRAFFICGEN_IMAGE_REPO):$(IMAGE_TAG)
docker push $(INTERRUPTER_IMAGE_REPO):$(IMAGE_TAG)

.PHONY: jaeger-port-forward
jaeger-port-forward:
.PHONY: port-forward-jaeger
port-forward-jaeger:
kubectl port-forward svc/jaeger-query 16686
@echo "Navigate to http://localhost:16686"

.PHONY: grafana-port-forward
grafana-port-forward:
.PHONY: port-forward-grafana
port-forward-grafana:
kubectl port-forward svc/prometheus-grafana 8080:80
@echo "Navigate to http://localhost:8080"

.PHONY: prometheus-port-forward
prometheus-port-forward:
.PHONY: port-forward-prometheus
port-forward-prometheus:
kubectl port-forward svc/prometheus-kube-prometheus-prometheus 9090

.PHONY: trafficgen-stop
trafficgen-stop:
kubectl patch deploy trafficgen -p '{"spec": {"replicas": 0}}'
@echo "Navigate to http://localhost:9090"

.PHONY: e2e
e2e:
Expand All @@ -157,10 +144,14 @@ e2e:
deps:
./scripts/dependencies.sh

.PHONY: version-with-commit
version-with-commit:
@./scripts/version.py --withcommit

.PHONY: version
version:
@./scripts/version.py

.PHONY: run-local-database
run-local-database:
./scripts/database_run_local.sh

.PHONY: stop-local-database
stop-local-database:
docker kill $(DB_CONTAINER_NAME)
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ There are a few ways to "use" the application...
If you want to run _everything_ in a local [kind](https://kind.sigs.k8s.io/) cluster:

```bash
make deploy
make run-local
```

Local dependencies:
Expand All @@ -25,19 +25,25 @@ Local dependencies:
If you already have a Kubernetes cluster and you want the application and observability tooling:

```bash
make app-install-with-tools
make install-tools-and-app
```

Local dependency: [helm](https://helm.sh/docs/intro/install/)

If you want _just_ the application:

```bash
make app-install
make install-app
```

Local dependency: [helm](https://helm.sh/docs/intro/install/)

And finally, if you want just the observability tooling:

```bash
make install-tools
```

## Viewing telemetry

Once everything is installed, you should be able to view the traces through Jaeger. If you installed Jaeger either with `make deploy` or `make app-install-with-tools` you can port-forward:
Expand Down
9 changes: 9 additions & 0 deletions scripts/cert-manager_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.3/cert-manager.yaml
while kubectl get po -n cert-manager --no-headers | grep -v Running; do
echo "Waiting for cert-manager to come up..."
sleep 5
done
sleep 10
echo "cert-manager is up"
27 changes: 17 additions & 10 deletions scripts/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ if ! make kind-create; then
echo "Failed to make kind"
exit 1
fi
make clean
make stop-local

if ! make deploy; then
if ! make run-local; then
echo "Failed deploy"
exit 1
fi
Expand All @@ -20,13 +20,20 @@ until ! kubectl get po -A | grep ContainerCreating; do
done

sleep 60

if kubectl get po -A --no-headers | grep -v Running | grep -v Completed; then
MAX_ITERATIONS=20
CURRENT_ITERATION=1
while [[ $CURRENT_ITERATION -le $MAX_ITERATIONS ]]; do
echo "Iteration $CURRENT_ITERATION of $MAX_ITERATIONS"
if ! kubectl get po -A --no-headers | grep -v Running | grep -v Completed; then
echo "Cluster successfully running"
make stop-local
exit
fi
echo "Found pods in a state other than Running or Completed"
kubectl get po -A --no-headers | grep -v Running | grep -v Completed |
awk '{print $2}' | xargs -rn 1 kubectl logs
exit 1
fi
CURRENT_ITERATION=$((CURRENT_ITERATION + 1))
sleep 10
done

echo "Cluster successfully running"
make clean
echo "Cluster not successfully running"
make stop-local
exit 1
10 changes: 4 additions & 6 deletions scripts/jaeger_install.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#!/bin/bash

kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.3/cert-manager.yaml

kubectl create namespace observability
JAEGER_OPERATOR_URI="https://github.com/jaegertracing/jaeger-operator/releases/download/v1.49.0/jaeger-operator.yaml"
until kubectl create -f "$JAEGER_OPERATOR_URI" -n observability; do
kubectl delete -f "$JAEGER_OPERATOR_URI" -n observability
echo Waiting for cert-manager to be ready for jaeger
sleep 10
echo "Waiting for jaeger operator to come up..."
sleep 5
done

until kubectl create -f ./kubernetes/jaeger.yaml; do
echo Waiting for jaeger to be installed
sleep 10
echo "Waiting for jaeger to install successfully..."
sleep 5
done
File renamed without changes.

0 comments on commit 58278db

Please sign in to comment.