Skip to content

Commit abfe8eb

Browse files
committed
Added helm chart
1 parent a67776c commit abfe8eb

19 files changed

+460
-7
lines changed

Makefile

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
PROMPT_COLOR=\033[36m
2+
PROMPT_NC=\033[0m # No Color
3+
4+
MS_IMAGE_REGISTRY = public.ecr.aws/e3b4k2v5/otterside
5+
MS_CART_SERVICE_NAME = cart
6+
MS_USERS_SERVICE_NAME = users
7+
MS_FRONTEND_SERVICE_NAME = frontend
8+
MS_PRODUCTS_SERVICE_NAME = products
9+
MS_CHECKOUT_SERVICE_NAME = checkout
10+
MS_NEWSLETTER_SERVICE_NAME = newsletter
11+
12+
HELM_CHART_PATH = ./helm
13+
KUBECONFIG_PATH = $(HOME)/.kube/config
14+
OTTERSIDE_NAMESPACE = otterside
15+
16+
# Include .env file if it exists
17+
ifneq (,$(wildcard ./.env))
18+
include .env
19+
export
20+
endif
21+
22+
help: ## Show help message
23+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " ${PROMPT_COLOR}%-25s${PROMPT_NC} %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
24+
25+
# Image building targets
26+
27+
build-users: ## Builds and pushes the users service image
28+
@echo "${PROMPT_COLOR}Building users image'...${PROMPT_NC}"
29+
docker buildx build --platform linux/amd64 -t $(MS_IMAGE_REGISTRY):$(MS_USERS_SERVICE_NAME)-amd64 --push --file build/$(MS_USERS_SERVICE_NAME).Dockerfile .
30+
docker buildx build --platform linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_USERS_SERVICE_NAME)-arm64 --push --file build/$(MS_USERS_SERVICE_NAME).Dockerfile .
31+
32+
build-cart: ## Builds and pushes the cart service image
33+
@echo "${PROMPT_COLOR}Building cart image'...${PROMPT_NC}"
34+
docker buildx build --platform linux/amd64 -t $(MS_IMAGE_REGISTRY):$(MS_CART_SERVICE_NAME)-amd64 --push --file build/$(MS_CART_SERVICE_NAME).Dockerfile .
35+
docker buildx build --platform linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_CART_SERVICE_NAME)-arm64 --push --file build/$(MS_CART_SERVICE_NAME).Dockerfile .
36+
37+
build-checkout: ## Builds and pushes the checkout service image
38+
@echo "${PROMPT_COLOR}Building checkout image'...${PROMPT_NC}"
39+
docker buildx build --platform linux/amd64 -t $(MS_IMAGE_REGISTRY):$(MS_CHECKOUT_SERVICE_NAME)-amd64 --push --file build/$(MS_CHECKOUT_SERVICE_NAME).Dockerfile .
40+
docker buildx build --platform linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_CHECKOUT_SERVICE_NAME)-arm64 --push --file build/$(MS_CHECKOUT_SERVICE_NAME).Dockerfile .
41+
42+
build-frontend: ## Builds and pushes the frontend service image
43+
@echo "${PROMPT_COLOR}Building frontend image'...${PROMPT_NC}"
44+
docker buildx build --platform linux/amd64 -t $(MS_IMAGE_REGISTRY):$(MS_FRONTEND_SERVICE_NAME)-amd64 --push --file build/$(MS_FRONTEND_SERVICE_NAME).Dockerfile .
45+
docker buildx build --platform linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_FRONTEND_SERVICE_NAME)-arm64 --push --file build/$(MS_FRONTEND_SERVICE_NAME).Dockerfile .
46+
47+
build-newsletter: ## Builds and pushes the newsletter service image
48+
@echo "${PROMPT_COLOR}Building newsletter image'...${PROMPT_NC}"
49+
docker buildx build --platform linux/amd64 -t $(MS_IMAGE_REGISTRY):$(MS_NEWSLETTER_SERVICE_NAME)-amd64 --push --file build/$(MS_NEWSLETTER_SERVICE_NAME).Dockerfile .
50+
docker buildx build --platform linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_NEWSLETTER_SERVICE_NAME)-arm64 --push --file build/$(MS_NEWSLETTER_SERVICE_NAME).Dockerfile .
51+
52+
build-products: ## Builds and pushes the products service image
53+
@echo "${PROMPT_COLOR}Building products image'...${PROMPT_NC}"
54+
docker buildx build --platform linux/amd64 -t $(MS_IMAGE_REGISTRY):$(MS_PRODUCTS_SERVICE_NAME)-amd64 --push --file build/$(MS_PRODUCTS_SERVICE_NAME).Dockerfile .
55+
docker buildx build --platform linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_PRODUCTS_SERVICE_NAME)-arm64 --push --file build/$(MS_PRODUCTS_SERVICE_NAME).Dockerfile .
56+
57+
build-images: build-users build-cart build-checkout build-frontend build-newsletter build-products ## Build and push all images
58+
59+
# Combine arch images
60+
61+
tag-users: ## Tag the users service images
62+
docker buildx imagetools create -t $(MS_IMAGE_REGISTRY):$(MS_USERS_SERVICE_NAME) \
63+
$(MS_IMAGE_REGISTRY):$(MS_USERS_SERVICE_NAME)-amd64 \
64+
$(MS_IMAGE_REGISTRY):$(MS_USERS_SERVICE_NAME)-arm64
65+
66+
tag-cart: ## Tag the cart service images
67+
docker buildx imagetools create -t $(MS_IMAGE_REGISTRY):$(MS_CART_SERVICE_NAME) \
68+
$(MS_IMAGE_REGISTRY):$(MS_CART_SERVICE_NAME)-amd64 \
69+
$(MS_IMAGE_REGISTRY):$(MS_CART_SERVICE_NAME)-arm64
70+
71+
tag-checkout: ## Tag the checkout service images
72+
docker buildx imagetools create -t $(MS_IMAGE_REGISTRY):$(MS_CHECKOUT_SERVICE_NAME) \
73+
$(MS_IMAGE_REGISTRY):$(MS_CHECKOUT_SERVICE_NAME)-amd64 \
74+
$(MS_IMAGE_REGISTRY):$(MS_CHECKOUT_SERVICE_NAME)-arm64
75+
76+
tag-frontend: ## Tag the frontend service images
77+
docker buildx imagetools create -t $(MS_IMAGE_REGISTRY):$(MS_FRONTEND_SERVICE_NAME) \
78+
$(MS_IMAGE_REGISTRY):$(MS_FRONTEND_SERVICE_NAME)-amd64 \
79+
$(MS_IMAGE_REGISTRY):$(MS_FRONTEND_SERVICE_NAME)-arm64
80+
81+
tag-newsletter: ## Tag the newsletter service images
82+
docker buildx imagetools create -t $(MS_IMAGE_REGISTRY):$(MS_NEWSLETTER_SERVICE_NAME) \
83+
$(MS_IMAGE_REGISTRY):$(MS_NEWSLETTER_SERVICE_NAME)-amd64 \
84+
$(MS_IMAGE_REGISTRY):$(MS_NEWSLETTER_SERVICE_NAME)-arm64
85+
86+
tag-products: ## Tag the products service images
87+
docker buildx imagetools create -t $(MS_IMAGE_REGISTRY):$(MS_PRODUCTS_SERVICE_NAME) \
88+
$(MS_IMAGE_REGISTRY):$(MS_PRODUCTS_SERVICE_NAME)-amd64 \
89+
$(MS_IMAGE_REGISTRY):$(MS_PRODUCTS_SERVICE_NAME)-arm64
90+
91+
tag-images: tag-users tag-cart tag-checkout tag-frontend tag-newsletter tag-products ## Tag all images
92+
93+
update-images: build-images tag-images ## Build and tag all images
94+
95+
install-otterside: ## Installs Otterside in the kubernetes cluster
96+
helm --kubeconfig=$(KUBECONFIG_PATH) dep up $(HELM_CHART_PATH); \
97+
helm --kubeconfig=$(KUBECONFIG_PATH) upgrade --install otterside $(HELM_CHART_PATH) -n $(OTTERSIDE_NAMESPACE) --create-namespace

build/checkout.Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RUN openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 \
1111
-keyout server.key -out server.crt
1212

1313
# Stage 2: Build the Node application
14-
FROM node:16
14+
FROM node:21
1515
WORKDIR /app
1616

1717
# Copy the certificates from the certs stage

build/frontend.Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# docker build -t frontend-service -f build/frontend.Dockerfile .
2+
3+
# Stage 1: Create a self signed SSL certificate
4+
FROM alpine:latest AS certs
5+
WORKDIR /app
6+
RUN apk --no-cache add openssl
7+
8+
# Generate self-signed certificate (server.crt and server.key)
9+
RUN openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 \
10+
-subj "/C=US/ST=State/L=City/O=Organization/CN=localhost" \
11+
-keyout server.key -out server.crt
12+
13+
# Stage 2: Build the Python application
14+
FROM python:3.12-slim
15+
WORKDIR /app
16+
17+
# Copy the certificates from the certs stage
18+
COPY --from=certs /app .
19+
20+
# Copy requirements and install dependencies
21+
COPY services/frontend/requirements.txt .
22+
RUN pip install --no-cache-dir -r requirements.txt
23+
24+
# Copy the rest of the application code
25+
COPY services/frontend/. .
26+
27+
# Expose port 7000 for the HTTPS server
28+
EXPOSE 7000
29+
30+
# Run the Python server
31+
CMD ["python", "server.py"]

build/newsletter.Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RUN openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 \
1111
-keyout server.key -out server.crt
1212

1313
# Stage 2: Build the Node application
14-
FROM node:16
14+
FROM node:21
1515
WORKDIR /app
1616

1717
# Copy the certificates from the certs stage

docker-compose.yml

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
version: "3.9"
22
services:
3+
34
users-service:
45
build:
56
dockerfile: build/users.Dockerfile
@@ -72,6 +73,26 @@ services:
7273
depends_on:
7374
- cart-service
7475

76+
frontend-service:
77+
build:
78+
dockerfile: build/frontend.Dockerfile
79+
restart: unless-stopped
80+
platform: linux/amd64
81+
ports:
82+
- "7000:7000"
83+
environment:
84+
CART_SERVICE_API: https://cart-service:7004
85+
USERS_SERVICE_API: https://users-service:7001
86+
PRODUCTS_SERVICE_API: https://products-service:7002
87+
CHECKOUT_SERVICE_API: https://checkout-service:7005
88+
NEWSLETTER_SERVICE_API: https://newsletter-service:7003
89+
depends_on:
90+
- cart-service
91+
- users-service
92+
- products-service
93+
- checkout-service
94+
- newsletter-service
95+
7596
postgres:
7697
image: postgres:14
7798
restart: unless-stopped

helm/Chart.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v2
2+
name: otterside
3+
description: A microservices-based e-commerce platform
4+
version: 1.0.0
5+
appVersion: "1.0"

helm/templates/ms-deployment.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{{- range $service, $config := .Values.services }}
2+
{{- if and $config.enabled (ne $service "redis") (ne $service "postgres") }}
3+
---
4+
apiVersion: apps/v1
5+
kind: Deployment
6+
metadata:
7+
name: {{ $service }}
8+
labels:
9+
network-mapper.otterize.com/ebpf-visibility: 'true'
10+
spec:
11+
replicas: 1
12+
selector:
13+
matchLabels:
14+
app: {{ $service }}
15+
template:
16+
metadata:
17+
labels:
18+
app: {{ $service }}
19+
network-mapper.otterize.com/ebpf-visibility: 'true'
20+
spec:
21+
containers:
22+
- name: {{ $service }}
23+
image: {{ $config.image.repository }}:{{ $config.image.tag }}
24+
ports:
25+
- containerPort: {{ $config.port }}
26+
env:
27+
{{- range $key, $value := $config.env }}
28+
- name: {{ $key }}
29+
value: {{ $value | quote }}
30+
{{- end }}
31+
imagePullPolicy: Always
32+
{{- end }}
33+
{{- end }}

helm/templates/ms-service.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- range $service, $config := .Values.services }}
2+
{{- if $config.enabled }}
3+
---
4+
apiVersion: v1
5+
kind: Service
6+
metadata:
7+
name: {{ $service }}
8+
spec:
9+
selector:
10+
app: {{ $service }}
11+
ports:
12+
- protocol: TCP
13+
port: {{ $config.port }}
14+
targetPort: {{ $config.port }}
15+
type: ClusterIP
16+
{{- end }}
17+
{{- end }}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{{- if .Values.postgres.enabled }}
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: postgres
6+
labels:
7+
network-mapper.otterize.com/ebpf-visibility: 'true'
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: postgres
13+
template:
14+
metadata:
15+
labels:
16+
app: postgres
17+
network-mapper.otterize.com/ebpf-visibility: 'true'
18+
spec:
19+
containers:
20+
- name: postgres
21+
image: {{ .Values.postgres.image.repository }}:{{ .Values.postgres.image.tag }}
22+
ports:
23+
- containerPort: {{ .Values.postgres.port }}
24+
env:
25+
{{- range $key, $value := .Values.postgres.env }}
26+
- name: {{ $key }}
27+
value: {{ $value | quote }}
28+
{{- end }}
29+
volumeMounts:
30+
- mountPath: /var/lib/postgresql/data
31+
name: postgres-data
32+
volumes:
33+
- name: postgres-data
34+
persistentVolumeClaim:
35+
claimName: postgres-pvc
36+
{{- end }}

helm/templates/postgres-pvc.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{- if .Values.postgres.enabled }}
2+
apiVersion: v1
3+
kind: PersistentVolumeClaim
4+
metadata:
5+
name: postgres-pvc
6+
spec:
7+
accessModes:
8+
- ReadWriteOnce
9+
resources:
10+
requests:
11+
storage: {{ .Values.postgres.persistence.size }}
12+
{{- end }}

helm/templates/postgres-service.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- if .Values.postgres.enabled }}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: postgres
6+
spec:
7+
selector:
8+
app: postgres
9+
ports:
10+
- protocol: TCP
11+
port: {{ .Values.postgres.port }}
12+
targetPort: {{ .Values.postgres.port }}
13+
type: ClusterIP
14+
{{- end }}

helm/templates/redis-deployment.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{{- if .Values.redis.enabled }}
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: redis
6+
labels:
7+
network-mapper.otterize.com/ebpf-visibility: 'true'
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: redis
13+
template:
14+
metadata:
15+
labels:
16+
app: redis
17+
network-mapper.otterize.com/ebpf-visibility: 'true'
18+
spec:
19+
containers:
20+
- name: redis
21+
image: {{ .Values.redis.image.repository }}:{{ .Values.redis.image.tag }}
22+
ports:
23+
- containerPort: {{ .Values.redis.port }}
24+
{{- end }}

helm/templates/redis-service.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- if .Values.redis.enabled }}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: redis
6+
spec:
7+
selector:
8+
app: redis
9+
ports:
10+
- protocol: TCP
11+
port: {{ .Values.redis.port }}
12+
targetPort: {{ .Values.redis.port }}
13+
type: ClusterIP
14+
{{- end }}

0 commit comments

Comments
 (0)