Skip to content

Commit

Permalink
Docker support updated
Browse files Browse the repository at this point in the history
  • Loading branch information
adlrocha committed Jan 2, 2018
1 parent 8494fa1 commit 5547e4d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
scripts/nohup.out
scripts/permissioned-nodes.json
go1*
data/keys
21 changes: 13 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
FROM ubuntu:xenial
FROM ubuntu:16.04

LABEL maintainer "Jakub Vanak (https://github.com/Koubek)"
LABEL maintainer "Alfonso de la Rocha (https://github.com/arochaga)"

ARG hostip
ARG nodetype
ARG nodename
ENV HOST_IP $hostip

COPY data /root/alastria-node/data
RUN chmod -R u+x /root/alastria-node/data
Expand All @@ -10,16 +15,16 @@ RUN chmod -R u+x /root/alastria-node/scripts

WORKDIR /root/alastria-node/scripts

RUN sed -i -e 's/\r$//' init.sh && sed -i -e 's/\r$//' bootstrap.sh && sed -i -e 's/\r$//' start.sh

RUN \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -q -y curl \
apt-get install -y curl \
libcurl3 unzip wget git make gcc libsodium-dev build-essential libdb-dev zlib1g-dev libtinfo-dev sysvbanner wrk psmisc sudo

WORKDIR /root/alastria-node/scripts
RUN ./bootstrap.sh
RUN sudo -H ./bootstrap.sh
RUN ./init.sh dockerfile $nodetype $nodename
RUN ./start.sh

EXPOSE 9000 21000 21000/udp 22000 41000

# CMD ["/run.sh"]
RUN ./start.sh
CMD ["./start.sh dockerfile"]
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,29 @@ Existe un script `./scripts/clean.sh` que limpia el nodo actual y exige una resi
del mismo al iniciarlo de nuevo. Esto solventa posibles errores de sincronización.
Su efecto es el mismo que el de ejecutar directamente `./scripts/start.sh clean`

## Crear un nodo con Docker
Para generar la imagen de Docker ejecutar:
```
sudo docker build -t alastria-node . --build-arg hostip=<host-ip> --build-arg nodetype=<node-type> --build-arg nodename=<node-name>
```
Indicando la IP del host donde se ejecuta el nodo, el tipo de nodo a generar (validador o general) y el nombre que queremos dar al nodo,
y ejecutando el comando anterior se genera la imagen para nuestro nodo con el nombre *alastria-node*.

**NOTA**
Si deseamos generar el nodo utilizando un enode y las claves de un nodo ya existente debemos hacer un backup de las claves
del antiguo nodo:
```
./backup.sh keys
```
Esto generará la carpeta ~/alastria-keysBackup-<date> cuyo contenido deberemos moverlo a ~/alastria-node/data/keys.
La claves de este directorio (que tiene que mantener la estructura de carpetas del backup generado) serán las utilizadas
en la imagen del nodo que vamos a generar.


Una vez finalizada la generación de la imagen, ejecutamos el nodo en segundo plano:
```
docker run -d --name alastria -p 9000:9000 -p 21000:21000 -p 22000:22000 -p 41000:41000 alastria-node
```
<!-- EN PROCESO DE REVISIÓN
## Build/Run with Docker
Expand Down
2 changes: 1 addition & 1 deletion scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if ( [ "keys" == "$1" ]); then
echo "Saving node keys ..."
cp -r ~/alastria/data/keystore ~/alastria-keysBackup-$CURRENT_DATE/data
echo "Saving enode ID ..."
cp ~/alastria/data/geth/nodekey ~/alastria-keysBackup-$CURRENT_DATE/data/nodekey
cp ~/alastria/data/geth/nodekey ~/alastria-keysBackup-$CURRENT_DATE/data/geth/nodekey
fi

if ( [ "full" == "$1" ]); then
Expand Down
34 changes: 32 additions & 2 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ fi
CURRENT_HOST_IP="$1"
NODE_TYPE="$2"
NODE_NAME="$3"
ACCOUNT_PASSWORD='Passw0rd'


if ( [ "auto" == "$1" -o "backup" == "$1" ]); then
echo "Autodiscovering public host IP ..."
CURRENT_HOST_IP="$(dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null || curl -s --retry 2 icanhazip.com)"
echo "Public host IP found: $CURRENT_HOST_IP"
fi

if ( [ "dockerfile" == "$1" ]); then
echo "Getting IP from environmental variable ..."
CURRENT_HOST_IP=$HOST_IP
echo "Public host IP found: $CURRENT_HOST_IP"
fi

if ( [ "backup" == "$1" ]); then
echo "Backing up current node keys ..."
#Backup directory tree
Expand Down Expand Up @@ -147,6 +155,10 @@ if ( [ "backup" == "$1" ]); then
ENODE_KEY=$(bootnode -nodekey ~/alastria-keysBackup/data/geth/nodekey -writeaddress)
fi

if ( [ "dockerfile" == "$1" ]); then
ENODE_KEY=$(bootnode -nodekey ~/alastria-node/data/keys/data/geth/nodekey -writeaddress)
fi

echo "ENODE -> 'enode://${ENODE_KEY}@${CURRENT_HOST_IP}:21000?discport=0'"
update_nodes_list "enode://${ENODE_KEY}@${CURRENT_HOST_IP}:21000?discport=0"
cd ~
Expand All @@ -165,8 +177,11 @@ fi


if ( [ "general" == "$NODE_TYPE" ]); then
echo " Por favor, introduzca como contraseña 'Passw0rd'."
geth --datadir ~/alastria/data account new
# echo " Por favor, introduzca como contraseña 'Passw0rd'."
echo " Definida contraseña por defecto para cuenta principal como: $ACCOUNT_PASSWORD."
echo $ACCOUNT_PASSWORD > ./account_pass
geth --datadir ~/alastria/data --password ./account_pass account new
rm ./account_pass

echo "[*] Initializing Constellation node."
update_constellation_nodes "${CURRENT_HOST_IP}" "9000"
Expand All @@ -193,6 +208,21 @@ if ( [ "backup" == "$1" ]); then
rm -rf ~/alastria-keysBackup
fi

if ( [ "dockerfile" == "$1" ]); then
echo "Recovering keys saved in the repository ..."
rm -rf ~/alastria/data/constellation/keystore
rm -rf ~/alastria/data/keystore
rm ~/alastria/data/geth/nodekey

echo "Recovering constellation keys ..."
cp -rf ~/alastria-node/data/keys/data/constellation/keystore ~/alastria/data/constellation/
echo "Recovering node keys ..."
cp -rf ~/alastria-node/data/keys/data/keystore ~/alastria/data/
echo "Recovering enode ID ..."
cp ~/alastria-node/data/keys/data/geth/nodekey ~/alastria/data/geth/nodekey

fi

echo "[*] Initialization was completed successfully."
echo " "
echo " Update DIRECTORY_REGULAR.md or DIRECTORY_VALIDATOR.md from alastria-node repository and send a Pull Request."
Expand Down
8 changes: 8 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,13 @@ else
fi
fi

if ([ ! $# -ne 1 ] && [ "dockerfile" == "$1" ]); then

echo "Running your node ..."
while true; do
sleep 1000000
done;
fi

set +u
set +e

0 comments on commit 5547e4d

Please sign in to comment.