Compare commits

..

3 Commits

Author SHA1 Message Date
Vivek Teega
b60a489df4 Squashed commit of the following:
commit 5d82cb79f9
Author: Vivek Teega <vivek.teega@gmail.com>
Date:   Sat Aug 3 15:30:18 2024 +0530

    remove build workflows

commit 14e392ee8a
Merge: 24f8a63 32821cd
Author: Vivek Teega <vivek.teega@gmail.com>
Date:   Sat Aug 3 15:20:12 2024 +0530

    Merge pull request #15 from vivekteega/upgrade/separate-images

    Merged changes from source-branch as a single commit

commit 32821cd482
Author: Vivek Teega <vivek.teega@gmail.com>
Date:   Sat Aug 3 14:29:00 2024 +0530

    Merged changes from source-branch as a single commit

commit 24f8a637d2
Author: Vivek Teega <vivek.teega@gmail.com>
Date:   Wed Jul 3 21:29:30 2024 +0530

    Preparation for CI CD

commit 95393696ed
Author: Vivek Teega <vivek.teega@gmail.com>
Date:   Tue Jul 2 15:52:47 2024 +0530

    Updated Readme, added comments, minor changes and cleanup

commit 9cbfe96d44
Author: Vivek Teega <vivek.teega@gmail.com>
Date:   Tue Jul 2 15:17:58 2024 +0530

    Structure set in place for Docker compose based deployment

commit b7d99fcd08
Author: Vivek Teega <vivek.teega@gmail.com>
Date:   Wed Jun 12 20:08:31 2024 +0530

    Added changes to entrypoint.sh for frontend to take in IP of backend container for RPC connection

commit a162ab19f3
Author: Vivek Teega <vivek.teega@gmail.com>
Date:   Tue Jun 11 15:48:12 2024 +0530

    Build single image, but separate execution

commit 15b9955f98
Author: Vivek Teega <vivek.teega@gmail.com>
Date:   Sat Jun 8 23:11:36 2024 +0000

    Separated images, attached same volume and port mapping

commit 81b6cee363
Author: Vivek Teega <vivek.teega@gmail.com>
Date:   Sun Jun 9 03:52:19 2024 +0530

    Cleanup and roadmap

commit 76a911542b
Merge: 1f463bd 00b2ca2
Author: Vivek Teega <vivek.teega@gmail.com>
Date:   Mon Jun 3 15:16:45 2024 +0530

    Merge pull request #7 from asif158/upgrade/sysbox-independent

    Initial changes for removing sysbox dependency
2024-08-03 15:33:17 +05:30
Vivek Teega
0114d71b94
Testing workflow 2024-07-03 22:11:41 +05:30
asif158
44c812ae77 Add: new-deb files and dockerfile 2024-06-04 08:51:34 +05:30
17 changed files with 271 additions and 335 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

12
.env.example Normal file
View File

@ -0,0 +1,12 @@
BACKEND_IMAGE=vivekteega/blockbook:1.0.0
FRONTEND_IMAGE=vivekteega/blockbook:1.0.0
BACKEND_CONTAINER_NAME=blockbook-backend
FRONTEND_CONTAINER_NAME=blockbook-frontend
BACKEND_BOOTSTRAP_FILE=/path/to/your/bootstrap-blockbook-flo-mainnet-backend.tar.gz # Set to empty string if not provided
FRONTEND_BOOTSTRAP_FILE=/path/to/your/bootstrap-blockbook-flo-mainnet-frontend.tar.gz # Set to empty string if not provided
BACKEND_BOOTSTRAP_URL=/path/to/your/bootstrap-blockbook-flo-mainnet-backend.tar.gz # Set to empty string if not provided
FRONTEND_BOOTSTRAP_URL=/path/to/your/bootstrap-blockbook-flo-mainnet-frontend.tar.gz # Set to empty string if not provided
BACKEND_PORT_1=38366
BACKEND_PORT_2=8066
FRONTEND_PORT_1=9166
FRONTEND_PORT_2=9066

36
.github/workflows/docker-image.yml vendored Normal file
View File

@ -0,0 +1,36 @@
name: Docker Image CI
on:
push:
branches: [ "upgrade/separate-images/ci-cd-testing" ]
pull_request:
branches: [ "upgrade/separate-images/ci-cd-testing" ]
jobs:
build:
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/blockbook:1.0.0
- name: Log out from Docker Hub
run: docker logout

3
.gitignore vendored
View File

@ -1 +1,2 @@
.env
.env
playbook.yml

43
Dockerfile Executable file → Normal file
View File

@ -1,32 +1,21 @@
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
# Backend
COPY ./deb-files/backend-flo_0.15.1.1-satoshilabs-1_amd64.deb /opt/backend.deb
COPY ./deb-files/blockbook-flo_0.4.0_amd64.deb /opt/blockbook.deb
# Copying files to the container
COPY /deb-files-mainnet/backend-flo_0.15.1.1-satoshilabs-1_amd64.deb /tmp/backend-flo.deb
COPY /deb-files-mainnet/blockbook-flo_0.4.0_amd64.deb /tmp/blockbook-flo.deb
RUN apt update && apt install -y /opt/backend.deb /opt/blockbook.deb curl && \
sed -i 's/daemon=1/daemon=0/' /opt/coins/nodes/flo/flo.conf && \
sed -i '/rpcport=8066/a rpcallowip=0.0.0.0/0' /opt/coins/nodes/flo/flo.conf && \
echo "addnode=ramanujam.ranchimall.net" >> /opt/coins/nodes/flo/flo.conf && \
echo "addnode=turing.ranchimall.net" >> /opt/coins/nodes/flo/flo.conf && \
echo "addnode=stevejobs.ranchimall.net" >> /opt/coins/nodes/flo/flo.conf && \
echo "addnode=brahmagupta.ranchimall.net" >> /opt/coins/nodes/flo/flo.conf && \
echo "addnode=feynman.ranchimall.net" >> /opt/coins/nodes/flo/flo.conf
# Installing Blockbook and Supervisor
RUN apt-get update && \
apt-get install -y /tmp/backend-flo.deb /tmp/blockbook-flo.deb supervisor wget && \
rm /tmp/backend-flo.deb /tmp/blockbook-flo.deb && \
rm -rf /var/lib/apt/lists/*
WORKDIR /opt/coins/blockbook/flo
# Copying conf file after installing supervisor to fix scripting error
COPY /deb-files-mainnet/supervisord.conf /etc/supervisor/supervisord.conf
COPY start.sh /tmp
# Configuring backend as forground process under supervisord
RUN sed -i "s/daemon=1/daemon=0/g" /opt/coins/nodes/flo/flo.conf &&\
chmod +x /tmp/start.sh
EXPOSE 9166
VOLUME /opt/coins
# CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
CMD ["/bin/bash", "-c", "/tmp/start.sh"]
# check logs
# tail -f /opt/coins/data/flo/backend/debug.log
# tail -f /opt/coins/blockbook/flo/logs/blockbook.INFO
# Execution
COPY ./entrypoint.sh /opt/entrypoint.sh
RUN chmod +x /opt/entrypoint.sh
ENTRYPOINT ["/opt/entrypoint.sh"]

View File

@ -1,39 +0,0 @@
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
# Copying files to the container
# COPY /deb-files-testnet/peers.dat /tmp
COPY /deb-files-testnet/backend-flo-testnet_0.15.1.1-satoshilabs-1_amd64.deb /tmp/backend-flo.deb
COPY /deb-files-testnet/blockbook-flo-testnet_0.4.0_amd64.deb /tmp/blockbook-flo.deb
# Installing Blockbook and Supervisor
RUN apt-get update && \
apt-get install -y /tmp/backend-flo.deb /tmp/blockbook-flo.deb supervisor wget && \
rm /tmp/backend-flo.deb /tmp/blockbook-flo.deb && \
rm -rf /var/lib/apt/lists/*
# Copying conf file after installing supervisor to fix scripting error
COPY /deb-files-testnet/supervisord.conf /etc/supervisor/supervisord.conf
COPY start.sh /tmp
# Configuring backend as forground process and adding nodes to sync backend
RUN sed -i "s/daemon=1/daemon=0/g" /opt/coins/nodes/flo_testnet/flo_testnet.conf && \
sed -i '$a addnode=ramanujam.ranchimall.net\naddnode=turing.ranchimall.net\naddnode=stevejobs.ranchimall.net\naddnode=brahmagupta.ranchimall.net\naddnode=feynman.ranchimall.net' /opt/coins/nodes/flo_testnet/flo_testnet.conf && \
chmod +x /tmp/start.sh
# RUN cd /opt/coins/nodes/flo_testnet && \
# /opt/coins/nodes/flo_testnet/bin/flod --testnet -datadir=/opt/coins/data/flo_testnet/backend -conf=/opt/coins/nodes/flo_testnet/flo_testnet.conf -pid=/run/flo_testnet/flo_testnet.pid
# RUN mv /tmp/peers.dat /opt/coins/data/flo_testnet/backend/testnet4/peers.dat
EXPOSE 19166
VOLUME /opt/coins
# CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
CMD ["/bin/bash", "-c", "/tmp/start.sh"]
# check logs
# tail -f /opt/coins/data/flo_testnet/backend/testnet4/debug.log
# tail -f /opt/coins/blockbook/flo_testnet/logs/blockbook.INFO

176
README.md
View File

@ -1,166 +1,48 @@
# Blockbook Docker (Single Container)
# Blockbook docker
This guide will help you build and run the Docker image for Blockbook Mainnet and Testnet, which is based on Ubuntu 22.04 and includes both backend and frontend components in a single container.
## Prerequisites
- [Docker installed on your machine](https://docs.docker.com/engine/install/).
- Clone or download the repository to your local machine.
## Roadmap for upgrade
- [ ] How to set this up in production
- [ ] Think of how Blockbook container will detect the status of backend container
- [ ] Figure out if multiple volume path need to be mounted
- [ ] See if creating a new network for both the containers will be a good option.
---
- [X] [Unable to build frontend separately since having backend package installed is a dependency] Create separate images for both backend and blockbook.
- [X] Attach the same volume to both the running containers of the images.
# Mainnet
## Quickstart
Steps to build the Docker image for Mainnet.
To run the services using this file create a .env file using .env.example file, fill info and run the following command in the same directory:
- **Building the Docker Image**
Navigate to the directory where the repository is cloned and build the Docker image:
```sh
git clone https://github.com/ranchimall/blockbook-docker
cd blockbook-docker
docker build -f Dockerfile -t ranchimall/blockbook-mainnet:1.0.0 .
```
- **Running the Docker Container**
Create a named volume for persistent storage:
```sh
docker volume create mainnet
```
Run the Docker container in detached mode and map port `9166` of the container to port `9166` (or any other port) on the host machine (`-p host-port:container-port`):
```sh
docker run -d -e ZIP=false -e NETWORK=mainnet --name blockbook-mainnet -p 9166:9166 --mount source=mainnet,target=/opt/coins ranchimall/blockbook-mainnet:1.0.0
```
- **Accessing the Frontend**
Once the Docker container is running, you can access the frontend of the application by navigating to: [https://localhost:9166](https://localhost:9166) in your web browser.
- **Accessing Logs**
To check the logs, you can access the container shell and use the `tail` command:
```sh
docker exec -it blockbook-mainnet bash
```
To view the logs of the backend and frontend, run:
```sh
# Backend logs
tail -f /opt/coins/data/flo/backend/debug.log
# Frontend logs
tail -f /opt/coins/blockbook/flo/logs/blockbook.INFO
```
---
# Testnet
Steps to build the Docker image for Testnet.
- **Building the Docker Image**
Navigate to the directory where the repository is cloned or downloaded and build the Docker image:
```sh
cd blockbook-docker
docker build -f Dockerfile-testnet -t ranchimall/blockbook-testnet:1.0.0 .
```
- **Running the Docker Container**
Create a named volume for persistent storage:
```sh
docker volume create testnet
```
Run the Docker container in detached mode and map port `19166` of the container to port `19166` (or any other port) on the host machine (`-p host-port:container-port`):
```sh
docker run -d -e ZIP=false -e NETWORK=testnet --name blockbook-testnet -p 19166:19166 --mount source=testnet,target=/opt/coins ranchimall/blockbook-testnet:1.0.0
```
- **Accessing the Frontend**
Once the Docker container is running, you can access the frontend of the application by navigating to: [https://localhost:19166](https://localhost:19166) in your web browser.
- **Accessing Logs**
To check the logs, you can access the container shell and use the `tail` command:
```sh
docker exec -it blockbook-testnet bash
```
To view the logs of the backend and frontend, run:
```sh
# Backend logs
tail -f /opt/coins/data/flo_testnet/backend/testnet4/debug.log
# Frontend logs
tail -f /opt/coins/blockbook/flo_testnet/logs/blockbook.INFO
```
## Environment Variables
Blockbook uses environment variables to allow for configuration settings. You set the environment variables in your Docker run startup command. Here are the config settings offered by this image:
- NETWORK: [mainnet|testnet] The FLO network you wish to run the Blockbook on.
- ZIP: [true|false] To download the bootstrap data or not to speed up the syncing of blocks, which will be reflected in Blockbook.
- TESTNET_ZIP_URL: The URL for Testnet to download the zip for bootstrapping Blockbook (Testnet).
- MAINNET_ZIP_URL: The URL for Mainnet to download the zip for bootstrapping Blockbook (Mainnet).
You can use the `--env-file` flag to pass these environments through a file during runtime. Create a `.env` file in the same directory as your project, using the `.env.example` file as a guide. Then, run your app with the following command to load the environment variables from the file:
```sh
#to run mainnet add mainnet Environment Variables.
docker run -d --env-file .env --name blockbook-mainnet -p 9166:9166 --mount source=mainnet,target=/opt/coins ranchimall/blockbook-mainnet:1.0.0
#to run testnet add testnet Environment Variables.
docker run -d --env-file .env -name blockbook-testnet -p 19166:19166 --mount source=testnet,target=/opt/coins ranchimall/blockbook-testnet:1.0.0
```
sudo docker-compose up -d
```
## Additional Commands
## Running blockbook manually
- **Stopping the Docker Container:**
```
To stop the container, use:
docker volume create blockbook
```sh
docker stop <containername>
```
docker network create blockbook
- **Removing the Docker Container:**
# Run backend in "it" mode for testing
docker run -it --name blockbook-backend --mount source=blockbook,target=/opt -p 38366:38366 -p 8066:8066 --network=blockbook vivekteega/blockbook:1.0.0 backend
To remove the container, use:
# Run backend in daemon mode for production
docker run -d --name blockbook-backend --mount source=blockbook,target=/opt -p 38366:38366 -p 8066:8066 --network=blockbook vivekteega/blockbook:1.0.0 backend
```sh
docker rm <containername>
```
# Run backend in daemon mode for production with Bootstrap
docker run -d --name blockbook-backend --mount source=blockbook,target=/opt -p 38366:38366 -p 8066:8066 --network=blockbook --env BOOTSTRAP_URL=https://bootstrap.ranchimall.net/blockbook-flo-backend1.tar.gz vivekteega/blockbook:1.0.0 backend
- **Removing the Docker Image:**
To remove the image, use:
# Run frontend in "it" mode for testing
docker run -it --name blockbook-frontend --mount source=blockbook,target=/opt -p 9166:9166 -p 9066:9066 --network=blockbook vivekteega/blockbook:1.0.0 frontend 172.20.0.2
```sh
docker rmi <imagename>
```
# Run frontend in daemon mode for production
docker run -d --name blockbook-frontend --mount source=blockbook,target=/opt -p 9166:9166 -p 9066:9066 --network=blockbook vivekteega/blockbook:1.0.0 frontend 172.20.0.2
Replace `<imagename>` and `<containername>` with the actual image name and container name or ID, respectively.
# Bootstrap
docker run -d --name blockbook-frontend --mount source=blockbook,target=/opt -p 9166:9166 -p 9066:9066 --network=blockbook --env BOOTSTRAP_URL=https://bootstrap.ranchimall.net/blockbook-flo-frontend.tar.gz vivekteega/blockbook:1.0.0 frontend 172.20.0.2
## Troubleshooting
- Ensure that no other application is using port `9166` or `19166` on your host machine.
- If you encounter issues, check the Docker container logs:
```sh
docker logs <containername>
```
```

View File

@ -1,37 +0,0 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/log/supervisor
# Enable communication to supervised processes
[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
[program:backend-flo]
command=/opt/coins/nodes/flo/bin/flod -datadir=/opt/coins/data/flo/backend -conf=/opt/coins/nodes/flo/flo.conf -pid=/run/flo/flo.pid
directory=/opt/coins/nodes/flo
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/supervisor/backend-flo.out.log
stderr_logfile=/var/log/supervisor/backend-flo.err.log
[program:blockbook-flo]
command=/opt/coins/blockbook/flo/bin/blockbook -blockchaincfg=/opt/coins/blockbook/flo/config/blockchaincfg.json -datadir=/opt/coins/data/flo/blockbook/db -sync -internal=:9066 -public=:9166 -certfile=/opt/coins/blockbook/flo/cert/blockbook -explorer= -log_dir=/opt/coins/blockbook/flo/logs -dbcache=1073741824
directory=/opt/coins/blockbook/flo
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/supervisor/blockbook-flo.out.log
stderr_logfile=/var/log/supervisor/blockbook-flo.err.log
[include]
files = /etc/supervisor/conf.d/*.conf

Binary file not shown.

View File

@ -1,37 +0,0 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/log/supervisor
# Enable communication to supervised processes
[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
[program:backend-flo-testnet]
command=/opt/coins/nodes/flo_testnet/bin/flod --testnet -datadir=/opt/coins/data/flo_testnet/backend -conf=/opt/coins/nodes/flo_testnet/flo_testnet.conf -pid=/run/flo_testnet/flo_testnet.pid
directory=/opt/coins/nodes/flo_testnet
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/supervisor/backend-flo-testnet.log
stderr_logfile=/var/log/supervisor/backend-flo-testnet.err
[program:blockbook-flo-testnet]
command=/opt/coins/blockbook/flo_testnet/bin/blockbook -blockchaincfg=/opt/coins/blockbook/flo_testnet/config/blockchaincfg.json -datadir=/opt/coins/data/flo_testnet/blockbook/db -sync -internal=:19066 -public=:19166 -certfile=/opt/coins/blockbook/flo_testnet/cert/blockbook -explorer= -log_dir=/opt/coins/blockbook/flo_testnet/logs -dbcache=1073741824
directory=/opt/coins/blockbook/flo_testnet
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/supervisor/blockbook-flo-testnet.log
stderr_logfile=/var/log/supervisor/blockbook-flo-testnet.err
[include]
files = /etc/supervisor/conf.d/*.conf

45
docker-compose.yml Normal file
View File

@ -0,0 +1,45 @@
version: '3.8'
services:
blockbook-backend:
image: ${BACKEND_IMAGE}
container_name: ${BACKEND_CONTAINER_NAME}
networks:
- blockbook
volumes:
- blockbook:/opt
- ${BACKEND_BOOTSTRAP_FILE:-/dev/null}:/local-bootstrap/bootstrap-blockbook-flo-mainnet-backend.tar.gz # Use /dev/null if no file
ports:
- "${BACKEND_PORT_1}:38366"
- "${BACKEND_PORT_2}:8066"
command: backend
environment:
- BOOTSTRAP_FILE=/local-bootstrap/bootstrap-blockbook-flo-mainnet-backend.tar.gz # Set to empty string if not provided
- BOOTSTRAP_URL=${BACKEND_BOOTSTRAP_URL:-} # Set to empty string if not provided
blockbook-frontend:
image: ${FRONTEND_IMAGE}
container_name: ${FRONTEND_CONTAINER_NAME}
networks:
- blockbook
volumes:
- blockbook:/opt
- ${FRONTEND_BOOTSTRAP_FILE:-/dev/null}:/local-bootstrap/bootstrap-blockbook-flo-mainnet-frontend.tar.gz # Use /dev/null if no file
ports:
- "${FRONTEND_PORT_1}:9166"
- "${FRONTEND_PORT_2}:9066"
depends_on:
- blockbook-backend
entrypoint: /bin/sh -c
command: >
"/opt/entrypoint.sh frontend $(getent hosts blockbook-backend | awk '{ print $1 }')"
environment:
- BOOTSTRAP_FILE=/local-bootstrap/bootstrap-blockbook-flo-mainnet-frontend.tar.gz # Set to empty string if not provided
- BOOTSTRAP_URL=${FRONTEND_BOOTSTRAP_URL:-} # Set to empty string if not provided
volumes:
blockbook:
networks:
blockbook:
driver: bridge

131
entrypoint.sh Normal file
View File

@ -0,0 +1,131 @@
#!/bin/sh
set -e
# Paths for frontend bootstrap files
FRONTEND_BOOTSTRAP_URL_FILE="/opt/coins/data/flo/blockbook/bootstrap-url.txt"
FRONTEND_BOOTSTRAP_FILE_HASH_FILE="/opt/coins/data/flo/blockbook/bootstrap-file-hash.txt"
# Paths for backend bootstrap files
BACKEND_BOOTSTRAP_URL_FILE="/opt/coins/data/flo/backend/bootstrap-url.txt"
BACKEND_BOOTSTRAP_FILE_HASH_FILE="/opt/coins/data/flo/backend/bootstrap-file-hash.txt"
# Function to calculate the hash of a file
calculate_file_hash() {
local file=$1
sha256sum "$file" | awk '{print $1}'
}
# Function to update config file
update_config_file() {
local config_path=$1
local new_ip=$2
if [ -n "$new_ip" ]; then
echo "Updating config file: $config_path with IP: $new_ip"
if ! sed -i "s/127.0.0.1/$new_ip/g" "$config_path"; then
echo "Failed to update config file: $config_path"
exit 1
fi
fi
}
# Function to handle bootstrap from URL
handle_bootstrap_url() {
local bootstrap_url=$1
local destination_dir=$2
local url_file=$3
local bootstrap_file=$4
if [ -z "$bootstrap_url" ]; then
echo "No bootstrap URL provided, skipping download."
return
fi
if [ -f "$url_file" ]; then
local existing_url
existing_url=$(cat "$url_file")
if [ "$existing_url" = "$bootstrap_url" ]; then
echo "Bootstrap URL already processed, skipping download and extraction."
return
fi
fi
echo "Downloading bootstrap file from: $bootstrap_url"
curl -L -o "/tmp/$bootstrap_file" "$bootstrap_url"
echo "Cleaning and extracting bootstrap file to: $destination_dir"
mkdir -p "$destination_dir"
rm -rf "$destination_dir"/*
tar -xzvf "/tmp/$bootstrap_file" -C "$destination_dir"
rm "/tmp/$bootstrap_file"
echo "$bootstrap_url" > "$url_file"
}
# Function to handle bootstrap from file
handle_bootstrap_file() {
local bootstrap_file=$1
local destination_dir=$2
local hash_file=$3
if [ -z "$bootstrap_file" ] || [ ! -f "$bootstrap_file" ]; then
echo "No valid bootstrap file provided, skipping extraction."
return
fi
local new_hash
new_hash=$(calculate_file_hash "$bootstrap_file")
if [ -f "$hash_file" ]; then
local existing_hash
existing_hash=$(cat "$hash_file")
if [ "$existing_hash" = "$new_hash" ]; then
echo "Bootstrap file already processed, skipping extraction."
return
fi
fi
echo "Using bootstrap file: $bootstrap_file"
echo "Cleaning and extracting bootstrap file to: $destination_dir"
mkdir -p "$destination_dir"
rm -rf "$destination_dir"/*
tar -xzf "$bootstrap_file" -C "$destination_dir"
echo "$new_hash" > "$hash_file"
}
case "$1" in
"frontend")
if [ -z "$2" ]; then
echo "Missing parameter: new_ip for frontend"
exit 1
fi
new_ip=$2
echo "Running frontend command with IP: $new_ip"
if [ -n "$BOOTSTRAP_FILE" ] && [ -f "$BOOTSTRAP_FILE" ]; then
handle_bootstrap_file "$BOOTSTRAP_FILE" "/opt/coins/data/flo/blockbook" "$FRONTEND_BOOTSTRAP_FILE_HASH_FILE"
elif [ -n "$BOOTSTRAP_URL" ]; then
handle_bootstrap_url "$BOOTSTRAP_URL" "/opt/coins/data/flo/blockbook" "$FRONTEND_BOOTSTRAP_URL_FILE" "bootstrap-frontend.tar.gz"
fi
update_config_file "/opt/coins/blockbook/flo/config/blockchaincfg.json" "$new_ip"
cd /opt/coins/blockbook/flo
exec /opt/coins/blockbook/flo/bin/blockbook -blockchaincfg=/opt/coins/blockbook/flo/config/blockchaincfg.json -datadir=/opt/coins/data/flo/blockbook/db -sync -internal=:9066 -public=:9166 -certfile=/opt/coins/blockbook/flo/cert/blockbook -explorer= -log_dir=/opt/coins/blockbook/flo/logs -dbcache=1073741824
;;
"backend")
echo "Running backend command"
if [ -n "$BOOTSTRAP_FILE" ] && [ -f "$BOOTSTRAP_FILE" ]; then
handle_bootstrap_file "$BOOTSTRAP_FILE" "/opt/coins/data/flo/backend" "$BACKEND_BOOTSTRAP_FILE_HASH_FILE"
elif [ -n "$BOOTSTRAP_URL" ]; then
handle_bootstrap_url "$BOOTSTRAP_URL" "/opt/coins/data/flo/backend" "$BACKEND_BOOTSTRAP_URL_FILE" "bootstrap-backend.tar.gz"
fi
cd /opt/coins/nodes/flo
exec /opt/coins/nodes/flo/bin/flod -datadir=/opt/coins/data/flo/backend -conf=/opt/coins/nodes/flo/flo.conf -pid=/run/flo/flo.pid
;;
*)
echo "Invalid option: $1"
echo "Usage: $0 {frontend new_ip|backend}"
exit 1
;;
esac

View File

@ -1,47 +0,0 @@
#!/bin/bash
DOWNLOAD_DIR="/tmp"
EXTRACT_DIR="/opt/coins"
ZIP_FILE="${DOWNLOAD_DIR}/data.tar.gz"
SUPERVISOR_CONF="/etc/supervisor/supervisord.conf"
mkdir -p ${DOWNLOAD_DIR}
start_supervisor() {
echo "Starting Supervisor..."
/usr/bin/supervisord -c ${SUPERVISOR_CONF}
}
#setting the zip url to mainnet or testnet (bootstrap)
if [ "${NETWORK}" = "testnet" ]; then
ZIP_URL="${TESTNET_ZIP_URL}"
elif [ "${NETWORK}" = "mainnet" ]; then
ZIP_URL="${MAINNET_ZIP_URL}"
else
echo "Invalid or missing NETWORK variable. Please set NETWORK to 'testnet' or 'mainnet'."
exit 1
fi
#to download bootstrap or not.
if [ "${ZIP}" = "true" ]; then
echo "Downloading ${ZIP_URL}..."
wget -q --show-progress ${ZIP_URL} -O ${ZIP_FILE}
if [ $? -ne 0 ]; then
echo "Failed to download the zip file."
exit 1
fi
echo "Extracting ${ZIP_FILE} to ${EXTRACT_DIR}..."
tar -xzf ${ZIP_FILE} -C ${EXTRACT_DIR}
if [ $? -ne 0 ]; then
echo "Failed to extract the zip file."
exit 1
fi
rm ${ZIP_FILE}
else
echo "Skipping download and extraction of the zip file."
fi
start_supervisor