Docker: Add Dockerfile for running teos

This commit is contained in:
Orbital 2023-07-07 13:41:21 -05:00
parent 658fcca0ce
commit 96efd4320c
No known key found for this signature in database
GPG key ID: E557F37C985848F7
2 changed files with 115 additions and 0 deletions

49
docker/Dockerfile Normal file
View file

@ -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" ]

66
docker/entrypoint.sh Executable file
View file

@ -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