diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml new file mode 100644 index 000000000..2bfbec4b3 --- /dev/null +++ b/.github/workflows/docker-release.yml @@ -0,0 +1,50 @@ +name: Docker + +on: + push: + # Publish `v1.2.3` tags as releases. + tags: + - v* + +env: + IMAGE_NAME: node + +jobs: + # Push image to GitHub Packages. + push: + runs-on: ubuntu-latest + if: github.event_name == 'push' + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: | + docker build . \ + --label "org.opencontainers.image.source=${{ secrets.IMAGE_SOURCE }}" \ + --label "org.opencontainers.image.revision=$(git rev-parse HEAD)" \ + --label "org.opencontainers.image.version=$(git describe --tags --abbrev=0)" \ + --label "org.opencontainers.image.licenses=LGPL-3.0,GPL-3.0" \ + -f ./Dockerfile -t "${IMAGE_NAME}" + + - name: Log into registry + run: echo "${{ secrets.PACKAGE_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository }} + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + # Use Docker `latest` tag convention + [ "$VERSION" == "master" ] && VERSION=latest + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:latest + docker push $IMAGE_ID:$VERSION + docker push $IMAGE_ID:latest diff --git a/Dockerfile b/Dockerfile index d3529bbfa..49f50b6d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -FROM golang:1.11-alpine AS build-env +FROM golang:1.17-alpine AS build-env # Set up dependencies -ENV PACKAGES make git libc-dev bash gcc linux-headers eudev-dev curl ca-certificates ssh +ENV PACKAGES make git libc-dev bash gcc linux-headers eudev-dev curl ca-certificates # Set working directory for the build WORKDIR /go/src/github.com/bnb-chain/node @@ -9,26 +9,40 @@ WORKDIR /go/src/github.com/bnb-chain/node # Add source files COPY . . -# Add ssh key to download private deps -COPY ~/.ssh/id_rsa /root/ssh/ - # Install minimum necessary dependencies, build Cosmos SDK, remove packages RUN apk add --no-cache $PACKAGES && \ - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh && \ - make get_vendor_deps && \ - make build-alpine && \ + make build && \ make install -# Final image -FROM alpine:edge +# # Final image +FROM alpine:3.16.0 + +# Install dependencies +RUN apk add --update ca-certificates tini bash + +ARG USER=bnbchain +ARG USER_UID=1000 +ARG USER_GID=1000 -# Install ca-certificates -RUN apk add --update ca-certificates -WORKDIR /root +ENV DEFAULT_CONFIG=/configs +ENV HOME=/data + +RUN addgroup -g ${USER_GID} ${USER} \ + && adduser -u ${USER_UID} -G ${USER} --shell /sbin/nologin --no-create-home -D ${USER} \ + && addgroup ${USER} tty +RUN mkdir -p ${HOME} ${DEFAULT_CONFIG} +WORKDIR ${HOME} # Copy over binaries from the build-env COPY --from=build-env /go/bin/bnbchaind /usr/bin/bnbchaind COPY --from=build-env /go/bin/bnbcli /usr/bin/bnbcli +COPY docker-entrypoint.sh / +COPY ./asset/ ${DEFAULT_CONFIG}/ + +RUN chown -R ${USER_UID}:${USER_GID} ${HOME} \ + && chmod +x /docker-entrypoint.sh + +USER ${USER}:${USER} # Run gaiad by default, omit entrypoint to ease using container with gaiacli -CMD ["bnbchaind"] +CMD ["/sbin/tini", "--", "/docker-entrypoint.sh"] diff --git a/asset/mainnet/app.toml b/asset/mainnet/app.toml index 0df4da2d5..72b2c1dcc 100644 --- a/asset/mainnet/app.toml +++ b/asset/mainnet/app.toml @@ -146,7 +146,7 @@ localMaxAge = 7 [log] # Write logs to console instead of file -logToConsole = false +logToConsole = true ## The below parameters take effect only when logToConsole is false # Log file root, if not set, use home path diff --git a/asset/testnet/app.toml b/asset/testnet/app.toml index f03da2109..d381ff7f5 100644 --- a/asset/testnet/app.toml +++ b/asset/testnet/app.toml @@ -169,7 +169,7 @@ kafkaVersion = "2.1.0" [log] # Write logs to console instead of file -logToConsole = false +logToConsole = true ## The below parameters take effect only when logToConsole is false # Log file root, if not set, use home path diff --git a/asset/testnet/config.toml b/asset/testnet/config.toml index 56d5bcb7a..9628fbdb9 100644 --- a/asset/testnet/config.toml +++ b/asset/testnet/config.toml @@ -99,7 +99,7 @@ with_app_stat = true [rpc] # TCP or UNIX socket address for the RPC server to listen on -laddr = "tcp://0.0.0.0:26657" +laddr = "tcp://0.0.0.0:27147" # A list of origins a cross-domain request can be executed from # Default value '[]' disables cors support diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 000000000..ef806ab1d --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +DEFAULT_NETWORK=("mainnet" "testnet") +NETWORK=${NETWORK:-mainnet} +HOME=${HOME:-/data} +DEFAULT_CONFIG=${DEFAULT_CONFIG:-/configs} + +if echo ${DEFAULT_NETWORK[@]} | grep -q -w "${NETWORK}" +then + mkdir -p ${HOME}/config + cp ${DEFAULT_CONFIG}/${NETWORK}/* ${HOME}/config/ +fi + +exec "bnbchaind" "start" "--home" ${HOME} "$@" \ No newline at end of file diff --git a/docs/docker.md b/docs/docker.md new file mode 100644 index 000000000..c6fa10bb4 --- /dev/null +++ b/docs/docker.md @@ -0,0 +1,27 @@ +## Docker Usage + +### Image +```sh +docker pull ghcr.io/bnb-chain/node:latest +``` + +### Env + +| env | desc | default| +|---|---|---| +| NETWORK | default network options, if `mainnet` or `testnet` is configured, the genesis file will be automatically configured | `mainnet`| +| HOME | directory for config and data | `/data` | + +### Example +1. Start a testnet full node +``` +docker run -p 27146:27146 -p 27147:27147 -e NETWORK=testnet ghcr.io/bnb-chain/node:latest +``` + +2. Start a mainnet full node with mounted volume +``` +docker run -p 27146:27146 -p 27147:27147 -v /tmp/chain/data:/data ghcr.io/bnb-chain/node:latest +``` + + +