Skip to content

Commit

Permalink
build(repo): General improvements for Cluster structure (#328)
Browse files Browse the repository at this point in the history
* build(repo): use nats helm template instead of duplicate it

* build(repo): refactor to use local publisher instead

* build(repo): general improvements for the cluster

* build(repo): adjust publisher chart
  • Loading branch information
pedronauck committed Dec 2, 2024
1 parent 55bcfc7 commit 5dfaff9
Show file tree
Hide file tree
Showing 96 changed files with 728 additions and 3,495 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/helm_publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
branches:
- main
paths:
- helm/fuel-streams-publisher/Chart.yaml
- cluster/charts/fuel-streams-publisher/Chart.yaml
- cluster/charts/fuel-nats/Chart.yaml

permissions:
contents: read
Expand All @@ -20,6 +21,11 @@ jobs:
permissions:
contents: read
packages: write
strategy:
matrix:
chart:
- fuel-streams-publisher
- fuel-nats
steps:
- name: Check out code
uses: actions/checkout@v4
Expand All @@ -32,4 +38,4 @@ jobs:
username: ${{ github.repository_owner }}
access-token: ${{ secrets.GITHUB_TOKEN }}
force: true
chart-folder: ./helm/fuel-streams-publisher
chart-folder: ./cluster/charts/${{ matrix.chart }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ profile.json
.rust-version
coverage/
docs/
**/**/charts/**.tgz
values-publisher-env.yaml
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exclude: |
(?x)^(
CHANGELOG.md|
pnpm-lock.yaml|
helm/.*|
cluster/charts/.*|
node_modules/.*
)$
Expand Down
1 change: 0 additions & 1 deletion .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ extend-exclude = [
"crates/fuel-indexer/*",
"docker/chain-config",
"docker/monitoring",
"helm",
"cluster",
]
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,11 @@ bench:

# Default values for minikube resources
MINIKUBE_DISK_SIZE ?= 50000mb
MINIKUBE_MEMORY ?= 20000mb
MINIKUBE_MEMORY ?= 8000mb

tilt_%:
@./scripts/set_envs.sh
@./cluster/scripts/gen_env_secret.sh
@tilt --file ${TILTFILE} $* $(ARGS)

cluster_up: %: tilt_% ## Start Tiltfile services.
Expand All @@ -333,12 +335,18 @@ cluster_reset: down up ## Reset Tiltfile services.

# Minikube and K8s setup commands
minikube_%:
@./cluster/$*_minikube.sh "$(MINIKUBE_DISK_SIZE)" "$(MINIKUBE_MEMORY)"
@./cluster/scripts/$*_minikube.sh "$(MINIKUBE_DISK_SIZE)" "$(MINIKUBE_MEMORY)"

k8s_setup:
@./cluster/setup_k8s.sh
@./cluster/scripts/setup_k8s.sh

cluster_setup: minikube_setup k8s_setup ## Setup both minikube and k8s configuration
cluster_setup: minikube_setup k8s_setup helm_setup ## Setup both minikube and kubernetes configuration

helm_setup: ## Update Helm dependencies
@echo "Updating Helm dependencies..."
cd cluster/charts/fuel-local && helm dependency update
cd cluster/charts/fuel-nats && helm dependency update
cd cluster/charts/fuel-streams-publisher && helm dependency update

# ------------------------------------------------------------
# Websocket
Expand Down
120 changes: 68 additions & 52 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -1,79 +1,95 @@
#!/usr/bin/env python
load('ext://restart_process', 'docker_build_with_restart')
load('ext://color', 'color')
load('ext://dotenv', 'dotenv')

analytics_settings(True) # Enable telemetry dialogue in web UI
disable_snapshots() # Disable TiltCloud Snapshots
version_settings(True) # Enable 'new version' banner

# parse Tiltfile config
config.define_string(name="env", args=False, usage="This argument defines the build env (dev or release)")
settings = config.parse()
environment=settings.get('env', "dev") #dev or release
# Load environment variables from .env file
dotenv()

# load ingresses
k8s_yaml('./cluster/charts/fuel-local/crds/traefik-resources.yaml')
k8s_kind('IngressRoute')
# Build publisher image with proper configuration for Minikube
custom_build(
ref='fuel-streams-publisher:latest',
command=['./cluster/scripts/build_publisher.sh'],
deps=[
'./src',
'./Cargo.toml',
'./Cargo.lock',
'./docker/fuel-streams-publisher.Dockerfile'
],
live_update=[
sync('./src', '/usr/src'),
sync('./Cargo.toml', '/usr/src/Cargo.toml'),
sync('./Cargo.lock', '/usr/src/Cargo.lock'),
run('cargo build', trigger=['./src', './Cargo.toml', './Cargo.lock'])
],
skips_local_docker=True,
ignore=['./target']
)

# disable unused image
update_settings(suppress_unused_image_warnings=["k8s-tools:latest"])

# project namespace
namespace = "fuel-local"

# load fuel helm chart
fuel_chart_name = "fuel"
fuel_chart_dir = "cluster/charts/fuel-local"
fuel_values = "cluster/charts/fuel-local/values.yaml"
k8s_yaml(helm(fuel_chart_dir, name=fuel_chart_name, namespace=namespace, values=[fuel_values], set=[]))

# load nats helm chart
nats_chart_name = "nats"
nats_chart_dir = "cluster/charts/fuel-nats"
nats_values = "cluster/charts/fuel-nats/values.yaml"
k8s_yaml(helm(nats_chart_dir, name=nats_chart_name, namespace=namespace, values=[nats_values], set=[]))

# load surrealdb helm chart
surrealdb_chart_name = "surrealdb"
surrealdb_chart_dir = "cluster/charts/fuel-surrealdb"
surrealdb_values = "cluster/charts/fuel-surrealdb/values.yaml"
k8s_yaml(helm(surrealdb_chart_dir, name=surrealdb_chart_name, namespace=namespace, values=[surrealdb_values], set=[]))

# build publisher image
# ref = 'fuel-publisher:{}'
# command = 'make build-fuel-publisher-{} && docker tag fuel-publisher:{} $EXPECTED_REF'.format(environment, environment)
# deps = ["./fuel-publisher/Cargo.lock", "./fuel-publisher/Cargo.toml", "./fuel-publisher/src", "./fuel-publisher/target/release/**/*"]
# custom_build(ref=ref, command=command, deps=deps)

# build k8s tools (tag is always latest!)
ref = "k8s-tools:latest"
command = "make build-k8s-tools && docker tag k8s-tools:latest $EXPECTED_REF"
custom_build(ref=ref, command=command, deps=[])
# Deploy the Helm chart with values from .env
k8s_yaml(helm(
'cluster/charts/fuel-local',
name='local',
namespace='fuel-local',
values=[
'cluster/charts/fuel-local/values.yaml',
'cluster/charts/fuel-local/values-publisher-env.yaml',
]
))

# k8s resources
ports = {
"monitoring": ["9090:9090", "3000:3000"],
"surrealdb": ["8000:8000", "8001:8001"],
"elasticsearch": ["9200:9200", "9300:9300"],
"kibana": ["5601:5601"],
"fuel-publisher": ["4000:4000", "8080:8080"],
"publisher": ["4000:4000", "8080:8080"],
"nats": ["4222:4222"],
"nats-box": [],
}

deps = {
"monitoring": [],
"surrealdb": [],
"elasticsearch": [],
"kibana": ["elasticsearch"],
"fuel-publisher": [],
"publisher": [],
"nats": [],
"nats-box": [],
}

k8s_resource("monitoring", port_forwards=ports["monitoring"], resource_deps=deps["monitoring"], labels="monitoring")
k8s_resource("surrealdb", port_forwards=ports["surrealdb"], resource_deps=deps["surrealdb"], labels="indexer")
k8s_resource("elasticsearch", port_forwards=ports["elasticsearch"], resource_deps=deps["elasticsearch"], labels="logging")
k8s_resource("kibana", port_forwards=ports["kibana"], resource_deps=deps["kibana"], labels="logging")
k8s_resource("fuel-publisher", port_forwards=ports["fuel-publisher"], resource_deps=deps["fuel-publisher"], labels="publisher")
k8s_resource("nats", port_forwards=ports["nats"], resource_deps=deps["nats"], labels="nats")
k8s_resource("nats-box", port_forwards=ports["nats-box"], resource_deps=deps["nats-box"], labels="nats")
k8s_resource("monitoring",
port_forwards=ports["monitoring"],
resource_deps=deps["monitoring"],
labels="monitoring"
)
k8s_resource("elasticsearch",
port_forwards=ports["elasticsearch"],
resource_deps=deps["elasticsearch"],
labels="logging"
)
k8s_resource("kibana",
port_forwards=ports["kibana"],
resource_deps=deps["kibana"],
labels="logging"
)
k8s_resource("local-fuel-streams-publisher",
new_name="publisher", # Override the display name
resource_deps=deps["publisher"],
port_forwards=ports["publisher"],
labels="publisher"
)
k8s_resource("local-nats",
new_name="nats",
port_forwards=ports["nats"],
resource_deps=deps["nats"],
labels="nats"
)
k8s_resource("local-nats-box",
new_name="nats-box",
port_forwards=ports["nats-box"],
resource_deps=deps["nats-box"],
labels="nats"
)
9 changes: 9 additions & 0 deletions cluster/charts/fuel-local/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies:
- name: fuel-streams-publisher
repository: file://../fuel-streams-publisher
version: 0.3.7
- name: fuel-nats
repository: file://../fuel-nats
version: 0.1.0
digest: sha256:4362071bef367c36d9433fa948178f176614e65a69cd5e08f880937f2c4795df
generated: "2024-11-30T00:12:23.285838-03:00"
9 changes: 8 additions & 1 deletion cluster/charts/fuel-local/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
apiVersion: v1
apiVersion: v2
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: fuel-local
version: 0.2.0
dependencies:
- name: fuel-streams-publisher
version: "0.3.7"
repository: "file://../fuel-streams-publisher"
- name: fuel-nats
version: "0.1.0"
repository: "file://../fuel-nats"
15 changes: 0 additions & 15 deletions cluster/charts/fuel-local/templates/fuel-shared-mnt.yaml

This file was deleted.

101 changes: 0 additions & 101 deletions cluster/charts/fuel-local/templates/publisher.yaml

This file was deleted.

11 changes: 11 additions & 0 deletions cluster/charts/fuel-local/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-fuel-streams-publisher
labels:
{{- include "fuel-streams-publisher.labels" . | nindent 4 }}
type: Opaque
stringData:
{{- range $key, $value := index .Values "fuel-streams-publisher" "secrets" }}
{{ $key }}: {{ $value | default "" | quote }}
{{- end }}
Loading

0 comments on commit 5dfaff9

Please sign in to comment.