Skip to content

Commit

Permalink
Merge pull request #107 from Anoncoin/docker
Browse files Browse the repository at this point in the history
Dockerfile for Anoncoin daemon
  • Loading branch information
Cryptoslave committed Jan 6, 2017
2 parents 3fd47af + 98b5213 commit b0106db
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 0 deletions.
53 changes: 53 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM alpine:latest

MAINTAINER Mikal Villa <mikal@sigterm.no>

ENV GIT_BRANCH="master"
ENV ANONCOIN_PREFIX="/opt/anoncoin-${GIT_BRANCH}"
ENV PATH=${ANONCOIN_PREFIX}/bin:$PATH
ENV ANONCOIN_DATA="/home/anoncoin/.anoncoin/"

ENV GOSU_VERSION=1.7
ENV GOSU_SHASUM="34049cfc713e8b74b90d6de49690fa601dc040021980812b2f1f691534be8a50 /usr/local/bin/gosu"

ENV BERKELEYDB_VERSION=db-4.8.30.NC
ENV BERKELEYDB_PREFIX=/opt/${BERKELEYDB_VERSION}

RUN apk --no-cache --virtual build-dependendencies add autoconf automake make gcc g++ libtool pkgconfig git boost-dev build-base openssl-dev git

RUN adduser -S anoncoin

RUN mkdir -p /tmp/build && cd /tmp/build && git clone -b ${GIT_BRANCH} https://github.com/Anoncoin/anoncoin.git \
&& wget -O /tmp/build/${BERKELEYDB_VERSION}.tar.gz http://download.oracle.com/berkeley-db/${BERKELEYDB_VERSION}.tar.gz \
&& tar -xzf /tmp/build/${BERKELEYDB_VERSION}.tar.gz -C /tmp/build/ \
&& sed s/__atomic_compare_exchange/__atomic_compare_exchange_db/g -i /tmp/build/${BERKELEYDB_VERSION}/dbinc/atomic.h \
&& mkdir -p ${BERKELEYDB_PREFIX} \
&& cd /tmp/build/${BERKELEYDB_VERSION}/build_unix \
&& ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=${BERKELEYDB_PREFIX} \
&& make install

RUN apk --no-cache add openssl \
&& wget -O /usr/local/bin/gosu https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64 \
&& echo "${GOSU_SHASUM}" | sha256sum -c \
&& chmod +x /usr/local/bin/gosu

RUN cd /tmp/build/anoncoin && ./autogen.sh && ./configure LDFLAGS=-L${BERKELEYDB_PREFIX}/lib \
CPPFLAGS=-I${BERKELEYDB_PREFIX}/include --prefix=${ANONCOIN_PREFIX} --without-qrencode \
--without-miniupnpc --with-gui=no --disable-shared --enable-hardening --disable-tests \
--with-pic --disable-ccache --with-daemon --with-utils && make -j4 && make install

#RUN strip ${ANONCOIN_PREFIX}/bin/anoncoind && ${ANONCOIN_PREFIX}/bin/anoncoin-tx ${ANONCOIN_PREFIX}/bin/anoncoin-cli \
RUN rm -rf /tmp/build ${BERKELEYDB_PREFIX}/docs && apk --no-cache --purge del \
autoconf automake make gcc g++ libtool pkgconfig git boost-dev build-base openssl-dev git \
&& apk --no-cache add boost boost-program_options

COPY entrypoint.sh /entrypoint.sh
RUN chmod a+x /entrypoint.sh

VOLUME [ "/home/anoncoin/.anoncoin" ]

EXPOSE 19377 9377 9376 19376

ENTRYPOINT [ "/entrypoint.sh" ]

CMD [ "anoncoind" ]
44 changes: 44 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Howto build & run
==================

**Build**

Assuming you're in the root directory of the anoncoin source code.

$ `cd docker`
$ `docker -t anoncoin .`

**Run**

If you don't have a anoncoin.conf yet, the entrypoint.sh will make one for you with a random password.

$ `docker run --name anonnode -v confandblockchainOnHostPath:/home/anoncoin/.anoncoin -p 9376:9376 -p 9377:9377 -d meeh/anoncoin`

**Options**

Options are set via docker environment variables. This can be set at run with -e parameters.

* DEBUG_ENABLED - If set to 1, debug messages is enabled (default: 0).
* CONF_MAXCONN - Maximum remote connections (default: 500).
* CONF_TESTNET - If set to 1, anoncoin will connect to the testnet (default: 0).
* CONF_NOTIFY_MAIL - If a email is set, anoncoin notifies with sending a mail when a problem occurs.
* CONF_EXTRAS - Whatever parameters you'll want. Note; only one option per line.

**Logging**

Logging happens to STDOUT as the best practise with docker containers, since infrastructure systems like kubernetes with ELK integration can automaticly forward the log to say, kibana or greylog without manual setup. :)


**Interaction with it**

Example:

$ `docker exec -ti anonnode gosu anoncoin anoncoin-cli getinfo`

On kubernetes it would be something like:

$ `kubectl exec -ti anonnode-u19231-pod81293 -- gosu anoncoin anoncoin-cli getinfo`

You can also talk to it via the json-rpc endpoint at 9376.


39 changes: 39 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

DEBUG_ENABLED=${DEBUG_ENABLED:-0}
CONF_MAXCONN=${CONF_MAXCONN:-500}
CONF_TESTNET=${CONF_TESTNET:-0}

CONF_NOTIFY_MAIL=""
if [ "$NOTIFY_MAIL" != "" ]; then
CONF_NOTIFY_MAIL="alertnotify=echo %s | mail -s 'Anoncoin Alert' $NOTIFY_MAIL"
fi

conf_dir="/home/anoncoin/.anoncoin"
conf_file="/home/anoncoin/.anoncoin/anoncoin.conf"

# Config check
if [ ! -f "$conf_file" ]; then
mkdir -p $conf_dir && chown anoncoin:nobody $conf_dir
cat <<EOT >> $conf_file
rpcuser=anoncoinrpc`date +%s | sha256sum | base64 | tail -c 4 ; echo`
rpcpassword=`date +%s | sha256sum | base64 | head -c 32 ; echo`
debug=$DEBUG_ENABLED
maxconnections=$CONF_MAXCONN
testnet=$CONF_TESTNET
printtoconsole=1
daemon=0 # DO NOT SET THIS TO 1, that will break the docker instance. If anoncoind isn't in foreground, the container dies at once.
listen=1
bind=0.0.0.0
$CONF_NOTIFY_MAIL
$CONF_EXTRAS
EOT
chown anoncoin:nobody $conf_file
fi

if [ "$1" = "anoncoind" ] || [ "$1" = "anoncoin-cli" ] || [ "$1" = "anoncoin-tx" ]; then
exec gosu anoncoin "$1"
fi

echo
exec "$@"
24 changes: 24 additions & 0 deletions docker/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM ubuntu:16.04

MAINTAINER Mikal Villa <mikal@sigterm.no>

RUN apt update && apt install -y build-essential git vim libboost-all-dev pkg-config automake autoconf libtool libdb++-dev libssl-dev

RUN cd /usr/src && git clone https://github.com/Anoncoin/anoncoin.git

RUN cd /usr/src/anoncoin && ./autogen.sh && ./configure --prefix=/usr/local --without-qrencode --without-miniupnpc --with-gui=no \
--disable-shared --enable-hardening --disable-tests --with-pic --with-incompatible-bdb

RUN cd /usr/src/anoncoin && make -j4 && make install

RUN apt remove -y automake autoconf git libtool build-essential && apt autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/*

VOLUME [ "/root/.anoncoin" ]

COPY entrypoint.sh /entrypoint.sh

RUN chmod a+x /entrypoint.sh

EXPOSE 19377 9377 9376 19376

ENTRYPOINT [ "/entrypoint.sh" ]
6 changes: 6 additions & 0 deletions docker/ubuntu/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Warning
========

This shows how it could be done, **and is in no way complete**.
You have to write your own entrypoint.sh or modify the alpine
version's entrypoint.sh to use this.

0 comments on commit b0106db

Please sign in to comment.