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

Initial version - celestia app charts #84

Merged
merged 13 commits into from
Dec 11, 2024
64 changes: 64 additions & 0 deletions .github/workflows/releaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,70 @@ on:
workflow_dispatch:

jobs:
# common-celestia-app
release-common-celestia-app:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"

- name: Run chart-releaser for common-celestia-app
uses: helm/[email protected]
with:
charts_dir: "common-charts"
packages_with_index: "true"
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

# celestia-app
release-celestia-app:
permissions:
contents: write
runs-on: ubuntu-latest
needs: release-common-celestia-app
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"

- name: Install Helm
uses: azure/setup-helm@v4
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

- name: Add Helm Repositories
run: |
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add celestiaorg https://celestiaorg.github.io/helm-charts
helm repo update

- name: Update Helm Dependencies for celestia-app
run: |
helm dependency update charts/celestia-app

- name: Run chart-releaser for celestia-app
uses: helm/[email protected]
with:
charts_dir: "charts"
packages_with_index: "true"
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

# common-celestia-node
release-common-celestia-node:
permissions:
Expand Down
7 changes: 5 additions & 2 deletions charts/celestia-app/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ annotations:
category: celestia
licenses: Apache-2.0
apiVersion: v2
appVersion: v2.2.0
appVersion: v3.0.1
dependencies:
- name: common-celestia-app
version: 0.1.1
tty47 marked this conversation as resolved.
Show resolved Hide resolved
repository: https://celestiaorg.github.io/helm-charts
- name: common
repository: oci://registry-1.docker.io/bitnamicharts
tags:
Expand All @@ -21,4 +24,4 @@ maintainers:
name: celestia-app
sources:
- https://github.com/celestiaorg/celestia-app
version: 0.3.1
version: 0.3.2
199 changes: 124 additions & 75 deletions charts/celestia-app/README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions charts/celestia-app/charts/common-celestia-app
40 changes: 40 additions & 0 deletions charts/celestia-app/files/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh
# CELESTIA_HOME should be set in the environment
# APP_ID should be set in the environment
# CHAIN_ID should be set in the environment
# INITIAL_TIA_AMOUNT should be set in the environment
# STAKING_TIA_AMOUNT should be set in the environment
# EVM_ADDRESS should be set in the environment

KEY_NAME="${APP_ID}-${CHAIN_ID}"

echo "---------------------------------------------------"
echo "Checking if the file [genesis.json] exists or not..."
echo "---------------------------------------------------"
if [[ ! -f "$CELESTIA_HOME/config/genesis.json" ]]; then
celestia-appd init "${APP_ID}" --home "${CELESTIA_HOME}" --chain-id "${CHAIN_ID}"

# yes n | celestia-appd keys add "${KEY_NAME}" --home "${CELESTIA_HOME}" --no-backup
celestia-appd keys add "${KEY_NAME}" --home "${CELESTIA_HOME}" --no-backup

account_address=$(celestia-appd keys show "${KEY_NAME}" -a --home "${CELESTIA_HOME}")
celestia-appd add-genesis-account "${account_address}" "${INITIAL_TIA_AMOUNT}" --home "${CELESTIA_HOME}"

celestia-appd gentx "${KEY_NAME}" "${STAKING_TIA_AMOUNT}" --home "${CELESTIA_HOME}" --chain-id "${CHAIN_ID}"

celestia-appd collect-gentxs --home "${CELESTIA_HOME}"

echo "Copying the keys to the config path..."
mv $CELESTIA_HOME/config/priv_validator_key.json $CELESTIA_HOME/keys
mv $CELESTIA_HOME/config/node_key.json $CELESTIA_HOME/keys
fi

echo "Configuration applied [$CELESTIA_HOME/config/config.toml]"
echo "---------------------------------------------------"
cat $CELESTIA_HOME/config/config.toml
echo "Configuration applied [$CELESTIA_HOME/config/app.toml]"
echo "---------------------------------------------------"
cat $CELESTIA_HOME/config/app.toml
echo "Configuration applied [$CELESTIA_HOME/config/client.toml]"
echo "---------------------------------------------------"
cat $CELESTIA_HOME/config/client.toml
125 changes: 125 additions & 0 deletions charts/celestia-app/files/val-maker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/bin/sh

set -e

# CELESTIA_HOME should be set in the environment
# CHAIN_ID should be set in the environment
# FUND_TIA_AMOUNT should be set in the environment
# STAKING_TIA_AMOUNT should be set in the environment

# CONSENSUS_VALIDATOR_POD should be set in the environment
# CONSENSUS_VALIDATOR_NAMEPACE should be set in the environment

# CONENSUS_VALIDATOR_POD_NOMINATEES should be set in the environment

CONSENSUS_VALIDATOR_KEY_NAME="${CONSENSUS_VALIDATOR_POD}-${CHAIN_ID}"
CONTAINER_NAME="app"

# wait until validator is ready and all containers are ready
echo "---------------------------------------------------"
echo "Waiting for ${CONSENSUS_VALIDATOR_POD} to be ready..."
echo "---------------------------------------------------"
kubectl wait --for=condition=Ready pod/${CONSENSUS_VALIDATOR_POD} -n "${CONSENSUS_VALIDATOR_NAMESPACE}" --timeout=300s

for CONENSUS_VALIDATOR_POD_NOMINATEE in $(echo $CONENSUS_VALIDATOR_POD_NOMINATEES | sed "s/,/ /g")
do

# wait until validator is ready and all containers are ready
echo "---------------------------------------------------"
echo "Waiting for ${CONENSUS_VALIDATOR_POD_NOMINATEE} to be ready..."
echo "---------------------------------------------------"
until kubectl wait --for=condition=Ready pod/${CONENSUS_VALIDATOR_POD_NOMINATEE} -n "${CONSENSUS_VALIDATOR_NAMESPACE}" --timeout=300s; do
echo "Command timed out, retrying..."
sleep 5
done

# fetch account address from nominatee
echo "---------------------------------------------------"
echo "Fetching account address from ${CONENSUS_VALIDATOR_POD_NOMINATEE}"
echo "---------------------------------------------------"
# Extract the desired part of the string, the key name is different than the pod name
validator_name=$(echo "${CONENSUS_VALIDATOR_POD_NOMINATEE}" | cut -d'-' -f1-3)
fetch_address_command="celestia-appd keys show ${validator_name}-0-${CHAIN_ID} -a --home ${CELESTIA_HOME}"

echo $fetch_address_command
nominatee_address=$(kubectl -n ${CONSENSUS_VALIDATOR_NAMESPACE} exec -t ${CONENSUS_VALIDATOR_POD_NOMINATEE} --container=${CONTAINER_NAME} -- /bin/sh -c "${fetch_address_command}")
echo "nominatee_address: ${nominatee_address}"

# fetch validator address from nominatee
echo "---------------------------------------------------"
echo "Fetching validator address from ${CONENSUS_VALIDATOR_POD_NOMINATEE}"
echo "---------------------------------------------------"
fetch_validator_address_command="celestia-appd keys show ${validator_name}-0-${CHAIN_ID} -a --bech val --home ${CELESTIA_HOME}"

echo $fetch_validator_address_command
validator_address=$(kubectl -n ${CONSENSUS_VALIDATOR_NAMESPACE} exec -t ${CONENSUS_VALIDATOR_POD_NOMINATEE} --container=${CONTAINER_NAME} -- /bin/sh -c "${fetch_validator_address_command}")
echo "validator_address: ${validator_address}"

# fetch validator pubkey from nominatee
echo "---------------------------------------------------"
echo "Fetching validator pubkey from ${CONENSUS_VALIDATOR_POD_NOMINATEE}"
echo "---------------------------------------------------"
fetch_pubkey_command="celestia-appd tendermint show-validator --home ${CELESTIA_HOME}"

echo $fetch_pubkey_command
nominatee_pubkey=$(kubectl -n ${CONSENSUS_VALIDATOR_NAMESPACE} exec -t ${CONENSUS_VALIDATOR_POD_NOMINATEE} --container=${CONTAINER_NAME} -- /bin/sh -c "${fetch_pubkey_command}")
echo "nominatee_pubkey: ${nominatee_pubkey}"

# check if nominatee is already a validator
echo "---------------------------------------------------"
echo "Checking if ${CONENSUS_VALIDATOR_POD_NOMINATEE} is already a validator"
echo "---------------------------------------------------"
status_command="celestia-appd query staking validator ${validator_address} --chain-id ${CHAIN_ID} --home ${CELESTIA_HOME}"

echo $status_command
if kubectl -n ${CONSENSUS_VALIDATOR_NAMESPACE} exec -t ${CONENSUS_VALIDATOR_POD_NOMINATEE} --container=${CONTAINER_NAME} -- /bin/sh -c "${status_command}" > /dev/null 2>&1; then
echo "${CONENSUS_VALIDATOR_POD_NOMINATEE} is already a validator, skipping..."
continue
fi

# fund nominatee from validator
echo "---------------------------------------------------"
echo "Funding ${CONENSUS_VALIDATOR_POD_NOMINATEE} from ${CONSENSUS_VALIDATOR_POD}"
echo "---------------------------------------------------"
send_command="celestia-appd tx bank send \
${CONSENSUS_VALIDATOR_KEY_NAME} \
${nominatee_address} \
${FUND_TIA_AMOUNT} \
--chain-id ${CHAIN_ID} \
--fees 22000utia \
--home ${CELESTIA_HOME} \
--yes"

echo $send_command
kubectl -n ${CONSENSUS_VALIDATOR_NAMESPACE} exec -t ${CONSENSUS_VALIDATOR_POD} --container=${CONTAINER_NAME} -- /bin/sh -c "${send_command}"

sleep 15

# make nominatee a validator
echo "---------------------------------------------------"
echo "Making ${CONENSUS_VALIDATOR_POD_NOMINATEE} a validator"
echo "---------------------------------------------------"
stake_command="celestia-appd tx staking create-validator \
--amount ${STAKING_TIA_AMOUNT} \
--pubkey '${nominatee_pubkey}' \
--moniker ${CONENSUS_VALIDATOR_POD_NOMINATEE}-${CHAIN_ID} \
--chain-id ${CHAIN_ID} \
--commission-rate 0.1 \
--commission-max-rate 0.2 \
--commission-max-change-rate 0.01 \
--min-self-delegation 1000000 \
--from ${CONENSUS_VALIDATOR_POD_NOMINATEE}-${CHAIN_ID} \
--keyring-backend test \
--fees 21000utia \
--home ${CELESTIA_HOME} \
--yes"

echo $stake_command
kubectl -n ${CONSENSUS_VALIDATOR_NAMESPACE} exec -t ${CONENSUS_VALIDATOR_POD_NOMINATEE} --container=${CONTAINER_NAME} -- /bin/sh -c "${stake_command}"
done

# I'm done and wait forever
echo "---------------------------------------------------"
echo "I'm done and wait forever"
echo "---------------------------------------------------"
sleep infinity
37 changes: 31 additions & 6 deletions charts/celestia-app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,49 @@ Return the proper app image name
Return the proper image name (for the init container volume-permissions image)
*/}}
{{- define "app.volumePermissions.image" -}}
{{- include "common.images.image" ( dict "imageRoot" .Values.volumePermissions.image "global" .Values.global ) -}}
{{- include "common.images.image" ( dict "imageRoot" .Values.app.volumePermissions.image "global" .Values.global ) -}}
{{- end -}}

{{/*
Return the proper Docker Image Registry Secret Names
*/}}
{{- define "app.imagePullSecrets" -}}
{{- include "common.images.renderPullSecrets" (dict "images" (list .Values.app.image .Values.volumePermissions.image) "context" $) -}}
{{- $pullSecrets := list }}

{{- if .Values.global.imagePullSecrets -}}
{{- range .Values.global.imagePullSecrets -}}
{{- $pullSecrets = append $pullSecrets . -}}
{{- end -}}
{{- end -}}

{{- if .Values.app.image.pullSecrets -}}
{{- range .Values.app.image.pullSecrets -}}
{{- $pullSecrets = append $pullSecrets . -}}
{{- end -}}
{{- end -}}

{{- if .Values.app.volumePermissions.image.pullSecrets -}}
{{- range .Values.app.volumePermissions.image.pullSecrets -}}
{{- $pullSecrets = append $pullSecrets . -}}
{{- end -}}
{{- end -}}

{{- if (not (empty $pullSecrets)) }}
imagePullSecrets:
{{- range $pullSecrets }}
- name: {{ . }}
{{- end }}
{{- end }}
{{- end -}}

{{/*
Create the name of the service account to use
Return the proper service account name
*/}}
{{- define "app.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "common.names.fullname" .) .Values.serviceAccount.name }}
{{- if .Values.app.serviceAccount.create -}}
{{ default (include "common.names.fullname" .) .Values.app.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{ default "default" .Values.app.serviceAccount.name }}
{{- end -}}
{{- end -}}

Expand Down
6 changes: 4 additions & 2 deletions charts/celestia-app/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.app.rbac.create }}
kind: ClusterRoleBinding
apiVersion: {{ include "common.capabilities.rbac.apiVersion" . }}
metadata:
Expand All @@ -10,8 +11,9 @@ metadata:
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ template "common.names.fullname" . }}
name: {{ include "common.names.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ template "app.serviceAccountName" . }}
name: {{ .Values.app.serviceAccount.name }}
namespace: {{ include "common.names.namespace" . | quote }}
{{- end }}
Loading
Loading