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

Deployment Charts #35

Merged
merged 13 commits into from
Aug 15, 2023
24 changes: 24 additions & 0 deletions .github/scripts/verify_chart_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -e

err() {
echo -e "\e[31m\e[1merror:\e[0m $@" 1>&2;
}

status() {
WIDTH=12
printf "\e[32m\e[1m%${WIDTH}s\e[0m %s\n" "$1" "$2"
}
# install dasel
curl -sSLf "https://github.com/TomWright/dasel/releases/download/v1.24.3/dasel_linux_amd64" -L -o dasel
chmod +x dasel
mv ./dasel /usr/local/bin/dasel
# check appVersion with crate package metadata
HELM_APP_VERSION=$(cat deployment/charts/Chart.yaml | dasel -r yaml 'appVersion')
CRATE_VERSION=$(cat Cargo.toml | dasel -r toml 'package.version')
if [ "$HELM_APP_VERSION" != "$CRATE_VERSION" ]; then
err "crate version $CRATE_VERSION, doesn't match helm app version $HELM_APP_VERSION"
exit 1
else
status "crate version matches helm chart app version $HELM_APP_VERSION"
fi
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ jobs:
echo "Comparing minimum supported toolchain ($MIN_VERSION) with ci toolchain (RUST_VERSION)"
test "$MIN_VERSION" == "$RUST_VERSION"

verify-helm-chart:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: alexellis/setup-arkade@v1
- uses: alexellis/arkade-get@master
with:
helm: latest
- name: Lint helm chart
run: helm lint deployment/charts
- name: Verify helm chart version matches crate
run: |
./.github/scripts/verify_chart_version.sh

cargo-verifications:
needs:
- verify-rust-version
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tokio = { version = "1.28.0", features = ["rt-multi-thread", "rt", "macros"] }
tokio-util = { version = "0.7.8" }
thiserror = "1.0.40"
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
tracing-subscriber = { version = "0.3.17", features = ["json"] }
clap = { version ="4.3", features =["derive", "env"] }
url = "2.3"
serde_json = "1.0.96"
Expand Down
6 changes: 6 additions & 0 deletions deployment/charts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: fuel-block-committer
description: Fuel Block Committer Helm Chart
type: application
appVersion: "0.0.0"
version: 0.1.0
21 changes: 21 additions & 0 deletions deployment/charts/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- define "fuel-block-committer.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "fuel-block-committer.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 -}}

{{- define "fuel-block-committer.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

116 changes: 116 additions & 0 deletions deployment/charts/templates/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{{- if .Values.app.prometheus.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ .Release.Name }}-service-monitor
labels:
release: {{ .Values.app.prometheus.helm_release_name }}
spec:
selector:
app: {{ template "fuel-block-committer.name" . }}
Voxelot marked this conversation as resolved.
Show resolved Hide resolved
release: {{ .Release.Name }}
endpoints:
- path: /metrics
port: http
{{- end }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: "{{ .Release.Name }}-claim"
labels:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: "1Gi"
storageClassName: "gp3"
---
kind: Service
apiVersion: v1
metadata:
labels:
app: {{ template "fuel-block-committer.name" . }}
chart: {{ template "fuel-block-committer.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
name: {{ .Release.Name }}-service
spec:
type: NodePort
Voxelot marked this conversation as resolved.
Show resolved Hide resolved
selector:
app: {{ template "fuel-block-committer.name" . }}
Voxelot marked this conversation as resolved.
Show resolved Hide resolved
release: {{ .Release.Name }}
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-deployment
labels:
app: {{ template "fuel-block-committer.name" . }}
chart: {{ template "fuel-block-committer.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
selector:
matchLabels:
app: {{ template "fuel-block-committer.name" . }}
release: {{ .Release.Name }}
replicas: 1
template:
metadata:
labels:
app: {{ template "fuel-block-committer.name" . }}
release: {{ .Release.Name }}
spec:
containers:
- name: {{ .Values.app.name }}
image: "{{ .Values.app.image.repository }}:{{ .Values.app.image.tag }}"
command: ["./fuel-block-committer"]
args:
- "--host"
- "0.0.0.0"
- "--port"
- "8080"
- "--db-path"
- "/mnt/db/db.db3"
resources: {}
imagePullPolicy: {{ .Values.app.image.pullPolicy }}
ports:
- name: http
containerPort: 8080
protocol: TCP
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 10
volumeMounts:
- name: "{{ .Release.Name }}-volume"
mountPath: "/mnt/db"
env:
- name: ETHEREUM_WALLET_KEY
value: "{{ .Values.app.ethereum_wallet_key | default false }}"
- name: ETHEREUM_RPC
value: "{{ .Values.app.ethereum_rpc }}"
- name: ETHEREUM_CHAIN
value: "{{ .Values.app.ethereum_chain_id }}"
- name: FUEL_GRAPHQL_ENDPOINT
value: "{{ .Values.app.fuel_graphql_endpoint }}"
- name: STATE_CONTRACT_ADDRESS
value: "{{ .Values.app.state_contract_address }}"
- name: COMMIT_INTERVAL
value: "{{ .Values.app.commit_interval }}"
volumes:
- name: "{{ .Release.Name }}-volume"
persistentVolumeClaim:
claimName: "{{ .Release.Name }}-claim"
17 changes: 17 additions & 0 deletions deployment/charts/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Default values for fuel block committer

app:
name: fuel-block-committer
ethereum_wallet_key: "${fuel_committer_eth_wallet_key}"
ethereum_rpc: "${fuel_committer_eth_rpc}"
ethereum_chain_id: "${fuel_committer_eth_chain_id}"
fuel_graphql_endpoint: "${fuel_committer_node_graphql_endpoint}"
state_contract_address: "${fuel_committer_state_contract_address}"
commit_interval: "${fuel_committer_commit_interval}"
image:
repository: "${fuel_committer_image_repository}"
tag: "${fuel_committer_image_tag}"
pullPolicy: Always
prometheus:
enabled: ${fuel_committer_prometheus_enabled}
helm_release_name: ${fuel_committer_prometheus_helm_release_name}
16 changes: 16 additions & 0 deletions deployment/scripts/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# k8s envs
k8s_provider="eks"
k8s_namespace="fuel-core"

# Faucet envs
fuel_committer_image_repository="ghcr.io/fuellabs/fuel-block-committer"
Voxelot marked this conversation as resolved.
Show resolved Hide resolved
fuel_committer_image_tag="latest"
Voxelot marked this conversation as resolved.
Show resolved Hide resolved
fuel_committer_eth_wallet_key="random"
fuel_committer_eth_rpc="https://api.infura.io"
fuel_committer_eth_chain_id="sepolia"
fuel_committer_node_graphql_endpoint="node.example.com"
fuel_committer_state_contract_address="CONTRACT_ADDRESS"
fuel_committer_commit_interval="10800"

# EKS
TF_VAR_eks_cluster_name="test-cluster"
19 changes: 19 additions & 0 deletions deployment/scripts/service-delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable

set -o allexport && source .env && set +o allexport

if [ "${k8s_provider}" == "eks" ]; then
echo "Updating your kube context locally ...."
aws eks update-kubeconfig --name ${TF_VAR_eks_cluster_name}
echo "Deleting fuel-block-committer helm chart on ${TF_VAR_eks_cluster_name} ...."
helm delete fuel-block-committer \
--namespace ${k8s_namespace} \
--wait \
--timeout 8000s \
--debug
else
echo "You have inputted a non-supported kubernetes provider in your .env"
fi
26 changes: 26 additions & 0 deletions deployment/scripts/service-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable

set -o allexport && source .env && set +o allexport

if [ "${k8s_provider}" == "eks" ]; then
echo "Updating your kube context locally ...."
aws eks update-kubeconfig --name ${TF_VAR_eks_cluster_name}
cd ../charts
mv values.yaml values.template
envsubst < values.template > values.yaml
rm values.template
echo "Deploying fuel-block-committer helm chart to ${TF_VAR_eks_cluster_name} ...."
helm upgrade fuel-block-committer . \
--values values.yaml \
--install \
--create-namespace \
--namespace=${k8s_namespace} \
--wait \
--timeout 8000s \
--debug
else
echo "You have inputted a non-supported kubernetes provider in your .env"
fi
8 changes: 7 additions & 1 deletion src/setup/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,13 @@ fn create_block_watcher(
}

pub fn setup_logger() {
tracing_subscriber::fmt::init();
tracing_subscriber::fmt()
.with_writer(std::io::stderr)
.with_ansi(false)
.with_level(true)
.with_line_number(true)
.json()
.init();
}

pub async fn setup_storage(config: &Config) -> Result<SqliteDb> {
Expand Down