diff --git a/dkr/Dockerfile b/dkr/Dockerfile index a4150f1..c871da3 100644 --- a/dkr/Dockerfile +++ b/dkr/Dockerfile @@ -24,6 +24,9 @@ RUN pip3 install jinja2 ARG steemd_version=stable ENV steemd_version ${steemd_version} +ARG STEEM_SOURCE="https://github.com/steemit/steem.git" +ENV STEEM_SOURCE ${STEEM_SOURCE} + ARG STEEM_STATIC_BUILD=ON ENV STEEM_STATIC_BUILD ${STEEM_STATIC_BUILD} @@ -40,9 +43,9 @@ ARG SKIP_BY_TX_ID=ON ENV SKIP_BY_TX_ID ${SKIP_BY_TX_ID} RUN cd ~ && \ - git clone https://github.com/steemit/steem.git && \ + echo " >>> Cloning tag/branch ${steemd_version} from repo: ${STEEM_SOURCE}" && \ + git clone ${STEEM_SOURCE} steem -b ${steemd_version} && \ cd steem && \ - git checkout ${steemd_version} && \ git submodule update --init --recursive && \ cd ~/steem && \ cmake -DCMAKE_BUILD_TYPE=Release . \ @@ -66,8 +69,11 @@ ARG STEEMD_BIN="/usr/local/bin/steemd" ENV STEEMD_BIN ${STEEMD_BIN} RUN echo "This container has been built with the following options:" >> /steem_build.txt && \ - echo "----\nsteemit/steem version/commit: ${steemd_version}\n----" >> /steem_build.txt && \ - echo "Default steemd executable: ${STEEMD_BIN}\n----" >> /steem_build.txt && \ + echo "----" >> /steem_build.txt && \ + echo "Git Repository: ${STEEM_SOURCE}" >> /steem_build.txt && \ + echo "Git version/commit: ${steemd_version}\n----" >> /steem_build.txt && \ + echo "Default steemd executable: ${STEEMD_BIN}\n---" >> /steem_build.txt && \ + echo "--- CMake Config Options ---" >> /steem_build.txt && \ echo "LOW_MEMORY_MODE=${LOW_MEMORY_MODE}\nSTEEM_STATIC_BUILD=${STEEM_STATIC_BUILD}" >> /steem_build.txt && \ echo "SKIP_BY_TX_ID=${SKIP_BY_TX_ID}\nENABLE_MIRA=${ENABLE_MIRA}\nCLEAR_VOTES=${CLEAR_VOTES}" >> /steem_build.txt && \ echo "----\nBuilt at: $(date)\n----" >> /steem_build.txt diff --git a/dkr_fullnode/Dockerfile b/dkr_fullnode/Dockerfile index 15599f3..9dc2295 100644 --- a/dkr_fullnode/Dockerfile +++ b/dkr_fullnode/Dockerfile @@ -13,6 +13,9 @@ RUN apt-get update && \ ARG steemd_version=stable +ARG STEEM_SOURCE="https://github.com/steemit/steem.git" +ENV STEEM_SOURCE ${STEEM_SOURCE} + ARG STEEM_STATIC_BUILD=ON ENV STEEM_STATIC_BUILD ${STEEM_STATIC_BUILD} @@ -20,7 +23,7 @@ ARG ENABLE_MIRA=ON ENV ENABLE_MIRA ${ENABLE_MIRA} RUN cd ~ && \ - git clone https://github.com/steemit/steem.git && \ + git clone ${STEEM_SOURCE} steem && \ cd steem && \ git checkout ${steemd_version} && \ git submodule update --init --recursive && \ diff --git a/example.env b/example.env new file mode 100644 index 0000000..e422ecc --- /dev/null +++ b/example.env @@ -0,0 +1,71 @@ +# This is an example .env file containing common environment variables that can be customised +# by the user, to allow steem-docker to be adjusted to the user's specific needs, +# as well as to aid with running multiple instances of steem-docker. +# +# Note: The .env file is loaded by run.sh after several variables are already set. +# This means that you can reference variables such as $DIR (detected folder of run.sh), +# $DATADIR (absolute path to steem-docker/data) etc. +# +# + +# Unique name to label the container created by this steem-docker installation +DOCKER_NAME="seed" + +# Default docker image to run using ./run.sh start / restart / replay +# Also used when tagging remote image downloaded from ./run.sh install +DOCKER_IMAGE="steem" + +# Comma separated port numbers to expose to the internet (binds to 0.0.0.0) +PORTS=2001 +# Advanced Usage Example: +# +# Expose 2001 to the internet, but only expose RPC ports 8090 and 8091 onto 127.0.0.1 (localhost) +# allowing the host machine access to the container's RPC ports via 127.0.0.1:8090 and 127.0.0.1:8091 +# +# PORTS=2001,127.0.0.1:8090:8090,127.0.0.1:8091:8091 + +# Amount of time in seconds to allow the docker container to stop before killing it. +# Default: 600 seconds (10 minutes) +STOP_TIME=600 + +# Websocket RPC node to use by default for ./run.sh remote_wallet +REMOTE_WS="wss://steemd.privex.io" + +# Remote docker tags to pull when running ./run.sh install OR ./run.sh install_full with no arguments, respectively +DK_TAG="someguy123/steem:latest" +DK_TAG_FULL="someguy123/steem:latest-full" + +# Git repository to use when building Steem - containing steemd code +STEEM_SOURCE="https://github.com/steemit/steem.git" + +# LOCAL folder containing Dockerfile for ./run.sh build +DOCKER_DIR="$DIR/dkr" +# LOCAL folder to hold witness_node_data_dir +DATADIR="$DIR/data" +# LOCAL folder to store shared_memory.bin (or rocksdb files for MIRA) +SHM_DIR="/dev/shm" + +# blockchain folder, used by dlblocks +BC_FOLDER="$DATADIR/witness_node_data_dir/blockchain" + +# Example RocksDB configuration file, will automatically be copied to MIRA_FILE on first run.sh execution +# if MIRA_FILE doesn't exist +EXAMPLE_MIRA="$DATADIR/witness_node_data_dir/database.cfg.example" +MIRA_FILE="$DATADIR/witness_node_data_dir/database.cfg" + +# Example Steem node configuration file, will automatically be copied to CONF_FILE on first run.sh execution +# if CONF_FILE doesn't exist +EXAMPLE_CONF="$DATADIR/witness_node_data_dir/config.ini.example" +CONF_FILE="$DATADIR/witness_node_data_dir/config.ini" + +# Array of additional arguments to be passed to Docker during builds +# Generally populated using arguments passed to build/build_full +# But you can specify custom additional build parameters by setting BUILD_ARGS +# as an array in .env +# e.g. +# +# BUILD_ARGS=('--rm' '-q' '--compress') +# +BUILD_ARGS=() + + diff --git a/run.sh b/run.sh index 872cf0c..8e6a5aa 100755 --- a/run.sh +++ b/run.sh @@ -4,6 +4,19 @@ # Released under GNU AGPL by Someguy123 # + +# Error handling function for ShellCore +_sc_fail() { >&2 echo "Failed to load or install Privex ShellCore..." && exit 1; } +# If `load.sh` isn't found in the user install / global install, then download and run the auto-installer +# from Privex's CDN. +[[ -f "${HOME}/.pv-shcore/load.sh" ]] || [[ -f "/usr/local/share/pv-shcore/load.sh" ]] || \ + { curl -fsS https://cdn.privex.io/github/shell-core/install.sh | bash >/dev/null; } || _sc_fail + +# Attempt to load the local install of ShellCore first, then fallback to global install if it's not found. +[[ -d "${HOME}/.pv-shcore" ]] && source "${HOME}/.pv-shcore/load.sh" || \ + source "/usr/local/share/pv-shcore/load.sh" || _sc_fail + + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" : ${DOCKER_DIR="$DIR/dkr"} : ${FULL_DOCKER_DIR="$DIR/dkr_fullnode"} @@ -43,7 +56,11 @@ RESET="$(tput sgr0)" # Default: 600 seconds (10 minutes) : ${STOP_TIME=600} -# default. override in .env +# Git repository to use when building Steem - containing steemd code +: ${STEEM_SOURCE="https://github.com/steemit/steem.git"} + +# Comma separated list of ports to expose to the internet. +# By default, only port 2001 will be exposed (the P2P seed port) : ${PORTS="2001"} # Internal variable. Set to 1 by build_full to inform child functions @@ -53,6 +70,7 @@ CUST_TAG="steem" # Placeholder for BUILD_VER shared between functions BUILD_VER="" + # Array of additional arguments to be passed to Docker during builds # Generally populated using arguments passed to build/build_full # But you can specify custom additional build parameters by setting BUILD_ARGS @@ -138,7 +156,11 @@ IFS="," DPORTS=() for i in $PORTS; do if [[ $i != "" ]]; then - DPORTS+=("-p0.0.0.0:$i:$i") + if grep -q ":" <<< "$i"; then + DPORTS+=("-p$i") + else + DPORTS+=("-p0.0.0.0:$i:$i") + fi fi done @@ -217,13 +239,26 @@ parse_build_args() { shift; shift; # Get rid of the two tag arguments. Everything after is now build args fi fi + local has_steem_src='n' if (( $# >= 1 )); then msg yellow " >> Additional build arguments specified." for a in "$@"; do msg yellow " ++ Build argument: ${BOLD}${a}" BUILD_ARGS+=('--build-arg' "$a") + if grep -q 'STEEM_SOURCE' <<< "$a"; then + has_steem_src='y' + fi done fi + + if [[ "$has_steem_src" == "y" ]]; then + msg bold yellow " [!!] STEEM_SOURCE has been specified in the build arguments. Using source from build args instead of global" + else + msg bold yellow " [!!] Did not find STEEM_SOURCE in build args. Using STEEM_SOURCE from environment:" + msg bold yellow " [!!] STEEM_SOURCE = ${STEEM_SOURCE}" + BUILD_ARGS+=('--build-arg' "STEEM_SOURCE=${STEEM_SOURCE}") + fi + msg blue " ++ CUSTOM BUILD SPECIFIED. Building from branch/tag ${BOLD}${BUILD_VER}" msg blue " ++ Tagging final image as: ${BOLD}${CUST_TAG}" msg yellow " -> Docker build arguments: ${BOLD}${BUILD_ARGS[@]}"