mirror of
https://github.com/EvernodeXRPL/hp-devkit.git
synced 2026-04-29 15:37:58 +00:00
Initial cluster script.
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
# hp-devtoolkit
|
||||
Developer toolkit for Hot Pocket smart contract development.
|
||||
# Hot Pocket developer toolkit
|
||||
Developer toolkit for Hot Pocket smart contract development. This toolkit makes use of Docker to provide a cross-platform development tools for developers.
|
||||
|
||||
We use Docker containers to run Hot Pocket and smart contracts in a Linux environment. We also use Docker containers distributing developer tools so developers can use the tools on any platform as long as they install Docker.
|
||||
|
||||
22
src/Dockerfile
Normal file
22
src/Dockerfile
Normal file
@@ -0,0 +1,22 @@
|
||||
# This image contains scripts for creating Hot Pocket contract clusters
|
||||
# on the developer machine for local development testing.
|
||||
|
||||
FROM ubuntu:focal as builder
|
||||
RUN apt-get update && apt-get install -y wget
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
# Download and extract docker.
|
||||
RUN wget -O docker.deb https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/docker-ce-cli_20.10.9~3-0~ubuntu-focal_amd64.deb
|
||||
RUN dpkg -x docker.deb docker-extracted
|
||||
|
||||
# Set permissions for hot pocket devkit scripts.
|
||||
COPY scripts /build/scripts
|
||||
RUN chmod -R +x /build/scripts/*.sh
|
||||
|
||||
FROM ubuntu:focal as runner
|
||||
COPY --from=builder /build/docker-extracted/usr/bin/docker /usr/bin/
|
||||
COPY --from=builder /build/scripts/cluster.sh /usr/bin/cluster
|
||||
|
||||
# docker build -t hpdevtoolkit .
|
||||
# docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock hpdevtoolkit cluster
|
||||
79
src/scripts/cluster.sh
Normal file
79
src/scripts/cluster.sh
Normal file
@@ -0,0 +1,79 @@
|
||||
#!/bin/bash
|
||||
globalprefix="hpdevkit"
|
||||
imgname="evernodedev/hotpocket:latest-ubt.20.04-njs.16"
|
||||
volmount="/devkitvol"
|
||||
|
||||
command=$1
|
||||
cluster=$2
|
||||
volume="${globalprefix}_${cluster}_vol"
|
||||
network="${globalprefix}_${cluster}_net"
|
||||
containerprefix="${globalprefix}_${cluster}_con"
|
||||
nodecount=0
|
||||
|
||||
echo "Hot Pocket development toolkit"
|
||||
|
||||
if [ "$command" = "create" ] || [ "$command" = "destroy" ] ; then
|
||||
echo "command: $command"
|
||||
else
|
||||
echo "Invalid command."
|
||||
echo "Expected: create | destroy"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[ -z $cluster ] && echo "Cluster name not specified." && exit 1
|
||||
|
||||
function parsenodecountarg() {
|
||||
! [ "$1" -eq "$1" ] 2> /dev/null && echo "Node count must be a number." && return 1
|
||||
[ $1 -le 0 ] && echo "Node count must be 1 or higher." && return 1
|
||||
nodecount=$1
|
||||
}
|
||||
|
||||
function exists() {
|
||||
local output=$(docker $1 ls | grep $2)
|
||||
if [ -z "$output" ] ; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function clusterexists() {
|
||||
if exists "volume" $volume || exists "network" $network || exists "container" $containerprefix ; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function createcluster() {
|
||||
clusterexists && echo "Cluster '$cluster' already exists." && exit 1
|
||||
docker volume create $volume
|
||||
docker network create $network
|
||||
|
||||
for ((i=1; i<=$nodecount; i++));
|
||||
do
|
||||
local containername="${containerprefix}_$i"
|
||||
docker container create --name $containername --privileged --mount type=volume,src=$volume,dst=$volmount $imgname
|
||||
done
|
||||
}
|
||||
|
||||
function destroycluster() {
|
||||
! clusterexists && echo "Cluster '$cluster' does not exist." && exit 1
|
||||
|
||||
local containercount=$(docker ps -a | grep $containerprefix | wc -l)
|
||||
for ((i=1; i<=$containercount; i++));
|
||||
do
|
||||
local containername="${containerprefix}_$i"
|
||||
docker container rm $containername
|
||||
done
|
||||
|
||||
exists "volume" $volume && docker volume rm $volume
|
||||
exists "network" $network && docker network rm $network
|
||||
}
|
||||
|
||||
if [ $command = "create" ]; then
|
||||
! parsenodecountarg $3 && echo "Usage: create <cluster name> <node count>" && exit 1
|
||||
createcluster
|
||||
elif [ $command = "destroy" ]; then
|
||||
destroycluster
|
||||
fi
|
||||
Reference in New Issue
Block a user