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

fix: container essentials fixes #13

Merged
merged 15 commits into from
Feb 15, 2024
Merged
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
134 changes: 134 additions & 0 deletions dapr-distributed-calendar/api-gateway/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
version: '3.8'
services:
############################
# Node app + Dapr sidecar
############################
controller:
build: ../node
ports:
- "3000"
- "50001"
depends_on:
- redis
- placement
labels:
- "traefik.enable=true"
- "traefik.http.routers.12factor.rule=Host(`12factor.<ENV-NAME>-<ENV-USER-ID>-02.<ENV-ANIMAL>.<ENV-DOMAIN>`)"
networks:
- dapr-callendar-network
environment:
- EVENT_APP=go-events
controller-dapr:
image: "daprio/daprd:edge"
command: ["./daprd",
"-app-id", "controller",
"-app-port", "3000",
"-placement-host-address", "placement:50006",
"-dapr-http-port", "3500",
"-components-path", "/components"]
volumes:
- "../components/:/components"
depends_on:
- controller
network_mode: "service:controller"
############################
# Python app + Dapr sidecar
############################
messages:
build: ../python
depends_on:
- redis
- placement
networks:
- dapr-callendar-network
environment:
- FLASK_RUN_PORT=5000
messages-dapr:
image: "daprio/daprd:edge"
command: ["./daprd",
"-app-id", "messages",
"-app-port", "5000",
"-dapr-http-port", "3501",
"-placement-host-address", "placement:50006",
"-components-path", "/components"]
volumes:
- "../components/:/components"
depends_on:
- messages
network_mode: "service:messages"
############################
# Go app + Dapr sidecar
############################
go-events:
build: ../go
environment:
- DAPR_HTTP_PORT=3503
depends_on:
- redis
- placement
networks:
- dapr-callendar-network
go-events-dapr:
image: "daprio/daprd:edge"
command: ["./daprd",
"-app-id", "go-events",
"-app-port", "6000",
"-placement-host-address", "placement:50006",
"-dapr-http-port", "3503",
"-components-path", "/components"]
volumes:
- "../components/:/components"
depends_on:
- go-events
network_mode: "service:go-events"
############################
# Dapr placement service
############################
placement:
image: "daprio/dapr"
command: ["./placement", "-port", "50006"]
ports:
- "50006:50006"
networks:
- dapr-callendar-network
############################
# Redis state store
############################
redis:
image: docker.io/bitnami/redis:7.2
environment:
# ALLOW_EMPTY_PASSWORD is recommended only for development.
# - ALLOW_EMPTY_PASSWORD=yes
- REDIS_DISABLE_COMMANDS=FLUSHDB,FLUSHALL
- REDIS_PASSWORD=Pa55w.rd
ports:
- '6379'
networks:
- dapr-callendar-network
volumes:
- 'redis_data:/bitnami/redis/data'
############################
# traefik api gateway
############################
traefik:
image: traefik:v2.9
command:
- "--api.insecure=true" # Don't do that in production!
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
ports:
# The HTTP port
- "80:80"
# The Web UI (enabled by --api.insecure=true)
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- dapr-callendar-network
- default

volumes:
redis_data:
driver: local
networks:
dapr-callendar-network:
14 changes: 4 additions & 10 deletions dapr-distributed-calendar/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: '3.8'
services:
############################
# Node app + Dapr sidecar
Expand All @@ -7,21 +7,21 @@ services:
build: ./node
ports:
- "3000:3000"
- "3500"
- "50002"
- "50001"
depends_on:
- redis
- placement
networks:
- dapr-callendar-network
environment:
- EVENT_APP=go-events
controller-dapr:
image: "daprio/daprd:edge"
command: ["./daprd",
"-app-id", "controller",
"-app-port", "3000",
"-placement-host-address", "placement:50006",
"-dapr-http-port", "3500",
"-dapr-grpc-port", "50002",
"-components-path", "/components"]
volumes:
- "./components/:/components"
Expand All @@ -33,9 +33,6 @@ services:
############################
messages:
build: ./python
ports:
- "5000"
- "3501"
depends_on:
- redis
- placement
Expand All @@ -61,9 +58,6 @@ services:
############################
go-events:
build: ./go
ports:
- "6000"
- "3503"
environment:
- DAPR_HTTP_PORT=3503
depends_on:
Expand Down
5 changes: 4 additions & 1 deletion dapr-distributed-calendar/go/go_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
)

var daprPort = os.Getenv("DAPR_HTTP_PORT") // Dapr's default is 3500 if not configured
var daprPort = os.Getenv("DAPR_HTTP_PORT")

const stateStoreName = `events`

Expand Down Expand Up @@ -270,6 +270,9 @@ func checkEvent(id string) ([]byte, error) {
}

func main() {
if daprPort == "" {
daprPort = "3500"
}
res, err := newResource()
if err != nil {
panic(err)
Expand Down
5 changes: 5 additions & 0 deletions dapr-distributed-calendar/kubernetes/appconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ spec:
endpointAddress: otel-dapr-collector.opentelemetry:4317
isSecure: false
protocol: grpc
# nameResolution:
# component: "kubernetes"
# configuration:
# clusterDomain: "cluster.local" # Mutually exclusive with the template field
# template: "{{.ID}}-{{.Data.region}}.internal:{{.Port}}" # Mutually exclusive with the clusterDomain field
4 changes: 2 additions & 2 deletions dapr-distributed-calendar/kubernetes/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ spec:
entryPoints:
- web
routes:
- match: Host(`controller.<ENV-NAME>-<ENV-USER-ID>-01.<ENV-ANIMAL>.<ENV-DOMAIN>`) && PathPrefix(`/`)
- match: Host(`12factor.<ENV-NAME>-<ENV-USER-ID>-01.<ENV-ANIMAL>.<ENV-DOMAIN>`) && PathPrefix(`/`)
kind: Rule
services:
- name: controller
port: 3000
port: 3000
69 changes: 69 additions & 0 deletions dapr-distributed-calendar/local-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# Check if Docker is installed
if command -v docker &>/dev/null; then
echo "Docker is already installed."
else
# Install Docker
echo "Docker is not installed. Installing..."

# Update package index
sudo apt-get update

# Install Docker
sudo apt install docker.io

# Add User to docker Group
sudo usermod -aG docker $USER
echo "Docker has been installed. Rerun the script to continue!"
newgrp docker
fi

# Prepare Dapr environment
cd $HOME
mkdir $HOME/.dapr
cp -r ~/12-factor-app/dapr-distributed-calendar/local/components ~/.dapr

wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash
dapr init # to initialize dapr

# Prepare Golang environment
git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh
source /etc/profile.d/golang_path.sh

# Build Golang application
cd ~/12-factor-app/dapr-distributed-calendar/go
go build go_events.go

# Prepare Python environment
if command -v python3 &>/dev/null; then
echo "Python 3 is installed on this machine."
else
echo "Python 3 is not installed. Installing..."
sudo apt update
sudo apt install python3
python3 --version
fi
# Check if python3.11 is available in the PATH
if command -v python3.11 &>/dev/null; then
echo "Python 3.11 is installed on this machine."
else
echo "Python 3.11 is not installed. Installing..."
sudo apt update
sudo apt install python3.11
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
python3 --version
fi

# Install Python Requirements
cd ~/12-factor-app/dapr-distributed-calendar/python
pip3 install -r ./requirements.txt

# Prepare Node environment
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - && sudo apt-get install -y nodejs

# Install Node Requirements
cd ~/12-factor-app/dapr-distributed-calendar/node
npm install
12 changes: 12 additions & 0 deletions dapr-distributed-calendar/local/components/pubsub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: pubsub
spec:
type: pubsub.redis
version: v1
metadata:
- name: redisHost
value: localhost:6379
- name: redisPassword
value: ""
14 changes: 14 additions & 0 deletions dapr-distributed-calendar/local/components/statestore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: events
spec:
type: state.redis
version: v1
metadata:
- name: redisHost
value: localhost:6379
- name: redisPassword
value: ""
- name: actorStateStore
value: "true"
7 changes: 1 addition & 6 deletions dapr-distributed-calendar/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
FROM node:17-alpine
FROM node:18-alpine

WORKDIR /app
COPY . .
RUN npm install
RUN npm install @opentelemetry/api @opentelemetry/resources \
@opentelemetry/semantic-conventions \
@opentelemetry/sdk-node \
@opentelemetry/sdk-metrics\
@opentelemetry/exporter-metrics-otlp-grpc

EXPOSE 3000
CMD [ "node", "--require", "./instrumentation.js", "node_controller.js"]
Loading
Loading