Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dockerfile #4

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
FROM debian:bookworm-slim AS builder

RUN apt-get update -y \
&& apt-get install -y ca-certificates curl git gnupg gosu python3 wget build-essential cmake pkg-config libevent-dev libboost-dev libsqlite3-dev libzmq3-dev libminiupnpc-dev libnatpmp-dev qtbase5-dev qttools5-dev qttools5-dev-tools \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

WORKDIR /src

# Copy source files
COPY . .

# Remove any existing build directory
RUN rm -rf build/

# Run CMake to configure the build
RUN cmake -S . -B build -DBUILD_TESTS=OFF -DBUILD_UTIL:BOOL=OFF -DBUILD_TX:BOOL=OFF -DBUILD_WALLET_TOOL=OFF

# Build the project
RUN cmake --build build -j

# Second stage
FROM debian:bookworm-slim

ARG UID=101
ARG GID=101

ARG TARGETPLATFORM

ENV DRIVECHAIN_DATA=/home/drivechain/.drivechain
ENV PATH=/opt/drivechain/bin:$PATH

RUN groupadd --gid ${GID} drivechain \
&& useradd --create-home --no-log-init -u ${UID} -g ${GID} drivechain \
&& apt-get update -y \
&& apt-get --no-install-recommends -y install jq curl gnupg gosu ca-certificates pkg-config libevent-dev libboost-dev libsqlite3-dev libzmq3-dev libminiupnpc-dev libnatpmp-dev qtbase5-dev qttools5-dev qttools5-dev-tools \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY --from=builder /src/build/src/bitcoind /opt/drivechain/bin/drivechaind
COPY --from=builder /src/build/src/bitcoin-cli /opt/drivechain/bin/drivechain-cli

COPY --chmod=755 entrypoint.sh /entrypoint.sh

VOLUME ["/home/drivechain/.drivechain"]

# P2P network (mainnet, testnet & regnet respectively)
EXPOSE 8333 18333 18444

# RPC interface (mainnet, testnet & regnet respectively)
EXPOSE 8332 18332 18443

# ZMQ ports (for transactions & blocks respectively)
EXPOSE 28332 28333

HEALTHCHECK --interval=300s --start-period=60s --start-interval=10s --timeout=20s CMD gosu bitcoin bitcoin-cli -rpcwait -getinfo || exit 1

ENTRYPOINT ["/entrypoint.sh"]

RUN drivechaind -version | grep "Bitcoin Core version"

CMD ["drivechaind"]
39 changes: 39 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -e

if [ -n "${UID+x}" ] && [ "${UID}" != "0" ]; then
usermod -u "$UID" drivechain
fi

if [ -n "${GID+x}" ] && [ "${GID}" != "0" ]; then
groupmod -g "$GID" drivechain
fi

echo "$0: assuming uid:gid for drivechain:drivechain of $(id -u drivechain):$(id -g drivechain)"

if [ "$(echo "$1" | cut -c1)" = "-" ]; then
echo "$0: assuming arguments for drivechaind"

set -- drivechaind "$@"
fi

if [ "$(echo "$1" | cut -c1)" = "-" ] || [ "$1" = "drivechaind" ]; then
mkdir -p "$DRIVECHAIN_DATA"
chmod 700 "$DRIVECHAIN_DATA"
# Fix permissions for home dir.
chown -R drivechain:drivechain "$(getent passwd drivechain | cut -d: -f6)"
# Fix permissions for drivechain data dir.
chown -R drivechain:drivechain "$DRIVECHAIN_DATA"

echo "$0: setting data directory to $DRIVECHAIN_DATA"

set -- "$@" -datadir="$DRIVECHAIN_DATA"
fi

if [ "$1" = "drivechaind" ] || [ "$1" = "drivechain-cli" ]; then
echo
exec gosu drivechain "$@"
fi

echo
exec "$@"
Loading