diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec55a4a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dapr-distributed-calendar/hashicorp/local/log diff --git a/dapr-distributed-calendar/hashicorp/README.md b/dapr-distributed-calendar/hashicorp/README.md new file mode 100644 index 0000000..bbd887b --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/README.md @@ -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 +``` diff --git a/dapr-distributed-calendar/hashicorp/components/barista_pubsub.yaml b/dapr-distributed-calendar/hashicorp/components/barista_pubsub.yaml new file mode 100644 index 0000000..1bf5aa6 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/components/barista_pubsub.yaml @@ -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: "" \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/components/consul.yml b/dapr-distributed-calendar/hashicorp/components/consul.yml new file mode 100644 index 0000000..e2cb06a --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/components/consul.yml @@ -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" \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/components/daprConfig.yaml b/dapr-distributed-calendar/hashicorp/components/daprConfig.yaml new file mode 100644 index 0000000..e06aea5 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/components/daprConfig.yaml @@ -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 \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/components/kitchen_pubsub.yaml b/dapr-distributed-calendar/hashicorp/components/kitchen_pubsub.yaml new file mode 100644 index 0000000..f853359 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/components/kitchen_pubsub.yaml @@ -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: "" \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/components/orderup_pubsub.yaml b/dapr-distributed-calendar/hashicorp/components/orderup_pubsub.yaml new file mode 100644 index 0000000..ea56d21 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/components/orderup_pubsub.yaml @@ -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: "" \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/local/etc/consul.hcl b/dapr-distributed-calendar/hashicorp/local/etc/consul.hcl new file mode 100755 index 0000000..2dbcc62 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/local/etc/consul.hcl @@ -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 +// } \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/local/etc/nomad.hcl b/dapr-distributed-calendar/hashicorp/local/etc/nomad.hcl new file mode 100755 index 0000000..f5608de --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/local/etc/nomad.hcl @@ -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"] +// } +// } \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/local/install-consule.sh b/dapr-distributed-calendar/hashicorp/local/install-consule.sh new file mode 100755 index 0000000..c3b31ab --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/local/install-consule.sh @@ -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 \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/local/install-nomad-consul.sh b/dapr-distributed-calendar/hashicorp/local/install-nomad-consul.sh new file mode 100755 index 0000000..2e3c7f0 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/local/install-nomad-consul.sh @@ -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 \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/local/install-nomad.sh b/dapr-distributed-calendar/hashicorp/local/install-nomad.sh new file mode 100755 index 0000000..0f6b1e7 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/local/install-nomad.sh @@ -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 \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/local/kv.json b/dapr-distributed-calendar/hashicorp/local/kv.json new file mode 100644 index 0000000..db95a86 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/local/kv.json @@ -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": "YXBpVmVyc2lvbjogZGFwci5pby92MWFscGhhMQpraW5kOiBDb21wb25lbnQKbWV0YWRhdGE6CiAgbmFtZTogb3JkZXJ1cHB1YnN1YgogIG5hbWVzcGFjZTogZGVmYXVsdApzcGVjOgogIHR5cGU6IHB1YnN1Yi5yZWRpcwogIHZlcnNpb246IHYxCiAgbWV0YWRhdGE6CiAgLSBuYW1lOiByZWRpc0hvc3QKICAgIHZhbHVlOiByZWRpczo2Mzc5CiAgLSBuYW1lOiByZWRpc1Bhc3N3b3JkCiAgICB2YWx1ZTogIiI=" + }, + { + "key": "dapr/daprConfig.yaml", + "flags": 0, + "value": "YXBpVmVyc2lvbjogZGFwci5pby92MWFscGhhMQpraW5kOiBDb25maWd1cmF0aW9uCm1ldGFkYXRhOgogIG5hbWU6IGRhcHJDb25maWcKc3BlYzoKICBuYW1lUmVzb2x1dGlvbjoKICAgIGNvbXBvbmVudDogImNvbnN1bCIKICAgIGNvbmZpZ3VyYXRpb246CiAgICAgIHNlbGZSZWdpc3RlcjogdHJ1ZQogICAgICBjbGllbnQ6CiAgICAgICAgYWRkcmVzczogIjEyNy4wLjAuMTo4NTAwIiAjIFRPRE86IHVwZGF0ZSBoZXJlICIxMC4xLjAuNDo4NTAwIiAjIFJlcXVpcmVkLiBFeGFtcGxlOiAiY29uc3VsLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWw6ODUwMCIgCiAgICAgIGNoZWNrczoKICAgICAgLSBuYW1lOiAiRGFwciBIZWFsdGggU3RhdHVzIgogICAgICAgIGNoZWNrSUQ6ICJkYXBySGVhbHRoOiAtICR7QVBQX0lEfSAtICR7Q09OU1VMX0hUVFBfQUREUn0iCiAgICAgICAgaW50ZXJ2YWw6ICIxNXMiCiAgICAgICAgdGNwOiAiMTI3LjAuMC4xOjg1MDAiICMgVE9ETzogdXBkYXRlIGhlcmUgIjEwLjEuMC40Ojg1MDAiICMgUmVxdWlyZWQuIEV4YW1wbGU6ICJjb25zdWwuZGVmYXVsdC5zdmMuY2x1c3Rlci5sb2NhbDo4NTAwIgogICAgICB0YWdzOgogICAgICAgIC0gImRhcHIiCiAgICAgIHF1ZXJ5T3B0aW9uczoKICAgICAgICB1c2VDYWNoZTogdHJ1ZQogICAgICAgIGZpbHRlcjogIkNoZWNrcy5TZXJ2aWNlVGFncyBjb250YWlucyBkYXByIgogIHRyYWNpbmc6CiAgICBzYW1wbGluZ1JhdGU6ICIxIgogICAgemlwa2luOgogICAgICBlbmRwb2ludEFkZHJlc3M6IGh0dHA6Ly8xMjcuMC4wLjE6OTQxMS9hcGkvdjIvc3BhbnM=" + } +] diff --git a/dapr-distributed-calendar/hashicorp/local/nomad-jobs.sh b/dapr-distributed-calendar/hashicorp/local/nomad-jobs.sh new file mode 100755 index 0000000..a9f6a32 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/local/nomad-jobs.sh @@ -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 diff --git a/dapr-distributed-calendar/hashicorp/local/start.sh b/dapr-distributed-calendar/hashicorp/local/start.sh new file mode 100755 index 0000000..faead6c --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/local/start.sh @@ -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 \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/nomad/.gitignore b/dapr-distributed-calendar/hashicorp/nomad/.gitignore new file mode 100644 index 0000000..326264b --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/nomad/.gitignore @@ -0,0 +1,3 @@ +.terraform +.terraform.lock.hcl +terraform.* \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/nomad/app.tf b/dapr-distributed-calendar/hashicorp/nomad/app.tf new file mode 100644 index 0000000..1b12b6f --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/nomad/app.tf @@ -0,0 +1,26 @@ +resource "nomad_job" "product_api" { + jobspec = file("${path.module}/jobs/product-api-dapr.nomad.hcl") +} + +resource "nomad_job" "counter_api" { + jobspec = file("${path.module}/jobs/counter-api-dapr.nomad.hcl") + depends_on = [nomad_job.product_api] +} + +resource "nomad_job" "barista_api" { + jobspec = file("${path.module}/jobs/barista-api-dapr.nomad.hcl") +} + +resource "nomad_job" "kitchen_api" { + jobspec = file("${path.module}/jobs/kitchen-api-dapr.nomad.hcl") +} + +resource "nomad_job" "reverse_proxy" { + jobspec = file("${path.module}/jobs/reverse-proxy.nomad.hcl") + depends_on = [nomad_job.product_api, nomad_job.counter_api, nomad_job.barista_api, nomad_job.kitchen_api] +} + +# resource "nomad_job" "web" { +# jobspec = file("${path.module}/jobs/web.nomad.hcl") +# depends_on = [nomad_job.grpc_gw] +# } diff --git a/dapr-distributed-calendar/hashicorp/nomad/infra.tf b/dapr-distributed-calendar/hashicorp/nomad/infra.tf new file mode 100644 index 0000000..55df95b --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/nomad/infra.tf @@ -0,0 +1,23 @@ +provider "nomad" { + address = "http://localhost:4646" + version = "~> 1.4" +} + +resource "nomad_job" "traefik" { + jobspec = file("${path.module}/jobs/traefik.nomad.hcl") +} + +resource "nomad_job" "postgres_db" { + jobspec = file("${path.module}/jobs/postgresdb.nomad.hcl") + depends_on = [nomad_job.traefik] +} + +# resource "nomad_job" "rabbitmq" { +# jobspec = file("${path.module}/jobs/rabbitmq.nomad.hcl") +# depends_on = [nomad_job.traefik] +# } + +resource "nomad_job" "redis" { + jobspec = file("${path.module}/jobs/redis.nomad.hcl") + depends_on = [nomad_job.traefik] +} diff --git a/dapr-distributed-calendar/hashicorp/nomad/jobs/barista-api-dapr.nomad.hcl b/dapr-distributed-calendar/hashicorp/nomad/jobs/barista-api-dapr.nomad.hcl new file mode 100644 index 0000000..91f3417 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/nomad/jobs/barista-api-dapr.nomad.hcl @@ -0,0 +1,105 @@ +job "barista-api-dapr" { + datacenters = ["dc1"] + + group "barista-api-dapr" { + network { + mode = "bridge" + port "app" { to = 5003 } + port "http" { to = 3500 } + port "grpc" { to = 50001 } + port "rpc" { to = 40001 } + } + + service { + name = "barista-api-dapr-http" + port = "${NOMAD_PORT_app}" + address_mode = "host" + + connect { + sidecar_service {} + } + + tags = [ + "dapr" + ] + meta { + DAPR_PORT = "${NOMAD_HOST_PORT_rpc}" + APP_PORT = "${NOMAD_PORT_app}" + } + } + + task "barista-api-dapr" { + driver = "docker" + + config { + image = "ghcr.io/thangchung/try-nomad-dapr/baristaapi:0.1.0" + ports = ["${NOMAD_PORT_app}"] + } + + env { + ASPNETCORE_ENVIRONMENT = "Development" + ConnectionStrings__baristadb = "Server=${attr.unique.network.ip-address};Port=5432;Database=postgres;User Id=postgres;Password=P@ssw0rd" + } + + resources { + memory = 200 + } + } + + task "daprd" { + driver = "docker" + + config { + image = "daprio/daprd:edge" + ports = ["http", "grpc", "rpc"] + command = "./daprd" + args = [ + "-app-id", "barista-api-dapr-http", + "-app-port", "${NOMAD_PORT_app}", + "-dapr-http-port", "${NOMAD_PORT_http}", + "-config", "local/build/dapr/components/daprConfig.yaml", + "-resources-path", "local/build/dapr/components", + ] + } + + template { + data = <