Skip to content

Commit

Permalink
feat: add ci script to docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Jul 15, 2022
1 parent 451071e commit d35fea9
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 17 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
@@ -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
42 changes: 28 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
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

# 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"]
2 changes: 1 addition & 1 deletion asset/mainnet/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion asset/testnet/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion asset/testnet/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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} "$@"
27 changes: 27 additions & 0 deletions docs/docker.md
Original file line number Diff line number Diff line change
@@ -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
```



0 comments on commit d35fea9

Please sign in to comment.