forked from ethstorage/es-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-docker.sh
More file actions
executable file
·56 lines (49 loc) · 1.84 KB
/
run-docker.sh
File metadata and controls
executable file
·56 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
# usage:
# env ES_NODE_STORAGE_MINER=<miner> ES_NODE_SIGNER_PRIVATE_KEY=<private_key> ./run-docker.sh
if [ -z "$ES_NODE_STORAGE_MINER" ]; then
echo "Please provide 'ES_NODE_STORAGE_MINER' as an environment variable"
exit 1
fi
if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ] || case $ES_NODE_STORAGE_MINER in 0x*) false;; *) true;; esac; then
echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x' and have a total length of 42"
exit 1
fi
if [ -z "$ES_NODE_SIGNER_PRIVATE_KEY" ]; then
echo "Please provide 'ES_NODE_SIGNER_PRIVATE_KEY' as an environment variable"
exit 1
fi
if [ ${#ES_NODE_SIGNER_PRIVATE_KEY} -ne 64 ]; then
echo "Error: ES_NODE_SIGNER_PRIVATE_KEY should have a length of 64"
exit 1
fi
container_name="es"
image_name="es-node"
# check if container is running
if sudo docker ps --format "{{.Names}}" | grep -q "^$container_name$"; then
echo "container $container_name already started"
else
# start container if exist
if sudo docker ps -a --format "{{.Names}}" | grep -q "^$container_name$"; then
sudo docker start $container_name
echo "container $container_name started"
else
# build an image if not exist
if ! sudo docker images --format "{{.Repository}}" | grep -q "^$image_name$"; then
sudo docker build -t $image_name .
echo "image $image_name built"
fi
# run container in the background
sudo docker run --name $container_name \
-v ./es-data:/es-node/es-data \
-e ES_NODE_STORAGE_MINER=$ES_NODE_STORAGE_MINER \
-e ES_NODE_SIGNER_PRIVATE_KEY=$ES_NODE_SIGNER_PRIVATE_KEY \
-p 9545:9545 \
-p 9222:9222 \
-p 30305:30305/udp \
-d \
--entrypoint /es-node/run.sh \
$image_name
echo "container $container_name started"
fi
fi