Skip to content

Commit 614c3da

Browse files
committed
completed GethNode docker file
1 parent 4fe61bd commit 614c3da

File tree

2 files changed

+87
-11
lines changed

2 files changed

+87
-11
lines changed

GethNode/Dockerfile

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ RUN apt-get update -y && \
2222

2323
RUN apt-get update -y && \
2424
apt-get install -y \
25-
ethereum \
25+
ethereum=1.13.4+build29068+jammy \
26+
python3 \
27+
python3-pip \
2628
openssl \
2729
curl
2830

2931

3032
# Prysm
3133
RUN mkdir /opt/prysm
32-
RUN curl https://github.com/prysmaticlabs/prysm/raw/master/prysm.sh \
34+
RUN curl -L https://github.com/prysmaticlabs/prysm/raw/v4.1.1/prysm.sh \
3335
--output /opt/prysm/prysm.sh
3436
RUN chmod 755 /opt/prysm/prysm.sh
3537
################################################################################
@@ -43,8 +45,8 @@ RUN mkdir /geth
4345
WORKDIR /geth
4446

4547
# test script
46-
COPY test.sh /bin/test.sh
47-
RUN chmod 755 /bin/test.sh
48+
# COPY test.sh /bin/test.sh
49+
# RUN chmod 755 /bin/test.sh
4850

4951
# entrypoint
5052
COPY init-geth /bin/init-geth

GethNode/init-geth

+81-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,84 @@
1-
#!/bin/bash
1+
#!/usr/bin/env python3
2+
# -*- coding:utf-8 -*-
3+
###
4+
# Copyright (c) 2023 Haofan Zheng
5+
# Use of this source code is governed by an MIT-style
6+
# license that can be found in the LICENSE file or at
7+
# https://opensource.org/licenses/MIT.
8+
###
29

3-
set -e
410

5-
if [[ ! -f /geth/jwt.hex ]]; then
6-
echo "JWT not found, generating..."
7-
openssl rand -hex 32 | tr -d "\n" > "/geth/jwt.hex"
8-
fi
11+
import os
12+
import shlex
13+
import signal
14+
import subprocess
15+
import sys
16+
import threading
17+
18+
19+
JWT_PATH = os.path.join(os.path.sep, 'geth', 'jwt.hex')
20+
TERMINATE_EVENT = threading.Event()
21+
22+
23+
def OnTerminate():
24+
TERMINATE_EVENT.set()
25+
26+
27+
def main():
28+
if not os.path.isfile(JWT_PATH):
29+
with open(JWT_PATH, 'w') as f:
30+
f.write(os.urandom(32).hex())
31+
32+
gethAddArgs = []
33+
envVal = os.getenv('GETH_OPTS', None)
34+
if envVal is not None:
35+
gethAddArgs = shlex.split(envVal)
36+
37+
gethCmd = [
38+
'/usr/bin/geth'
39+
] + gethAddArgs
40+
gethEnv = {
41+
k: v for k, v in os.environ.items() if (k.startswith('GETH_') or k == 'PATH')
42+
}
43+
44+
prysmAddArgs = []
45+
envVal = os.getenv('PRYSM_OPTS', None)
46+
if envVal is not None:
47+
prysmAddArgs = shlex.split(envVal)
48+
49+
prysmCmd = [
50+
'/opt/prysm/prysm.sh',
51+
] + prysmAddArgs
52+
prysmEnv = {
53+
'PATH': os.environ.get('PATH', ''),
54+
}
55+
56+
gethProc = subprocess.Popen(gethCmd, env=gethEnv, stdout=sys.stdout, stderr=sys.stderr)
57+
prysmProc = subprocess.Popen(prysmCmd, env=prysmEnv, stdout=sys.stdout, stderr=sys.stderr)
58+
59+
# register signal handler
60+
signal.signal(signal.SIGTERM, OnTerminate)
61+
signal.signal(signal.SIGINT, OnTerminate)
62+
63+
# wait for termination
64+
TERMINATE_EVENT.wait()
65+
66+
# terminate processes
67+
while prysmProc.poll() is None:
68+
prysmProc.terminate()
69+
try:
70+
prysmProc.wait(timeout=5)
71+
except subprocess.TimeoutExpired:
72+
pass
73+
74+
while gethProc.poll() is None:
75+
gethProc.terminate()
76+
try:
77+
gethProc.wait(timeout=5)
78+
except subprocess.TimeoutExpired:
79+
pass
80+
81+
82+
if __name__ == '__main__':
83+
main()
984

10-
/bin/test.sh --existing-arg1 --existing-arg2 ${GETH_OPTS}

0 commit comments

Comments
 (0)