Skip to content
Draft
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
137 changes: 134 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Copyright AGNTCY Contributors (https://github.com/agntcy)
# SPDX-License-Identifier: Apache-2.0

version: '3'

Expand Down Expand Up @@ -33,7 +31,7 @@ vars:
PROTOC_BIN: '{{ .BIN_DIR }}/protoc-{{.PROTOC_VERSION}}'
BUFBUILD_VERSION: '1.50.1'
BUFBUILD_BIN: '{{ .BIN_DIR }}/bufbuild-{{.BUFBUILD_VERSION}}'
GO_VERSION: '1.24.5'
GO_VERSION: '1.24.4'
MULTIMOD_VERSION: '0.17.0'
MULTIMOD_BIN: '{{ .BIN_DIR }}/multimod-{{.MULTIMOD_VERSION}}'
GOLANGCI_LINT_VERSION: '1.64.7'
Expand Down Expand Up @@ -914,6 +912,139 @@ tasks:
# Run tests
- 'go -C ./e2e test -v -failfast -test.v -test.paniconexit0 -ginkgo.timeout 2h -timeout 2h -ginkgo.v .'

abigen:install:
desc: Install abigen tool from go-ethereum
deps:
- deps:bin-dir
cmds:
- GOBIN={{.BIN_DIR}} go install github.com/ethereum/go-ethereum/cmd/[email protected]

abigen:generate:
desc: Generate Go bindings for AgentStore smart contract
deps:
- abigen:install
cmds:
- |
jq .abi blockchain/personal-chain/artifacts/contracts/AgentStore.sol/AgentStore.json > /tmp/AgentStore.abi.json
{{.BIN_DIR}}/abigen \
--pkg agentstore \
--out blockchain/dapps/bindings/go/agentstore/agentstore.go \
--abi /tmp/AgentStore.abi.json \
--type AgentStore

trustless:start:
desc: "Start trustless local chain service (KinD, Helm, port-forward)"
vars:
HELM_NAMESPACE: "personal-chain"
HELM_CHART_PATH: "blockchain/charts/chain"
IMAGE_REPO: "personal-chain"
IMAGE_TAG: "latest"
KIND_CLUSTER_NAME: "trustless-chain"
cmds:
- |
# Create KinD cluster
{{ .KIND_BIN }} create cluster --name {{ .KIND_CLUSTER_NAME }}
- |
# Load Docker image into KinD
{{ .KIND_BIN }} load docker-image {{ .IMAGE_REPO }}:{{ .IMAGE_TAG }} --name {{ .KIND_CLUSTER_NAME }}
- |
# Deploy Helm chart for personal-chain
{{ .HELM_BIN }} upgrade --install personal-chain {{ .HELM_CHART_PATH }} \
--set image.repository={{ .IMAGE_REPO }} \
--set image.tag={{ .IMAGE_TAG }} \
--namespace {{ .HELM_NAMESPACE }} \
--create-namespace \
--wait --timeout 5m
- |
# Port-forward JSON-RPC port
{{ .KUBECTL_BIN }} port-forward svc/personal-chain 8545:8545 -n {{ .HELM_NAMESPACE }} &
sleep 10
- |
# Wait for chain to be accessible before deploying contract
for i in {1..15}; do
if curl -s http://localhost:8545 > /dev/null; then
echo "Chain is accessible on localhost:8545"; break
fi
echo "Waiting for chain... ($i)"; sleep 2
if [ $i -eq 15 ]; then echo "Chain not accessible after waiting."; exit 1; fi
done
# Deploy AgentStore smart contract using Hardhat
cd blockchain/personal-chain
npx hardhat run scripts/deploy.js --network localhost
- |
# Wait for chain to be accessible
for i in {1..15}; do
if curl -s http://localhost:8545 > /dev/null; then
echo "Chain is accessible on localhost:8545"; break
fi
echo "Waiting for chain... ($i)"; sleep 2
if [ $i -eq 15 ]; then echo "Chain not accessible after waiting."; exit 1; fi
done

trustless:stop:
desc: "Stop trustless local chain service (KinD, Helm, port-forward)"
vars:
KIND_CLUSTER_NAME: "trustless-chain"
cmds:
- |
# Delete KinD cluster
{{ .KIND_BIN }} delete cluster --name {{ .KIND_CLUSTER_NAME }}


test:trustless:local:
desc: "Run trustless local test: deploy chain Helm chart on KinD and verify JSON-RPC endpoint"
vars:
HELM_NAMESPACE: "personal-chain"
HELM_CHART_PATH: "blockchain/charts/chain"
IMAGE_REPO: "personal-chain"
IMAGE_TAG: "latest"
KIND_CLUSTER_NAME: "trustless-chain"
cmds:
- defer: { task: deploy:kubernetes:local:cleanup, vars: { KIND_CLUSTER_NAME: trustless-chain } }
- |
# Create KinD cluster
{{ .KIND_BIN }} create cluster --name {{ .KIND_CLUSTER_NAME }}
- |
# Load Docker image into KinD
{{ .KIND_BIN }} load docker-image {{ .IMAGE_REPO }}:{{ .IMAGE_TAG }} --name {{ .KIND_CLUSTER_NAME }}
- |
# Deploy Helm chart for personal-chain
{{ .HELM_BIN }} upgrade --install personal-chain {{ .HELM_CHART_PATH }} \
--set image.repository={{ .IMAGE_REPO }} \
--set image.tag={{ .IMAGE_TAG }} \
--namespace {{ .HELM_NAMESPACE }} \
--create-namespace \
--wait --timeout 5m
- |
# Port-forward JSON-RPC port
{{ .KUBECTL_BIN }} port-forward svc/personal-chain 8545:8545 -n {{ .HELM_NAMESPACE }} &
sleep 10
- |
# Wait for chain to be accessible before deploying contract
for i in {1..15}; do
if curl -s http://localhost:8545 > /dev/null; then
echo "Chain is accessible on localhost:8545"; break
fi
echo "Waiting for chain... ($i)"; sleep 2
if [ $i -eq 15 ]; then echo "Chain not accessible after waiting."; exit 1; fi
done
# Deploy AgentStore smart contract using Hardhat
cd blockchain/personal-chain
npx hardhat run scripts/deploy.js --network localhost
- |
# Test JSON-RPC endpoint (eth_blockNumber)
RESPONSE=$(curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H "Content-Type: application/json" http://localhost:8545)
echo "eth_blockNumber response: $RESPONSE"
if echo "$RESPONSE" | grep -q '"result"'; then
echo "Test passed: Chain is running and responding."
else
echo "Test failed: No result in response." && exit 1
fi
- |
# Cleanup port-forward
pkill -f 'port-forward svc/personal-chain'


# TODO: move spire out from here
# TODO: change to Ingress services instead of LoadBalancer
test:spire:
Expand Down
23 changes: 23 additions & 0 deletions blockchain/charts/chain/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions blockchain/charts/chain/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: chain
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
62 changes: 62 additions & 0 deletions blockchain/charts/chain/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "chart.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "chart.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "chart.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "chart.labels" -}}
helm.sh/chart: {{ include "chart.chart" . }}
{{ include "chart.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "chart.selectorLabels" -}}
app.kubernetes.io/name: {{ include "chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "chart.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "chart.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
65 changes: 65 additions & 0 deletions blockchain/charts/chain/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "chart.fullname" . }}
labels:
{{- include "chart.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.autoscaling.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "chart.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "chart.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.image.pullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "chart.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
# TODO: maybe make the port on the container configurable
containerPort: 8545
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
env:
- name: CHAIN_ID
value: {{ .Values.chainID | quote }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
32 changes: 32 additions & 0 deletions blockchain/charts/chain/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "chart.fullname" . }}
labels:
{{- include "chart.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "chart.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
Loading
Loading