Skip to content
Permalink
Browse files

dockerfile of BTCPool: Properly carry the git tag as the version numb…

…er when building deploy images.
  • Loading branch information...
SwimmingTiger committed Jun 25, 2019
1 parent f9d6148 commit 77fd25265eb585f47c964fb29b049f927ab68177
Showing with 89 additions and 35 deletions.
  1. +31 −29 CMakeLists.txt
  2. +2 −0 docker/btcpool/deploy/Dockerfile
  3. +31 −6 docker/btcpool/deploy/README.md
  4. +25 −0 docker/btcpool/deploy/build.sh
@@ -374,35 +374,37 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
OUTPUT_VARIABLE BPOOL_GIT_DESCRIBE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BPOOL_GIT_DESCRIBE)
message("-- Git describe: ${BPOOL_GIT_DESCRIBE}")

# Split git describe likes `v2.3.2-0-g2d76329` to list
# Remove prefix `v`
string(REGEX REPLACE "^[^0-9]+" "" BPOOL_GIT_DESCRIBE ${BPOOL_GIT_DESCRIBE})
# Split to list
string(REPLACE "." ";" BPOOL_GIT_DESCRIBE_LIST ${BPOOL_GIT_DESCRIBE})

list(GET BPOOL_GIT_DESCRIBE_LIST 0 BPOOL_VERSION_MAJOR)
list(REMOVE_AT BPOOL_GIT_DESCRIBE_LIST 0)
list(GET BPOOL_GIT_DESCRIBE_LIST 0 BPOOL_VERSION_MINOR)
list(REMOVE_AT BPOOL_GIT_DESCRIBE_LIST 0)
# The tag may be `v2.2.1.1-bitcoin-0-gb9fb89d`
# So the BPOOL_VERSION_PATCH should be `1.1-bitcoin-0-gb9fb89d`
# We need to merge the remaining items with `.`
string(REPLACE ";" "." BPOOL_VERSION_PATCH "${BPOOL_GIT_DESCRIBE_LIST}")
else()
message("-- Git describe is empty, the base version will be used.")
message("-- It is recommended to add a tag to the current commit.")
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE BPOOL_GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(BPOOL_GIT_COMMIT_HASH)
set(BPOOL_VERSION_PATCH "${BPOOL_VERSION_PATCH}-${BPOOL_GIT_COMMIT_HASH}")
endif()
endif()

if (BPOOL_GIT_DESCRIBE)
message("-- Git describe: ${BPOOL_GIT_DESCRIBE}")

# Split git describe likes `v2.3.2-0-g2d76329` to list
# Remove prefix `v`
string(REGEX REPLACE "^[^0-9]+" "" BPOOL_GIT_DESCRIBE ${BPOOL_GIT_DESCRIBE})
# Split to list
string(REPLACE "." ";" BPOOL_GIT_DESCRIBE_LIST ${BPOOL_GIT_DESCRIBE})

list(GET BPOOL_GIT_DESCRIBE_LIST 0 BPOOL_VERSION_MAJOR)
list(REMOVE_AT BPOOL_GIT_DESCRIBE_LIST 0)
list(GET BPOOL_GIT_DESCRIBE_LIST 0 BPOOL_VERSION_MINOR)
list(REMOVE_AT BPOOL_GIT_DESCRIBE_LIST 0)
# The tag may be `v2.2.1.1-bitcoin-0-gb9fb89d`
# So the BPOOL_VERSION_PATCH should be `1.1-bitcoin-0-gb9fb89d`
# We need to merge the remaining items with `.`
string(REPLACE ";" "." BPOOL_VERSION_PATCH "${BPOOL_GIT_DESCRIBE_LIST}")

elseif(EXISTS "${CMAKE_SOURCE_DIR}/.git")
message("-- Git describe is empty, the base version will be used.")
message("-- It is recommended to add a tag to the current commit.")
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE BPOOL_GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(BPOOL_GIT_COMMIT_HASH)
set(BPOOL_VERSION_PATCH "${BPOOL_VERSION_PATCH}-${BPOOL_GIT_COMMIT_HASH}")
endif()
endif()

@@ -12,6 +12,7 @@ ARG BASE_IMAGE
FROM ${BASE_IMAGE} as build
LABEL maintainer="Hanjiang Yu <hanjiang.yu@bitmain.com>"

ARG GIT_DESCRIBE=""
ARG BUILD_JOBS=1
ARG BUILD_TESTING=ON
ARG BUILD_TYPE=Release
@@ -22,6 +23,7 @@ ARG WORK_WITH_STRATUM_SWITCHER=OFF
# Copy & build btcpool
COPY . /tmp/btcpool
RUN mkdir -p /tmp/build && cd /tmp/build && cmake \
-DBPOOL_GIT_DESCRIBE=${GIT_DESCRIBE} \
-DBUILD_TESTING=${BUILD_TESTING} \
-DCHAIN_SRC_ROOT=/work/blockchain \
-DCHAIN_TYPE=${CHAIN_TYPE} \
@@ -34,24 +34,49 @@ See [here](../base-image/).

## Build Deploy Images

### Use `build.sh`
```
# BTC
docker build -t btccom/btcpool-btc -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:btc-0.16.3 --build-arg BUILD_JOBS=$(nproc) ../../..
./build.sh -t btccom/btcpool-btc -b btccom/btcpool_build:btc-0.16.3 -j$(nproc)
# BCH
docker build -t btccom/btcpool-bch -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:bch-0.18.5 --build-arg BUILD_JOBS=$(nproc) ../../..
./build.sh -t btccom/btcpool-bch -b btccom/btcpool_build:bch-0.18.5 -j$(nproc)
# UBTC
docker build -t btccom/btcpool-ubtc -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:ubtc-2.5.0.1-1 --build-arg BUILD_JOBS=$(nproc) ../../..
./build.sh -t btccom/btcpool-ubtc -b btccom/btcpool_build:ubtc-2.5.0.1-1 -j$(nproc)
# SBTC (outdated)
docker build -t btccom/btcpool-sbtc -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:sbtc-0.16.2 --build-arg BUILD_JOBS=$(nproc) ../../..
./build.sh -t btccom/btcpool-sbtc -b btccom/btcpool_build:sbtc-0.16.2 -j$(nproc)
# LTC
docker build -t btccom/btcpool-ltc -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:ltc-0.16.3 --build-arg BUILD_JOBS=$(nproc) ../../..
./build.sh -t btccom/btcpool-ltc -b btccom/btcpool_build:ltc-0.16.3 -j$(nproc)
# ZEC
docker build -t btccom/btcpool-zec -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:zec-2.0.4 --build-arg BUILD_JOBS=$(nproc) ../../..
./build.sh -t btccom/btcpool-zec -b btccom/btcpool_build:zec-2.0.4 -j$(nproc)
# Other chains (ETH, Beam, Grin, Decred, Bytom, ...)
# Please use BTC's image.
```

### Use `docker build`
```
# BTC
docker build -t btccom/btcpool-btc -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:btc-0.16.3 --build-arg BUILD_JOBS=$(nproc) --build-arg GIT_DESCRIBE=$(git describe --tag --long) ../../..
# BCH
docker build -t btccom/btcpool-bch -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:bch-0.18.5 --build-arg BUILD_JOBS=$(nproc) --build-arg GIT_DESCRIBE=$(git describe --tag --long) ../../..
# UBTC
docker build -t btccom/btcpool-ubtc -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:ubtc-2.5.0.1-1 --build-arg BUILD_JOBS=$(nproc) --build-arg GIT_DESCRIBE=$(git describe --tag --long) ../../..
# SBTC (outdated)
docker build -t btccom/btcpool-sbtc -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:sbtc-0.16.2 --build-arg BUILD_JOBS=$(nproc) --build-arg GIT_DESCRIBE=$(git describe --tag --long) ../../..
# LTC
docker build -t btccom/btcpool-ltc -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:ltc-0.16.3 --build-arg BUILD_JOBS=$(nproc) --build-arg GIT_DESCRIBE=$(git describe --tag --long) ../../..
# ZEC
docker build -t btccom/btcpool-zec -f Dockerfile --build-arg BASE_IMAGE=btccom/btcpool_build:zec-2.0.4 --build-arg BUILD_JOBS=$(nproc) --build-arg GIT_DESCRIBE=$(git describe --tag --long) ../../..
# Other chains (ETH, Beam, Grin, Decred, Bytom, ...)
# Please use BTC's image.
@@ -0,0 +1,25 @@
#!/bin/bash
# build docker images of BTCPool

TITLE=""
BASE_IMAGE=""
BUILD_JOBS="$(nproc)"
GIT_DESCRIBE="$(git describe --tag --long)"

while getopts 't:b:j:' c
do
case $c in
t) TITLE="$OPTARG" ;;
b) BASE_IMAGE="$OPTARG" ;;
j) BUILD_JOBS="$OPTARG" ;;
esac
done

if [ "x$TITLE" = "x" ] || [ "x$BASE_IMAGE" = "x" ]; then
echo "Usage: $0 -t <image-title> -b <base-image> -j<build-jobs>"
echo "Example: $0 -t btccom/btcpool-btc -b btccom/btcpool_build:btc-0.16.3 -j$(nproc)"
exit
fi

docker build -t "$TITLE" -f Dockerfile --build-arg BASE_IMAGE="$BASE_IMAGE" --build-arg BUILD_JOBS="$BUILD_JOBS" --build-arg GIT_DESCRIBE="$GIT_DESCRIBE" ../../..

0 comments on commit 77fd252

Please sign in to comment.
You can’t perform that action at this time.