Skip to main content

Set up your invironment

Section 1: Ansible Playbook

This section contains the Ansible playbook for updating and upgrading apt packages, installing essential packages, and setting up Golang.

---
- name: Update and upgrade apt packages
apt:
update_cache: yes
upgrade: dist

- name: Install essential packages
apt:
name:
- curl
- tar
- wget
- aria2
- clang
- pkg-config
- libssl-dev
- jq
- build-essential
- git
- make
- ncdu
state: present

- name: Set Golang version
set_fact:
golang_version: "1.21.1"

- name: Download Golang
get_url:
url: "https://golang.org/dl/go{{ golang_version }}.linux-amd64.tar.gz"
dest: "/tmp/go{{ golang_version }}.linux-amd64.tar.gz"

- name: Remove old Golang
file:
path: /usr/local/go
state: absent

- name: Install Golang
unarchive:
src: "/tmp/go{{ golang_version }}.linux-amd64.tar.gz"
dest: /usr/local
remote_src: yes

- name: Remove Golang archive
file:
path: "/tmp/go{{ golang_version }}.linux-amd64.tar.gz"
state: absent

- name: Add Golang to PATH
lineinfile:
path: /home/{{ ansible_user_id }}/.bash_profile
line: 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin'
create: yes

- name: Source bash_profile
shell: source /home/{{ ansible_user_id }}/.bash_profile
args:
executable: /bin/bash

Section 2: Command-Line Installation

For users who prefer to execute commands manually, the following shell commands replicate the steps of the Ansible playbook.

# Update and upgrade apt packages
sudo apt update && sudo apt dist-upgrade -y

# Install essential packages
sudo apt install -y curl tar wget aria2 clang pkg-config libssl-dev jq build-essential git make ncdu

# Set Golang version
GOLANG_VERSION="1.21.1"

# Download Golang
wget https://golang.org/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz -O /tmp/go${GOLANG_VERSION}.linux-amd64.tar.gz

# Remove old Golang
sudo rm -rf /usr/local/go

# Install Golang
sudo tar -C /usr/local -xzf /tmp/go${GOLANG_VERSION}.linux-amd64.tar.gz

# Remove Golang archive
rm /tmp/go${GOLANG_VERSION}.linux-amd64.tar.gz

# Add Golang to PATH
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> ~/.bash_profile

# Source bash_profile
source ~/.bash_profile

This structured approach ensures clarity and ease of use for both automation via Ansible and manual installation via the command line.

🛠️ IDeploying Celestia

Certainly! Below, I'll divide the given YAML script into two sections: one for the Ansible Playbook and the other for the Command-Line Installation. This will make it easier to follow along whether you're using Ansible for automation or executing commands manually.


Section 1: Ansible Playbook

This section provides the Ansible playbook, which is used to create directories, initialize and start Celestia nodes using Docker, and deploy the Celestia App for RPC endpoints.

---
---
- name: Initialize Celestia App
docker_container:
name: celestia-init
image: "{{ celestia_app_image }}"
command: "init {{ node_name }} --chain-id {{ chain_id }} --home /app/celestia-app"
volumes:
- "{{ ansible_env.HOME }}/celestia-app:/app/celestia"
ports:
- "{{ rpc_port }}:{{ rpc_port }}"
- "{{ p2p_port }}:{{ p2p_port }}"
- "{{ grpc_port }}:{{ grpc_port }}"
state: started
user: "0:0"
register: init_container

- name: Wait for Celestia Init container to complete
docker_container:
name: celestia-init
state: stopped

- name: Download Genesis File
docker_container:
name: celestia-genesis
image: "{{ celestia_app_image }}"
command: "download-genesis {{ chain_id }} --home /app/celestia-app"
volumes:
- "{{ ansible_env.HOME }}/celestia-app:/app/celestia-app"
ports:
- "{{ rpc_port }}:{{ rpc_port }}"
- "{{ p2p_port }}:{{ p2p_port }}"
- "{{ grpc_port }}:{{ grpc_port }}"
state: started
user: "0:0"
register: genesis_container

- name: Wait for Genesis container to complete
docker_container:
name: celestia-genesis
state: stopped

- name: Remove Genesis container
docker_container:
name: celestia-genesis
state: absent

- name: Run Celestia App container
docker_container:
name: celestia-app
image: "{{ celestia_app_image }}"
command: "start --home /app/celestia-app "

volumes:
- "{{ ansible_env.HOME }}/celestia-app:/app/celestia-app"
ports:
- "{{ rpc_port }}:{{ rpc_port }}" # RPC Port
- "{{ p2p_port }}:{{ p2p_port }}" # P2P Port
- "{{ grpc_port }}:{{ grpc_port }}" # gRPC Port
state: started
user: "0:0"
register: start_container

Explanation of Ansible Playbook

Variables

  • celestia_app_image: Docker image for Celestia.
  • node_name: Celestia node name.
  • chain_id: Chain ID for the network.
  • rpc_port, p2p_port, grpc_port: Ports for RPC, P2P, and gRPC services.

Steps

  1. Initialize Celestia App: Initializes the Celestia node.

  2. Download Genesis File: Fetches the genesis file required for node operation.

  3. Run Celestia App: Starts the Celestia application.


Section 2: Command-Line Installation

For users who prefer manual execution, the following shell commands replicate the Ansible playbook tasks, providing step-by-step instructions to perform the setup manually.

Create Directory for Node Store

# Create directory for node store
mkdir -p ~/my-node-store

# Set Docker environment variables
export NODE_TYPE=<node_type> # e.g., 'light', 'full', etc.
export P2P_NETWORK=<p2p_network> # e.g., 'testnet', 'mainnet', etc.
export RPC_URL=<rpc_url> # e.g., 'http://127.0.0.1:26657'

Initialize Celestia Node Store

# Initialize Celestia node store
docker run --rm -u 0:0 \
-e NODE_TYPE=$NODE_TYPE \
-e P2P_NETWORK=$P2P_NETWORK \
-e HOME=/devops \
-v ~/my-node-store:/home/celestia \
ghcr.io/celestiaorg/celestia-node:v0.14.0 \
celestia $NODE_TYPE init

Start Celestia Light Node

# Start Celestia light node
docker run -d --name celestia_light -u 0:0 \
-e NODE_TYPE=$NODE_TYPE \
-e P2P_NETWORK=$P2P_NETWORK \
-e RPC_URL=$RPC_URL \
-e HOME=/devops \
-v ~/my-node-store:/home/celestia \
ghcr.io/celestiaorg/celestia-node:v0.14.0 \
celestia $NODE_TYPE start --core.ip $RPC_URL --p2p.network $P2P_NETWORK