-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docker: Add Dockerfile for running teos
- Loading branch information
1 parent
1a89c5d
commit f882af8
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 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\ | ||
# Rust-fmt is needed to format the grpc stubs generated by tonic | ||
&& rustup target add x86_64-unknown-linux-musl\ | ||
&& 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 && apk add --update bash | ||
|
||
# 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 a volume for the teos data directory | ||
RUN mkdir /home/teos/.teos | ||
RUN chown 1001:1001 /home/teos/.teos | ||
|
||
# Start teosd when the container starts | ||
ENTRYPOINT [ "/entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/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 [[ ! -z ${DEBUG} ]]; then | ||
START_COMMAND="$START_COMMAND --debug" | ||
fi | ||
|
||
if [[ ! -z ${DEPS_DEBUG} ]]; then | ||
START_COMMAND="$START_COMMAND --depsdebug" | ||
fi | ||
|
||
if [[ ! -z ${OVERWRITE_KEY} ]]; then | ||
START_COMMAND="$START_COMMAND --overwritekey" | ||
fi | ||
|
||
if [[ ! -z ${FORCE_UPDATE} ]]; then | ||
START_COMMAND="$START_COMMAND --forceupdate" | ||
fi | ||
|
||
|
||
# Start the TEOS daemon | ||
$START_COMMAND |