Skip to content

Commit

Permalink
completed GethNode docker file
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaven committed Oct 30, 2023
1 parent 4fe61bd commit 614c3da
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 11 deletions.
10 changes: 6 additions & 4 deletions GethNode/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ RUN apt-get update -y && \

RUN apt-get update -y && \
apt-get install -y \
ethereum \
ethereum=1.13.4+build29068+jammy \
python3 \
python3-pip \
openssl \
curl


# Prysm
RUN mkdir /opt/prysm
RUN curl https://github.com/prysmaticlabs/prysm/raw/master/prysm.sh \
RUN curl -L https://github.com/prysmaticlabs/prysm/raw/v4.1.1/prysm.sh \
--output /opt/prysm/prysm.sh
RUN chmod 755 /opt/prysm/prysm.sh
################################################################################
Expand All @@ -43,8 +45,8 @@ RUN mkdir /geth
WORKDIR /geth

# test script
COPY test.sh /bin/test.sh
RUN chmod 755 /bin/test.sh
# COPY test.sh /bin/test.sh
# RUN chmod 755 /bin/test.sh

# entrypoint
COPY init-geth /bin/init-geth
Expand Down
88 changes: 81 additions & 7 deletions GethNode/init-geth
Original file line number Diff line number Diff line change
@@ -1,10 +1,84 @@
#!/bin/bash
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
###
# Copyright (c) 2023 Haofan Zheng
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
###

set -e

if [[ ! -f /geth/jwt.hex ]]; then
echo "JWT not found, generating..."
openssl rand -hex 32 | tr -d "\n" > "/geth/jwt.hex"
fi
import os
import shlex
import signal
import subprocess
import sys
import threading


JWT_PATH = os.path.join(os.path.sep, 'geth', 'jwt.hex')
TERMINATE_EVENT = threading.Event()


def OnTerminate():
TERMINATE_EVENT.set()


def main():
if not os.path.isfile(JWT_PATH):
with open(JWT_PATH, 'w') as f:
f.write(os.urandom(32).hex())

gethAddArgs = []
envVal = os.getenv('GETH_OPTS', None)
if envVal is not None:
gethAddArgs = shlex.split(envVal)

gethCmd = [
'/usr/bin/geth'
] + gethAddArgs
gethEnv = {
k: v for k, v in os.environ.items() if (k.startswith('GETH_') or k == 'PATH')
}

prysmAddArgs = []
envVal = os.getenv('PRYSM_OPTS', None)
if envVal is not None:
prysmAddArgs = shlex.split(envVal)

prysmCmd = [
'/opt/prysm/prysm.sh',
] + prysmAddArgs
prysmEnv = {
'PATH': os.environ.get('PATH', ''),
}

gethProc = subprocess.Popen(gethCmd, env=gethEnv, stdout=sys.stdout, stderr=sys.stderr)
prysmProc = subprocess.Popen(prysmCmd, env=prysmEnv, stdout=sys.stdout, stderr=sys.stderr)

# register signal handler
signal.signal(signal.SIGTERM, OnTerminate)
signal.signal(signal.SIGINT, OnTerminate)

# wait for termination
TERMINATE_EVENT.wait()

# terminate processes
while prysmProc.poll() is None:
prysmProc.terminate()
try:
prysmProc.wait(timeout=5)
except subprocess.TimeoutExpired:
pass

while gethProc.poll() is None:
gethProc.terminate()
try:
gethProc.wait(timeout=5)
except subprocess.TimeoutExpired:
pass


if __name__ == '__main__':
main()

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

0 comments on commit 614c3da

Please sign in to comment.