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

Nomad with Firmate Bot test #18

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dapr-distributed-calendar/hashicorp/local/log
86 changes: 86 additions & 0 deletions dapr-distributed-calendar/hashicorp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Get starting with Nomad, Consult Connect

## Start Nomad, Consul and Vault

```bash
> cd build/local
> ./start.sh
```

> Make sure you set start.sh with execute permission => `sudo chmod +x start.sh`

## Use Terraform to provisioning all services

```bash
> cd build/nomad
> terraform init
> terraform apply
```

## Clean Up

```bash
> cd build/nomad
> terraform destroy
> cd build/local
# Ctrl + C
```

Happy hacking with HashiCorp stack!!!

http://localhost:8500

Key/Value menu

dapr/daprConfig.yaml
dapr/components/consul.yaml
dapr/components/orderup_pubsub.yaml
dapr/components/barista_pubsub.yaml
dapr/components/kitchen_pubsub.yaml

Notes: host_ip normally is `172.17.0.3`

```bash
cd build/nomad/jobs
```

```bash
nomad job run traefik.nomad.hcl
nomad job run postgresdb.nomad.hcl
nomad job run redis.nomad.hcl

nomad job stop traefik
nomad job stop postgres-db
nomad job stop redis
nomad system gc
```

```bash
nomad job run product-api-dapr.nomad.hcl
nomad job stop product-api-dapr
nomad system gc
```

```bash
nomad job run counter-api-dapr.nomad.hcl
nomad job stop counter-api-dapr
nomad system gc
```

```bash
nomad job run barista-api-dapr.nomad.hcl
nomad job stop barista-api-dapr
nomad system gc
```

```bash
nomad job run kitchen-api-dapr.nomad.hcl
nomad job stop kitchen-api-dapr
nomad system gc
```

```bash
nomad job run reverse-proxy.nomad.hcl
nomad job stop reverse-proxy
nomad system gc
```
13 changes: 13 additions & 0 deletions dapr-distributed-calendar/hashicorp/components/barista_pubsub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: baristapubsub
namespace: default
spec:
type: pubsub.redis
version: v1
metadata:
- name: redisHost
value: redis:6379
- name: redisPassword
value: ""
14 changes: 14 additions & 0 deletions dapr-distributed-calendar/hashicorp/components/consul.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: consul
namespace: default
spec:
type: state.consul
version: v1
metadata:
- name: datacenter
value: dc1 # Required. Example: dc1
- name: httpAddr
value: 127.0.0.1:8500 # TODO update here 10.1.0.4:8500 # Required. Example: "consul.default.svc.cluster.local:8500"
26 changes: 26 additions & 0 deletions dapr-distributed-calendar/hashicorp/components/daprConfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: daprConfig
spec:
nameResolution:
component: "consul"
configuration:
selfRegister: true
client:
address: "127.0.0.1:8500" # TODO: update here "10.1.0.4:8500" # Required. Example: "consul.default.svc.cluster.local:8500"
checks:
- name: "Dapr Health Status"
checkID: "daprHealth: - ${APP_ID} - ${CONSUL_HTTP_ADDR}"
interval: "15s"
tcp: "127.0.0.1:8500" # TODO: update here "10.1.0.4:8500" # Required. Example: "consul.default.svc.cluster.local:8500"
tags:
- "dapr"
queryOptions:
useCache: true
filter: "Checks.ServiceTags contains dapr"
tracing:
samplingRate: "1"
zipkin:
endpointAddress: http://127.0.0.1:9411/api/v2/spans
13 changes: 13 additions & 0 deletions dapr-distributed-calendar/hashicorp/components/kitchen_pubsub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: kitchenpubsub
namespace: default
spec:
type: pubsub.redis
version: v1
metadata:
- name: redisHost
value: redis:6379
- name: redisPassword
value: ""
13 changes: 13 additions & 0 deletions dapr-distributed-calendar/hashicorp/components/orderup_pubsub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: orderuppubsub
namespace: default
spec:
type: pubsub.redis
version: v1
metadata:
- name: redisHost
value: redis:6379
- name: redisPassword
value: ""
24 changes: 24 additions & 0 deletions dapr-distributed-calendar/hashicorp/local/etc/consul.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// data_dir = "./data/consul"
node_name = "consul-server"
server = true
bootstrap = true

ui_config {
enabled = true
}

datacenter = "dc1"
// data_dir = "consul/data"
log_level = "INFO"

addresses {
http = "0.0.0.0"
}

connect {
enabled = true
}

// ports {
// grpc = 8502
// }
31 changes: 31 additions & 0 deletions dapr-distributed-calendar/hashicorp/local/etc/nomad.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
bind_addr = "0.0.0.0"
log_level = "DEBUG"
disable_update_check = true

# these settings allow Nomad to automatically find its peers through Consul
consul {
server_service_name = "nomad"
server_auto_join = true
client_service_name = "nomad-client"
client_auto_join = true
auto_advertise = true
}

server {
enabled = true
bootstrap_expect = 1
}

client {
enabled = true
options = {
"driver.blacklist" = "java"
}
}

// plugin "docker" {
// config {
// allow_privileged = true
// allow_runtimes = ["runc", "sysbox-runc"]
// }
// }
4 changes: 4 additions & 0 deletions dapr-distributed-calendar/hashicorp/local/install-consule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install consul
22 changes: 22 additions & 0 deletions dapr-distributed-calendar/hashicorp/local/install-nomad-consul.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
sudo apt-get update && sudo apt-get install wget gpg coreutils
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt-get update && sudo apt-get install nomad
sudo apt update && sudo apt install consul

# fix plugin error for working with consul
cd
curl -L -o cni-plugins.tgz "https://github.com/containernetworking/plugins/releases/download/v1.0.0/cni-plugins-linux-$( [ $(uname -m) = aarch64 ] && echo arm64 || echo amd64)"-v1.0.0.tgz
sudo mkdir -p /opt/cni/bin
sudo tar -C /opt/cni/bin -xzf cni-plugins.tgz

echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-arptables
echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-ip6tables
echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-iptables

cd /etc/sysctl.d/ && sudo touch 10-bridge-nf-call-iptables.conf
echo "net.bridge.bridge-nf-call-arptables = 1" | sudo tee /etc/sysctl.d/10-bridge-nf-call-iptables.conf
echo "net.bridge.bridge-nf-call-ip6tables = 1" | sudo tee -a /etc/sysctl.d/10-bridge-nf-call-iptables.conf
echo "net.bridge.bridge-nf-call-iptables = 1" | sudo tee -a /etc/sysctl.d/10-bridge-nf-call-iptables.conf
sudo sysctl --system
21 changes: 21 additions & 0 deletions dapr-distributed-calendar/hashicorp/local/install-nomad.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
sudo apt-get update && sudo apt-get install wget gpg coreutils
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt-get update && sudo apt-get install nomad

# fix plugin error for working with consul
cd
curl -L -o cni-plugins.tgz "https://github.com/containernetworking/plugins/releases/download/v1.0.0/cni-plugins-linux-$( [ $(uname -m) = aarch64 ] && echo arm64 || echo amd64)"-v1.0.0.tgz
sudo mkdir -p /opt/cni/bin
sudo tar -C /opt/cni/bin -xzf cni-plugins.tgz

echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-arptables
echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-ip6tables
echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-iptables

cd /etc/sysctl.d/ && sudo touch 10-bridge-nf-call-iptables.conf
echo "net.bridge.bridge-nf-call-arptables = 1" | sudo tee /etc/sysctl.d/10-bridge-nf-call-iptables.conf
echo "net.bridge.bridge-nf-call-ip6tables = 1" | sudo tee -a /etc/sysctl.d/10-bridge-nf-call-iptables.conf
echo "net.bridge.bridge-nf-call-iptables = 1" | sudo tee -a /etc/sysctl.d/10-bridge-nf-call-iptables.conf
sudo sysctl --system
27 changes: 27 additions & 0 deletions dapr-distributed-calendar/hashicorp/local/kv.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"key": "dapr/components/barista_pubsub.yaml",
"flags": 0,
"value": "YXBpVmVyc2lvbjogZGFwci5pby92MWFscGhhMQpraW5kOiBDb21wb25lbnQKbWV0YWRhdGE6CiAgbmFtZTogYmFyaXN0YXB1YnN1YgogIG5hbWVzcGFjZTogZGVmYXVsdApzcGVjOgogIHR5cGU6IHB1YnN1Yi5yZWRpcwogIHZlcnNpb246IHYxCiAgbWV0YWRhdGE6CiAgLSBuYW1lOiByZWRpc0hvc3QKICAgIHZhbHVlOiByZWRpczo2Mzc5CiAgLSBuYW1lOiByZWRpc1Bhc3N3b3JkCiAgICB2YWx1ZTogIiI="
},
{
"key": "dapr/components/consul.yaml",
"flags": 0,
"value": "YXBpVmVyc2lvbjogZGFwci5pby92MWFscGhhMQpraW5kOiBDb21wb25lbnQKbWV0YWRhdGE6CiAgbmFtZTogY29uc3VsCiAgbmFtZXNwYWNlOiBkZWZhdWx0CnNwZWM6CiAgdHlwZTogc3RhdGUuY29uc3VsCiAgdmVyc2lvbjogdjEKICBtZXRhZGF0YToKICAtIG5hbWU6IGRhdGFjZW50ZXIKICAgIHZhbHVlOiBkYzEgIyBSZXF1aXJlZC4gRXhhbXBsZTogZGMxCiAgLSBuYW1lOiBodHRwQWRkcgogICAgdmFsdWU6IDEyNy4wLjAuMTo4NTAwICMgVE9ETyB1cGRhdGUgaGVyZSAxMC4xLjAuNDo4NTAwICMgUmVxdWlyZWQuIEV4YW1wbGU6ICJjb25zdWwuZGVmYXVsdC5zdmMuY2x1c3Rlci5sb2NhbDo4NTAwIg=="
},
{
"key": "dapr/components/kitchen_pubsub.yaml",
"flags": 0,
"value": "YXBpVmVyc2lvbjogZGFwci5pby92MWFscGhhMQpraW5kOiBDb21wb25lbnQKbWV0YWRhdGE6CiAgbmFtZToga2l0Y2hlbnB1YnN1YgogIG5hbWVzcGFjZTogZGVmYXVsdApzcGVjOgogIHR5cGU6IHB1YnN1Yi5yZWRpcwogIHZlcnNpb246IHYxCiAgbWV0YWRhdGE6CiAgLSBuYW1lOiByZWRpc0hvc3QKICAgIHZhbHVlOiByZWRpczo2Mzc5CiAgLSBuYW1lOiByZWRpc1Bhc3N3b3JkCiAgICB2YWx1ZTogIiI="
},
{
"key": "dapr/components/orderup_pubsub.yaml ",
"flags": 0,
"value": "YXBpVmVyc2lvbjogZGFwci5pby92MWFscGhhMQpraW5kOiBDb21wb25lbnQKbWV0YWRhdGE6CiAgbmFtZTogb3JkZXJ1cHB1YnN1YgogIG5hbWVzcGFjZTogZGVmYXVsdApzcGVjOgogIHR5cGU6IHB1YnN1Yi5yZWRpcwogIHZlcnNpb246IHYxCiAgbWV0YWRhdGE6CiAgLSBuYW1lOiByZW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GluZ1JhdGU6ICIxIgogICAgemlwa2luOgogICAgICBlbmRwb2ludEFkZHJlc3M6IGh0dHA6Ly8xMjcuMC4wLjE6OTQxMS9hcGkvdjIvc3BhbnM="
}
]
9 changes: 9 additions & 0 deletions dapr-distributed-calendar/hashicorp/local/nomad-jobs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# Change directory to the jobs folder
cd ../nomad/jobs/

# Start all jobs
for job_file in *.hcl; do
nomad job run "$job_file"
done
65 changes: 65 additions & 0 deletions dapr-distributed-calendar/hashicorp/local/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
set -euo pipefail

require() {
if ! hash "$1" &>/dev/null; then
echo "'$1' not found in PATH"
exit 1
fi
}

require consul
require nomad

cleanup() {
echo
echo "Shutting down services"
kill $(jobs -p)
wait
}
trap cleanup EXIT

# https://github.com/deislabs/hippo/blob/de73ae52d606c0a2351f90069e96acea831281bc/src/Infrastructure/Jobs/NomadJob.cs#L28
# https://www.nomadproject.io/docs/drivers/exec#client-requirements
case "$OSTYPE" in
linux*) SUDO="sudo --preserve-env=PATH" ;;
*) SUDO= ;;
esac

# change to the directory of this script
cd "$(dirname "${BASH_SOURCE[0]}")"

${SUDO} rm -rf ./data
mkdir -p log

IP_ADDRESS=$(hostname -I | xargs | awk '{print $1}')

echo "Starting consul..."
consul agent -dev \
-config-file ./etc/consul.hcl \
-bootstrap-expect 1 \
-client '0.0.0.0' \
-bind "${IP_ADDRESS}" \
&>log/consul.log &

echo "Waiting for consul..."
while ! consul members &>/dev/null; do
sleep 2
done

echo "Starting nomad..."
${SUDO} nomad agent -dev \
-config ./etc/nomad.hcl \
-network-interface eth0 \
-consul-address "${IP_ADDRESS}:8500" \
&>log/nomad.log &

echo "Waiting for nomad..."
while ! nomad server members 2>/dev/null | grep -q alive; do
sleep 2
done

echo
echo "Done!!!"

wait
3 changes: 3 additions & 0 deletions dapr-distributed-calendar/hashicorp/nomad/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.terraform
.terraform.lock.hcl
terraform.*
Loading
Loading