-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update dockerfile with a few enhancement (#998)
* feat: refactor dockerfile to add entrypoint script
- Loading branch information
Showing
5 changed files
with
179 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
version: '3.6' | ||
services: | ||
init: | ||
image: alpine | ||
command: | ||
- /bin/sh | ||
- -c | ||
- | | ||
chown -R 1000:1000 /data | ||
echo "done grany data directory permission" | ||
volumes: | ||
- data:/data | ||
|
||
bsc: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
environment: | ||
- NETWORK=mainnet | ||
restart: unless-stopped | ||
ports: | ||
- 30303:30303 | ||
- 30311:30311 | ||
- 8545:8545 | ||
- 8546:8546 | ||
- 8575:8575 | ||
- 8576:8576 | ||
healthcheck: | ||
test: | | ||
[[ "$NETWORK" == "testnet" ]] && PORT=8575 || PORT=8545; | ||
netstat -tunlp | grep $PORT > /dev/null; if [ 0 != $$? ]; then exit 1; else exit 0; fi; | ||
interval: 5s | ||
retries: 5 | ||
start_period: 10s | ||
timeout: 3s | ||
volumes: | ||
- data:/data | ||
- config:/bsc/config | ||
|
||
volumes: | ||
config: | ||
driver: local | ||
driver_opts: | ||
type: 'none' | ||
o: 'bind' | ||
device: '/tmp/bsc/config/mainnet' | ||
data: | ||
driver: local | ||
driver_opts: | ||
type: 'none' | ||
o: 'bind' | ||
device: '/tmp/bsc/data/mainnet' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
BSC_CONFIG=${BSC_HOME}/config/config.toml | ||
BSC_GENESIS=${BSC_HOME}/config/genesis.json | ||
|
||
# Init genesis state if geth not exist | ||
DATA_DIR=$(cat ${BSC_CONFIG} | grep -A1 '\[Node\]' | grep -oP '\"\K.*?(?=\")') | ||
|
||
GETH_DIR=${DATA_DIR}/geth | ||
if [ ! -d "$GETH_DIR" ]; then | ||
geth --datadir ${DATA_DIR} init ${BSC_GENESIS} | ||
fi | ||
|
||
exec "geth" "--config" ${BSC_CONFIG} "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
## Docker Image | ||
|
||
Included in this repo is a Dockerfile that you can launch BSC node for trying it out. Docker images are available on `ghcr.io/bnb-chain/bsc`. | ||
|
||
You can build the docker image with the following commands: | ||
```bash | ||
make docker | ||
``` | ||
|
||
If your build machine has an ARM-based chip, like Apple silicon (M1), the image is built for `linux/arm64` by default. To build for `x86_64`, apply the --platform arg: | ||
|
||
```bash | ||
docker build --platform linux/amd64 -t bnb-chain/bsc -f Dockerfile . | ||
``` | ||
|
||
Before start the docker, get a copy of the config.toml & genesis.json from the release: https://github.com/bnb-chain/bsc/releases, and make necessary modification. `config.toml` & `genesis.json` should be mounted into `/bsc/config` inside the container. Assume `config.toml` & `genesis.json` are under `./config` in your current working directory, you can start your docker container with the following command: | ||
```bash | ||
docker run -v $(pwd)/config:/bsc/config --rm --name bsc -it bnb-chain/bsc | ||
``` | ||
|
||
You can also use `ETHEREUM OPTIONS` to overwrite settings in the configuration file | ||
```bash | ||
docker run -v $(pwd)/config:/bsc/config --rm --name bsc -it bnb-chain/bsc --http.addr 0.0.0.0 --http.port 8545 --http.vhosts '*' --verbosity 3 | ||
``` | ||
|
||
If you need to open another shell, just do: | ||
```bash | ||
docker exec -it bnb-chain/bsc /bin/bash | ||
``` | ||
|
||
We also provide a `docker-compose` file for local testing | ||
|
||
To use the container in kubernetes, you can use a configmap or secret to mount the `config.toml` & `genesis.json` into the container | ||
```bash | ||
containers: | ||
- name: bsc | ||
image: bnb-chain/bsc | ||
|
||
ports: | ||
- name: p2p | ||
containerPort: 30311 | ||
- name: rpc | ||
containerPort: 8545 | ||
- name: ws | ||
containerPort: 8546 | ||
|
||
volumeMounts: | ||
- name: bsc-config | ||
mountPath: /bsc/config | ||
|
||
volumes: | ||
- name: bsc-config | ||
configMap: | ||
name: cm-bsc-config | ||
``` | ||
|
||
Your configmap `bsc-config` should look like this: | ||
``` | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: cm-bsc-config | ||
data: | ||
config.toml: | | ||
... | ||
genesis.json: | | ||
... | ||
``` |