From 96efd4320c2c355f41e434e388c2bc1bba47b9e7 Mon Sep 17 00:00:00 2001 From: Orbital Date: Fri, 7 Jul 2023 13:41:21 -0500 Subject: [PATCH] Docker: Add Dockerfile for running teos --- docker/Dockerfile | 49 ++++++++++++++++++++++++++++++++ docker/entrypoint.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 docker/Dockerfile create mode 100755 docker/entrypoint.sh diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..1333ea8 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,49 @@ +# Use the rust image as the base image for the build stage +FROM rust:latest AS builder + +# Copy the rust-teos source code +COPY . /tmp/rust-teos + +# Install the dependencies required for building rust-teos +RUN apt-get update\ + && apt-get -y --no-install-recommends install libffi-dev libssl-dev musl-tools pkg-config + +RUN cd /tmp/rust-teos \ + && rustup target add x86_64-unknown-linux-musl \ + # Rustfmt is needed to format the grpc stubs generated by tonic + && rustup component add rustfmt \ + # Cross compile with musl as the target, so teosd can run on alpine + && RUSTFLAGS='-C target-feature=+crt-static' cargo build --manifest-path=teos/Cargo.toml --locked --release --target x86_64-unknown-linux-musl + +# Use a new stage with a smaller base image to reduce image size +FROM alpine:latest + +RUN apk update && apk upgrade + +# UID and GID for the teosd user +ENV TEOS_UID=1001 TEOS_GID=1001 + +# Copy the teos binaries from the build stage to the new stage +COPY --from=builder \ + /tmp/rust-teos/target/x86_64-unknown-linux-musl/release/teosd \ + /tmp/rust-teos/target/x86_64-unknown-linux-musl/release/teos-cli /usr/local/bin/ + +# Copy the entrypoint script to the container +COPY docker/entrypoint.sh /entrypoint.sh + +# Set the entrypoint script as executable and add running user +RUN chmod +x /entrypoint.sh \ + && addgroup -g ${TEOS_GID} -S teos \ + && adduser -S -G teos -u ${TEOS_UID} teos + +# Expose the default port used by teosd +EXPOSE 9814/tcp + +# Switch user so that we don't run stuff as root +USER teos + +# Create the teos data directory +RUN mkdir /home/teos/.teos + +# Start teosd when the container starts +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..f8975af --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +# Define the start command +START_COMMAND="teosd" + +# Set the API bind address +if [[ ! -z ${API_BIND} ]]; then + START_COMMAND="$START_COMMAND --apibind $API_BIND" +fi + +# Set the API port +if [[ ! -z ${API_PORT} ]]; then + START_COMMAND="$START_COMMAND --apiport $API_PORT" +fi + +# Set the RPC bind address +if [[ ! -z ${RPC_BIND} ]]; then + START_COMMAND="$START_COMMAND --rpcbind $RPC_BIND" +fi + +# Set the RPC port +if [[ ! -z ${RPC_PORT} ]]; then + START_COMMAND="$START_COMMAND --rpcport $RPC_PORT" +fi + +# Set the Bitcoin network +if [[ ! -z ${BTC_NETWORK} ]]; then + START_COMMAND="$START_COMMAND --btcnetwork $BTC_NETWORK" +fi + +# Set the Bitcoin RPC credentials +if [[ ! -z ${BTC_RPC_USER} ]]; then + START_COMMAND="$START_COMMAND --btcrpcuser $BTC_RPC_USER" +fi + +if [[ ! -z ${BTC_RPC_PASSWORD} ]]; then + START_COMMAND="$START_COMMAND --btcrpcpassword $BTC_RPC_PASSWORD" +fi + +# Set the Bitcoin RPC connection details +if [[ ! -z ${BTC_RPC_CONNECT} ]]; then + START_COMMAND="$START_COMMAND --btcrpcconnect $BTC_RPC_CONNECT" +fi + +if [[ ! -z ${BTC_RPC_PORT} ]]; then + START_COMMAND="$START_COMMAND --btcrpcport $BTC_RPC_PORT" +fi + +if [ "${DEBUG}" == "true" ]; then + START_COMMAND="$START_COMMAND --debug" +fi + +if [ "${DEPS_DEBUG}" == "true" ]; then + START_COMMAND="$START_COMMAND --depsdebug" +fi + +if [ "${OVERWRITE_KEY}" == "true" ]; then + START_COMMAND="$START_COMMAND --overwritekey" +fi + +if [ "${FORCE_UPDATE}" == "true" ]; then + START_COMMAND="$START_COMMAND --forceupdate" +fi + +# Start the TEOS daemon +$START_COMMAND