diff --git a/docker/README.md b/docker/README.md index 27fae1e..f237438 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,5 +1,29 @@ # dockerized libbitcoin +## bitcoin explorer + +A linux image can be generated with the script below. Currently, this is only tested against the `version3` branch with or without the `v3.8.0` tag. + +### linux + +The following outlines usage of the `bx-linux` artifacts. + +#### Image construction + +The image construction can then continue via an other invocatio with the following parameters: + +``` +./bx-linux.sh --build-dir= --source= +``` + +#### Container usage + +The generated image can be used to execute the `bx` tool via the following: + +``` +docker run --interactive --tty --rm --user $(id -u):$(id -g) libbitcoin/bitcoin-explorer: +``` + ## bitcoin server A linux image can be generated with the script below. Currently, this is only tested against the `version3` branch with or without the `v3.8.0` tag. diff --git a/docker/bs-linux.Dockerfile b/docker/bs-linux.Dockerfile index 5fc323e..fdd1245 100644 --- a/docker/bs-linux.Dockerfile +++ b/docker/bs-linux.Dockerfile @@ -1,7 +1,10 @@ FROM alpine:latest AS build +ENV OPTIMIZATION="-O3" ENV BUILD_DEPS="build-base linux-headers gcc make autoconf automake libtool pkgconf git wget bash" -ENV CPPFLAGS="-O3" + +ENV CFLAGS="${OPTIMIZATION}" +ENV CXXFLAGS="${OPTIMIZATION}" RUN apk update && \ apk add --update ${BUILD_DEPS} @@ -10,33 +13,66 @@ RUN mkdir -p /build/src /build/obj /build/prefix COPY developer_setup.sh /build COPY src/ /build/src + RUN /build/developer_setup.sh \ + --build-target=dependencies \ + --build-src-dir=/build/src \ + --build-obj-dir=/build/obj \ + --prefix=/build/prefix \ + --build-mode=configure \ + --disable-shared \ + --enable-static \ --enable-isystem \ --without-consensus \ --with-icu \ --build-icu \ --build-boost \ - --build-zmq \ + --build-zmq + +RUN /build/developer_setup.sh \ + --build-target=libbitcoin \ + --build-src-dir=/build/src \ + --build-obj-dir=/build/obj \ + --prefix=/build/prefix \ --build-mode=configure \ - --build-target=all \ + --disable-shared \ + --enable-static \ + --enable-isystem \ + --without-consensus \ + --with-icu \ + --build-icu \ + --build-boost \ + --build-zmq + +RUN /build/developer_setup.sh \ + --build-target=project \ --build-src-dir=/build/src \ --build-obj-dir=/build/obj \ --prefix=/build/prefix \ + --build-mode=configure \ --disable-shared \ - --enable-static && \ - rm -rf /build/src /build/obj + --enable-static \ + --enable-isystem \ + --without-consensus \ + --with-icu \ + --build-icu \ + --build-boost \ + --build-zmq + +RUN rm -rf /build/src /build/obj FROM alpine:latest AS runtime -ENV BUILD_DEPS="build-base linux-headers gcc make autoconf automake libtool pkgconf git wget bash" +ENV RUNTIME_DEPS="bash gcc" RUN apk update && \ - apk add --update ${BUILD_DEPS} + apk add --update ${RUNTIME_DEPS} COPY --from=build /build/prefix/bin/bs /bitcoin/bs COPY bs-linux-startup.sh /bitcoin/startup.sh + # Bitcoin P2P EXPOSE 8333/tcp EXPOSE 8333/udp diff --git a/docker/bx-linux.Dockerfile b/docker/bx-linux.Dockerfile new file mode 100644 index 0000000..7e639f1 --- /dev/null +++ b/docker/bx-linux.Dockerfile @@ -0,0 +1,74 @@ +FROM alpine:latest AS build + +ENV OPTIMIZATION="-O3" +ENV BUILD_DEPS="build-base linux-headers gcc make autoconf automake libtool pkgconf git wget bash" + +ENV CFLAGS="${OPTIMIZATION}" +ENV CXXFLAGS="${OPTIMIZATION}" + +RUN apk update && \ + apk add --update ${BUILD_DEPS} + +RUN mkdir -p /build/src /build/obj /build/prefix + +COPY developer_setup.sh /build +COPY src/ /build/src + +RUN /build/developer_setup.sh \ + --build-target=dependencies \ + --build-src-dir=/build/src \ + --build-obj-dir=/build/obj \ + --prefix=/build/prefix \ + --build-mode=configure \ + --disable-shared \ + --enable-static \ + --enable-isystem \ + --with-icu \ + --build-icu \ + --build-boost \ + --build-zmq + +RUN /build/developer_setup.sh \ + --build-target=libbitcoin \ + --build-src-dir=/build/src \ + --build-obj-dir=/build/obj \ + --prefix=/build/prefix \ + --build-mode=configure \ + --disable-shared \ + --enable-static \ + --enable-isystem \ + --with-icu \ + --build-icu \ + --build-boost \ + --build-zmq + +RUN /build/developer_setup.sh \ + --build-target=project \ + --build-src-dir=/build/src \ + --build-obj-dir=/build/obj \ + --prefix=/build/prefix \ + --build-mode=configure \ + --disable-shared \ + --enable-static \ + --enable-isystem \ + --with-icu \ + --build-icu \ + --build-boost \ + --build-zmq \ + --without-tests + +RUN rm -rf /build/src /build/obj + + + +FROM alpine:latest AS runtime + +ENV RUNTIME_DEPS="gcc" + +RUN apk update && \ + apk add --update ${RUNTIME_DEPS} + +COPY --from=build /build/prefix/bin/bx /bitcoin/bx + +WORKDIR /bitcoin +ENTRYPOINT [ "/bitcoin/bx" ] diff --git a/docker/bx-linux.sh b/docker/bx-linux.sh new file mode 100755 index 0000000..96e030f --- /dev/null +++ b/docker/bx-linux.sh @@ -0,0 +1,192 @@ +#!/bin/bash + +set -e + +SCRIPT_IDENTITY=$(basename "$0") + +display_message() +{ + printf "%s\n" "$@" +} + +display_error() +{ + >&2 printf "%s\n" "$@" +} + +fatal_error() +{ + display_error "$@" + display_error "" + display_help + exit 1 +} + +display_help() +{ + display_message "Usage: ./${SCRIPT_IDENTITY} [OPTION]..." + display_message "Manage the generation of a docker image of bitcoin-explorer (bx)." + display_message "Script options:" + display_message " --build-dir= Directory for building docker image" + display_message " --source= xml file for gsl generation." + display_message " --tag= git tag to utilize with source instructions." + display_message " --build-only docker build without reinitializing build-dir." + display_message " --init-only Initialize build-dir for docker image building." + display_message "" +} + +parse_command_line_options() +{ + for OPTION in "$@"; do + case ${OPTION} in + # Specific + (--build-dir=*) DIR_BUILD="${OPTION#*=}";; + (--source=*) SOURCE="${OPTION#*=}";; + (--tag=*) TAG="${OPTION#*=}";; + (--build-only) BUILD_ONLY="yes";; + (--init-only) INIT_ONLY="yes";; + # Standard + (--help) DISPLAY_HELP="yes";; + esac + done +} + +display_state() +{ + display_message "Parameters:" + display_message " DIR_BUILD : ${DIR_BUILD}" + display_message " SOURCE : ${SOURCE}" + display_message " TAG : ${TAG}" + display_message " BUILD_ONLY : ${BUILD_ONLY}" + display_message " INIT_ONLY : ${INIT_ONLY}" + display_message "Deduced:" + display_message " DIR_BUILD_PROJ : ${DIR_BUILD_PROJ}" + display_message " VERSION : ${VERSION}" +} + +dispatch_help() +{ + if [[ ${DISPLAY_HELP} ]]; then + display_help + exit 0 + fi +} + +validate_parameterization() +{ + if [ -z ${DIR_BUILD} ]; then + fatal_error " --build-dir= required." + fi + + if [ -z ${SOURCE} ]; then + fatal_error " --source= required." + fi +} + +initialize_environment() +{ + # https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script + local DIR_SCRIPT=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + + # initialize DIR_BUILD_PROJ + pushd "${DIR_SCRIPT}/.." + DIR_BUILD_PROJ="$(pwd)" + popd + + if [ -f ${DIR_BUILD_PROJ}/${SOURCE} ]; then + SOURCE_VERSION=$(grep ' must be a valid filename in the expected path." + fi + + # rationalize intended version + if [ -z ${TAG} ]; then + VERSION="${SOURCE_VERSION}" + else + if [[ "${TAG}" =~ ^v.* ]]; then + VERSION=$(echo "${TAG}" | sed -n s/v//p) + else + VERSION="${TAG}" + fi + fi +} + +generate_instructions() +{ + display_message "Generate developer_setup.sh..." + + # create developer_setup.sh + pushd ${DIR_BUILD_PROJ} + eval gsl -q -script:templates/gsl.developer_setup.sh ${SOURCE} + chmod +x output/libbitcoin-*/developer_setup.sh + popd +} + +clean_build_directory() +{ + # cleanup build directory + if [ -d ${DIR_BUILD} ]; then + display_message "Directory '${DIR_BUILD}' found, emptying..." + pushd ${DIR_BUILD} + rm -rf developer_setup.sh src/ + mkdir -p "${DIR_BUILD}/src" + popd + else + display_message "Directory '${DIR_BUILD}' not found, building..." + mkdir -p "${DIR_BUILD}/src" + fi +} + +initialize_build_directory() +{ + if [[ $BUILD_ONLY ]]; then + return 0 + fi + + clean_build_directory + generate_instructions + + display_message "Initialize build directory contents..." + cp ${DIR_BUILD_PROJ}/output/libbitcoin-explorer/developer_setup.sh ${DIR_BUILD} + + pushd ${DIR_BUILD} + + local BUILD_TAG_PARAM="" + if [ -z ${TAG} ]; then + BUILD_TAG_PARAM="" + else + BUILD_TAG_PARAM="--build-tag=${TAG}" + fi + + ./developer_setup.sh ${BUILD_TAG_PARAM} \ + --build-sync-only \ + --build-src-dir="${DIR_BUILD}/src" \ + --build-target=all + + popd +} + +dockerize() +{ + if [[ $INIT_ONLY ]]; then + return 0 + fi + + pushd ${DIR_BUILD} + display_message "----------------------------------------------------------------------" + display_message "docker build : libbitcoin/bitcoin-explorer:${VERSION}" + display_message "----------------------------------------------------------------------" + docker build -t libbitcoin/bitcoin-explorer:${VERSION} -f ${DIR_BUILD_PROJ}/docker/bx-linux.Dockerfile . + popd +} + +parse_command_line_options "$@" +dispatch_help +validate_parameterization +initialize_environment +initialize_build_directory +display_state +dockerize