diff --git a/Dockerfile b/Dockerfile index 78d230d8f..dfe912e36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,34 @@ +##################### +# BUILD ENVIRONMENT # +##################### + +FROM golang:alpine AS build_chia_exporter + +WORKDIR /build + +RUN apk add --update --no-cache --virtual build-dependencies git ca-certificates && \ + git clone --depth 1 -b 0.12.0 https://github.com/Chia-Network/chia-exporter.git && \ + cd chia-exporter && \ + go build -o chia_exporter + +##################### +# FINAL ENVIRONMENT # +##################### + FROM debian:stable-slim -# Identify the maintainer of an image LABEL maintainer="contact@openchia.io" -# Update the image to the latest packages RUN apt-get update && apt-get upgrade -y +RUN apt-get install -y git python3-virtualenv lsb-release sudo procps tmux net-tools vim iputils-ping netcat-traditional -# Install git -RUN apt-get install git python3-virtualenv lsb-release sudo procps tmux net-tools vim iputils-ping netcat-traditional golang -y +WORKDIR /root/chia-exporter +COPY --from=build_chia_exporter /build/chia-exporter/chia_exporter . WORKDIR /root - -RUN git clone --depth 1 -b v0.5.2 https://github.com/retzkek/chia_exporter.git && \ - cd chia_exporter && go build - COPY . /root/chia-blockchain WORKDIR /root/chia-blockchain - RUN sh install.sh # Expose RPC ports @@ -26,7 +37,7 @@ EXPOSE 8444 EXPOSE 8555 EXPOSE 9256 # Chia prometheus exporter -EXPOSE 9133 +EXPOSE 9914 COPY ./docker/start.sh /root/start.sh COPY ./docker/change_config.py /root/change_config.py diff --git a/docker/change_config.py b/docker/change_config.py index 43f3ace5d..2a8400563 100644 --- a/docker/change_config.py +++ b/docker/change_config.py @@ -25,11 +25,13 @@ def main(): else: default_node_port = 8444 - config['wallet']['full_node_peer']['host'] = node_host - config['wallet']['full_node_peer']['port'] = int(os.environ.get('CHIA_NODE_PORT', default_node_port)) + config['wallet']['full_node_peers'][0]['host'] = node_host + config['wallet']['full_node_peers'][0]['port'] = int(os.environ.get('CHIA_NODE_PORT', default_node_port)) else: config['wallet'].pop('full_node_peer', None) + config['wallet']['trusted_peers'][trusted_node_id] = os.environ.get('CHIA_NODE_CRT', f'/data/chia/{chia_network}/config/ssl/full_node/public_full_node.crt') + config['wallet']['target_peer_count'] = int(os.environ.get('CHIA_PEER_COUNT', '3')) for k, v in os.environ.items(): if not k.startswith('CHIA_WALLET_'): diff --git a/docker/start.sh b/docker/start.sh index ee280f880..2d7338924 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -7,7 +7,7 @@ grep -v "::" /etc/hosts > /tmp/tmphosts cat /tmp/tmphosts > /etc/hosts if [ ! -d "/data" ]; then - echo "No /data to persist" + echo "Error: no /data to persist" exit 1 fi @@ -27,7 +27,11 @@ if [ ${chia_mode} = "wallet" ]; then chia init fi - chia keys add -l ${WALLET_ID} -f /data/wallet_keys_${WALLET_ID:=1} + # To use docker secret (require docker swarm orchestrator) + # echo "word1 word2 word3 ..." | docker secret create wallet_keys_${WALLET_ID} - + [ -e "/run/secrets/wallet_keys_${WALLET_ID:=1}" ] && WALLET_KEY_PATH="/run/secrets" + chia keys add -l ${WALLET_ID} -f ${WALLET_KEY_PATH:=/data}/wallet_keys_${WALLET_ID:=1} + rm -rf /root/.chia/mainnet/wallet mkdir -p /data/wallet_${WALLET_ID:=1} ln -fs /data/wallet_${WALLET_ID:=1} /root/.chia/mainnet/wallet @@ -49,7 +53,11 @@ if [ ${chia_mode} = "wallet" ]; then done if [ -n "${CHIA_EXPORTER}" ]; then - /root/chia_exporter/chia_exporter & + /root/chia-exporter/chia_exporter serve & + fi + + if [ -n "${CHIA_STDOUT}" ]; then + tail -f /root/.chia/mainnet/log/debug.log & fi exec ./venv/bin/chia_wallet @@ -73,7 +81,11 @@ else done if [ -n "${CHIA_EXPORTER}" ]; then - /root/chia_exporter/chia_exporter & + /root/chia-exporter/chia_exporter serve & + fi + + if [ -n "${CHIA_STDOUT}" ]; then + tail -f /root/.chia/mainnet/log/debug.log & fi exec ./venv/bin/chia_full_node