Skip to content

Commit

Permalink
feat: refactor dockerfile to add entrypoint script
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Yi <jasonhk.yi@consensys.net>
  • Loading branch information
jasonyic committed Jul 14, 2022
1 parent de4abf9 commit b391837
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 3 deletions.
42 changes: 39 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,46 @@ ADD . /go-ethereum
RUN cd /go-ethereum && make geth

# Pull Geth into a second stage deploy alpine container
FROM alpine:latest
FROM alpine:3.16.0

ARG BSC_VERSION=v1.1.11
ARG BSC_USER=bsc
ARG BSC_USER_UID=1000
ARG BSC_USER_GID=1000

ENV BSC_HOME=/bsc
ENV HOME=${BSC_HOME}
ENV DATA_DIR=/data

RUN apk add --no-cache ca-certificates~=20211220 jq~=1.6 bash~=5.1.16-r2 bind-tools~=9.16.29-r0 tini~=0.19.0 curl==7.83.1-r2 sed~=4.8-r0 \
&& rm -rf /var/cache/apk/* \
&& addgroup -g ${BSC_USER_GID} ${BSC_USER} \
&& adduser -u ${BSC_USER_UID} -G ${BSC_USER} --shell /sbin/nologin --no-create-home -D ${BSC_USER} \
&& addgroup ${BSC_USER} tty \
&& sed -i -e "s/bin\/sh/bin\/bash/" /etc/passwd

RUN echo "[ ! -z \"\$TERM\" -a -r /etc/motd ] && cat /etc/motd" >> /etc/bash/bashrc \
&& echo "Version: ${BSC_VERSION}" > /etc/motd

WORKDIR ${BSC_HOME}

RUN apk add --no-cache ca-certificates curl jq tini
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/

COPY docker-entrypoint.sh ./

RUN curl -LO https://github.com/bnb-chain/bsc/releases/download/${BSC_VERSION}/mainnet.zip \
&& unzip mainnet.zip -d mainnet && rm mainnet.zip \
&& curl -LO https://github.com/bnb-chain/bsc/releases/download/${BSC_VERSION}/testnet.zip \
&& unzip testnet.zip -d testnet && rm testnet.zip

RUN chmod +x docker-entrypoint.sh \
&& mkdir -p ${DATA_DIR} \
&& chown -R ${BSC_USER_UID}:${BSC_USER_GID} ${BSC_HOME} ${DATA_DIR}

VOLUME ${DATA_DIR}

USER ${BSC_USER_UID}:${BSC_USER_GID}

EXPOSE 8545 8546 8547 30303 30303/udp
ENTRYPOINT ["geth"]

ENTRYPOINT ["/sbin/tini", "--", "./docker-entrypoint.sh"]
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
.PHONY: geth-linux-arm geth-linux-arm-5 geth-linux-arm-6 geth-linux-arm-7 geth-linux-arm64
.PHONY: geth-darwin geth-darwin-386 geth-darwin-amd64
.PHONY: geth-windows geth-windows-386 geth-windows-amd64
.PHONY: docker

GOBIN = ./build/bin
GO ?= latest
GORUN = env GO111MODULE=on go run

BSC_VERSION ?= 1.1.11

geth:
$(GORUN) build/ci.go install ./cmd/geth
@echo "Done building."
Expand Down Expand Up @@ -155,3 +158,6 @@ geth-windows-amd64:
$(GORUN) build/ci.go xgo -- --go=$(GO) --targets=windows/amd64 -v ./cmd/geth
@echo "Windows amd64 cross compilation done:"
@ls -ld $(GOBIN)/geth-windows-* | grep amd64

docker:
docker build --pull -t bnb-chain/bsc:$(BSC_VERSION) -t bnb-chain/bsc:latest -f Dockerfile .
1 change: 1 addition & 0 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

//go:build none
// +build none

/*
Expand Down
23 changes: 23 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.6'
services:
bsc:
build:
context: .
dockerfile: Dockerfile
command: ["--http.addr", "0.0.0.0", "--ws.addr", "0.0.0.0"]
environment:
- LOG_LEVEL=3
- DIFF_SYNC=true
- CACHE=4096
restart: unless-stopped
ports:
- 30311:30311
- 6060:6060
- 8545:8545
- 8546:8546
healthcheck:
test: netstat -tunlp | grep 8545 > /dev/null; if [ 0 != $$? ]; then exit 1; else exit 0; fi;
interval: 5s
retries: 5
start_period: 10s
timeout: 3s
18 changes: 18 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

NETWORK=${BSC_NETWORK:-testnet}
DATA_DIR=${BSC_DATA_DIR:-/data}
BSC_CONFIG=${BSC_HOME}/config.toml

# Create symlink to network config.toml & genesis.json
ln -sf ./${NETWORK}/config.toml config.toml
ln -sf ./${NETWORK}/genesis.json genesis.json

# Default log to console
sed -i '/Node\.LogConfig/,/^$/d' ./${NETWORK}/config.toml

# Init genesis state:
geth --datadir ${DATA_DIR} init genesis.json

exec "/usr/local/bin/geth" "--config" ${BSC_CONFIG} "--datadir" ${DATA_DIR} "$@"

0 comments on commit b391837

Please sign in to comment.