Skip to content

Commit

Permalink
use a non-docker-managed data directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocynicys committed Jul 30, 2023
1 parent f7d6bd5 commit d2b1f31
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
40 changes: 19 additions & 21 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,45 @@ FROM rust:latest AS builder
COPY . /tmp/rust-teos

# Install the dependencies required for building Rust-TEOSd
RUN apt-get update &&\
RUN apt-get update && \
apt-get -y --no-install-recommends install libffi-dev libssl-dev musl-tools pkg-config

RUN cd /tmp/rust-teos\
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 target add x86_64-unknown-linux-musl\
&& rustup component add rustfmt\
&& rustup component add rustfmt \
# Cross compile with musl as the target, so teos 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
&& 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 TEOSD_UID=1001 TEOSD_GID=1001
RUN apk update && apk upgrade && apk add --update bash sudo

# Copy the teos binary from the build stage to the new stage
COPY --from=builder\
/tmp/rust-teos/target/x86_64-unknown-linux-musl/release/teosd\
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 ${TEOSD_GID} -S teosd\
&& adduser -S -G teosd -u ${TEOSD_UID} teosd
# Set the entrypoint script as executable
RUN chmod +x /entrypoint.sh

# Add a new user (with sudo permisions)
RUN adduser -S teos
RUN echo 'teos ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# Expose the default port used by Rust-TEOSd
EXPOSE 9814/tcp

# Switch user so that we don't run stuff as root
USER teosd

# Create a volume for the TEOS data directory
#VOLUME ["/home/teosd/.teos"]
RUN mkdir /home/teosd/.teos
RUN chown 1001:1001 /home/teosd/.teos
RUN mkdir /home/teos/.teos
RUN chown teos /home/teos/.teos

This comment has been minimized.

Copy link
@mariocynicys

mariocynicys Jul 30, 2023

Author Owner

This line isn't needed


# Switch user so that we don't run stuff as root
USER teos

# Start Rust-TEOS when the container starts
ENTRYPOINT [ "/entrypoint.sh" ]
11 changes: 6 additions & 5 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/sh

# Own the data directory
sudo chown -R teos /home/teos/.teos

# Allow the configuration file to be edited by anyone (so an outside users can edit it easily)
chmod 666 /home/teos/.teos/teos.toml

# Define the start command
START_COMMAND="teosd"

Expand Down Expand Up @@ -46,10 +52,6 @@ if [[ ! -z ${BTC_RPC_PORT} ]]; then
START_COMMAND="$START_COMMAND --btcrpcport $BTC_RPC_PORT"
fi

if [[ ! -z ${DATA_DIR} ]]; then
START_COMMAND="$START_COMMAND --datadir $DATA_DIR"
fi

if [[ ! -z ${DEBUG} ]]; then
START_COMMAND="$START_COMMAND --debug $DEBUG"
fi
Expand All @@ -66,6 +68,5 @@ if [[ ! -z ${FORCE_UPDATE} ]]; then
START_COMMAND="$START_COMMAND --forceupdate $FORCE_UPDATE"
fi


# Start the TEOS daemon
$START_COMMAND

This comment has been minimized.

Copy link
@mariocynicys

mariocynicys Jul 30, 2023

Author Owner

We can append --datadir=SOME_DATA_DIR here and use a simpler directory (shorter than /home/teos/.teos), maybe just /.teos.
Will need to change the chowns and chmods accordingly.

0 comments on commit d2b1f31

Please sign in to comment.