Compare commits
9 Commits
ef208dbc83
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
7761772dda
|
|||
|
28327d8604
|
|||
|
ed91f1ba49
|
|||
|
1f6e63ddad
|
|||
|
6253ed1f5f
|
|||
|
9a88767eaf
|
|||
|
7ed94e64f3
|
|||
|
e270e0f616
|
|||
|
604840eef9
|
16
README.md
16
README.md
@@ -16,7 +16,10 @@ Here are some example snippets to help you get started creating a container.
|
|||||||
version: "3"
|
version: "3"
|
||||||
services:
|
services:
|
||||||
pybitmessage:
|
pybitmessage:
|
||||||
image: bitdeals/pybitmessage
|
build:
|
||||||
|
context: https://git.bitdeals.org/private/bitmessage.git
|
||||||
|
dockerfile: ./docker/Dockerfile
|
||||||
|
image: registry.bitdeals.org/bitmessage
|
||||||
environment:
|
environment:
|
||||||
- BITMESSAGE_API_USER=bitmessage_api_user
|
- BITMESSAGE_API_USER=bitmessage_api_user
|
||||||
- BITMESSAGE_API_PASSWORD=bitmessage_api_password
|
- BITMESSAGE_API_PASSWORD=bitmessage_api_password
|
||||||
@@ -39,7 +42,7 @@ docker run -d \
|
|||||||
-e BITMESSAGE_TTL=172800 \
|
-e BITMESSAGE_TTL=172800 \
|
||||||
-e BITMESSAGE_STOPRESENDINGAFTERXDAYS=60
|
-e BITMESSAGE_STOPRESENDINGAFTERXDAYS=60
|
||||||
-p 8442:8442 \
|
-p 8442:8442 \
|
||||||
bitdeals/pybitmessage
|
registry.bitdeals.org/bitmessage
|
||||||
```
|
```
|
||||||
|
|
||||||
# Parameters
|
# Parameters
|
||||||
@@ -48,11 +51,12 @@ Container images are configured using parameters passed at runtime.
|
|||||||
|
|
||||||
|Parameter|Function|
|
|Parameter|Function|
|
||||||
|:--------|:-------|
|
|:--------|:-------|
|
||||||
|-p 8442|XML-RPC API port TCP|
|
|-p 8442|API port|
|
||||||
|-e BITMESSAGE_API_USER=|XML-RPC API user. Default: `bitmessage_api_user`|
|
|-e BITMESSAGE_API_USER|XML-RPC API user. Default: `bitmessage_api_user`|
|
||||||
|-e BITMESSAGE_API_PASSWORD=|XML-RPC API password. Default: `bitmessage_api_password`|
|
|-e BITMESSAGE_API_PASSWORD|XML-RPC API password. Default: `bitmessage_api_password`|
|
||||||
|-e BITMESSAGE_SEED_PHRASE|Create Deterministic Addresses password. Default: `bitmessage_seed_phrase`|
|
|-e BITMESSAGE_SEED_PHRASE|Create Deterministic Addresses password. Default: created randomly. |
|
||||||
|-e BITMESSAGE_SEED_ADDRESSES|Number of Deterministic Addresses to generate. Default: `1`|
|
|-e BITMESSAGE_SEED_ADDRESSES|Number of Deterministic Addresses to generate. Default: `1`|
|
||||||
|-e BITMESSAGE_TTL|The expiration of newly send messages, in seconds. Default: `172800`|
|
|-e BITMESSAGE_TTL|The expiration of newly send messages, in seconds. Default: `172800`|
|
||||||
|-e BITMESSAGE_STOPRESENDINGAFTERXDAYS|Stop resending unreceived message after X days. Default: `60`|
|
|-e BITMESSAGE_STOPRESENDINGAFTERXDAYS|Stop resending unreceived message after X days. Default: `60`|
|
||||||
|
|-e BITMESSAGE_APIVARIANT|provides xml or json-RPC API. Default: `legacy`|
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
version: '3.9'
|
|
||||||
services:
|
services:
|
||||||
bitmessage:
|
bitmessage:
|
||||||
image: bitdeals/pybitmessage:0.6.3.2-ubuntu
|
build:
|
||||||
build: ./docker
|
context: ./docker
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
image: registry.bitdeals.org/bitmessage
|
||||||
environment:
|
environment:
|
||||||
- BITMESSAGE_API_USER=bitmessage_api_user
|
- BITMESSAGE_API_USER=bitmessage_api_user
|
||||||
- BITMESSAGE_API_PASSWORD=bitmessage_api_password
|
- BITMESSAGE_API_PASSWORD=bitmessage_api_password
|
||||||
- BITMESSAGE_SEED_PHRASE=bitmessage_seed_phrase
|
- BITMESSAGE_SEED_PHRASE=
|
||||||
- BITMESSAGE_SEED_ADDRESSES=1
|
- BITMESSAGE_SEED_ADDRESSES=1
|
||||||
- BITMESSAGE_TTL=172800
|
- BITMESSAGE_TTL=172800
|
||||||
- BITMESSAGE_STOPRESENDINGAFTERXDAYS=60
|
- BITMESSAGE_STOPRESENDINGAFTERXDAYS=60
|
||||||
ports:
|
ports:
|
||||||
- 8442:8442
|
- 8442:8442
|
||||||
|
volumes:
|
||||||
|
- bitmessage:/home/bitmessage
|
||||||
|
volumes:
|
||||||
|
bitmessage:
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# A container for PyBitmessage daemon
|
# A container for PyBitmessage daemon
|
||||||
FROM ubuntu:bionic-20220401
|
FROM ubuntu:bionic
|
||||||
|
|
||||||
SHELL ["/bin/bash", "-exo", "pipefail", "-c"]
|
SHELL ["/bin/bash", "-exo", "pipefail", "-c"]
|
||||||
|
|
||||||
@@ -11,25 +11,18 @@ RUN apt-get install -yq --no-install-suggests --no-install-recommends \
|
|||||||
python-all-dev python-msgpack python-pip python-setuptools \
|
python-all-dev python-msgpack python-pip python-setuptools \
|
||||||
git
|
git
|
||||||
|
|
||||||
WORKDIR /root
|
## Do not use cache when building next layers of the image.
|
||||||
RUN git clone https://github.com/Bitmessage/PyBitmessage
|
ARG NOCACHE=0
|
||||||
|
|
||||||
WORKDIR /root/PyBitmessage
|
WORKDIR /root/PyBitmessage
|
||||||
|
RUN git clone https://github.com/Bitmessage/PyBitmessage .
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
RUN pip2 install jsonrpclib .
|
RUN pip2 install jsonrpclib .
|
||||||
|
|
||||||
FROM ubuntu:bionic-20220401
|
FROM ubuntu:bionic
|
||||||
|
|
||||||
EXPOSE 8442
|
EXPOSE 8442/tcp
|
||||||
|
|
||||||
ENV BITMESSAGE_API_USER=bitmessage_api_user
|
|
||||||
ENV BITMESSAGE_API_PASSWORD=bitmessage_api_password
|
|
||||||
ENV BITMESSAGE_SEED_PHRASE=bitmessage_seed_phrase
|
|
||||||
ENV BITMESSAGE_SEED_ADDRESSES=1
|
|
||||||
ENV BITMESSAGE_API_PORT=8442
|
|
||||||
ENV BITMESSAGE_TTL=172800
|
|
||||||
ENV BITMESSAGE_STOPRESENDINGAFTERXDAYS=30
|
|
||||||
|
|
||||||
ENV USER_UID=2000
|
ENV USER_UID=2000
|
||||||
ENV USER_GID=2000
|
ENV USER_GID=2000
|
||||||
@@ -37,6 +30,9 @@ ENV HOME=/home/bitmessage
|
|||||||
ENV BITMESSAGE_HOME=${HOME}
|
ENV BITMESSAGE_HOME=${HOME}
|
||||||
|
|
||||||
COPY --from=0 /usr/local/ /usr/local/
|
COPY --from=0 /usr/local/ /usr/local/
|
||||||
|
COPY ./docker/healthy_check.py /usr/local/bin/
|
||||||
|
COPY ./docker/seed_addr_gen.py /usr/local/bin/
|
||||||
|
COPY ./docker/run.sh /usr/local/bin/
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
@@ -45,29 +41,16 @@ RUN apt-get update \
|
|||||||
|
|
||||||
# Create a user
|
# Create a user
|
||||||
RUN addgroup --gid $USER_GID bitmessage ;\
|
RUN addgroup --gid $USER_GID bitmessage ;\
|
||||||
useradd --uid $USER_UID --gid $USER_GID -m -d $HOME bitmessage
|
useradd --uid $USER_UID --gid $USER_GID --skel /dev/null --create-home --home-dir $HOME bitmessage
|
||||||
|
|
||||||
WORKDIR ${HOME}
|
WORKDIR ${HOME}
|
||||||
|
|
||||||
# Generate default config
|
# Generate default config
|
||||||
RUN su bitmessage -c "pybitmessage -t"
|
RUN su bitmessage -c "pybitmessage -t"
|
||||||
|
|
||||||
# Setup environment
|
CMD ["sh", "/usr/local/bin/run.sh"]
|
||||||
CMD chown bitmessage:bitmessage keys.dat; chmod 600 keys.dat; \
|
|
||||||
cat keys.dat | \
|
|
||||||
sed -e "s|\(apiinterface = \).*|\10\.0\.0\.0|g" \
|
|
||||||
#-e "s|\(apivariant = \).*|\1json|g" \
|
|
||||||
-e "s|\(apiusername = \).*|\1$BITMESSAGE_API_USER|g" \
|
|
||||||
-e "s|\(apipassword = \).*|\1$BITMESSAGE_API_PASSWORD|g" \
|
|
||||||
-e "s|\(apiport = \).*|\1$BITMESSAGE_API_PORT|g" \
|
|
||||||
-e "s|\(apienabled = \).*|\1True|g" \
|
|
||||||
-e "s|\(ttl = \).*|\1$BITMESSAGE_TTL|g" \
|
|
||||||
-e "s|\(stopresendingafterxdays = \).*|\1$BITMESSAGE_STOPRESENDINGAFTERXDAYS|g" \
|
|
||||||
-e "s|\(udp = \).*|\1False|g" | \
|
|
||||||
gosu bitmessage sponge keys.dat && \
|
|
||||||
exec gosu bitmessage nice -n 19 pybitmessage -d
|
|
||||||
|
|
||||||
# Generate Deterministic address
|
## Check PyBitmessage active network connections
|
||||||
HEALTHCHECK --retries=3 --interval=15s \
|
HEALTHCHECK --retries=0 --interval=15s \
|
||||||
CMD python -c "import xmlrpclib; api_link='http://$BITMESSAGE_API_USER:$BITMESSAGE_API_PASSWORD@127.0.0.1:8442/'; api = xmlrpclib.ServerProxy(api_link); print api.createDeterministicAddresses('$BITMESSAGE_SEED_PHRASE'.encode('base64'),$BITMESSAGE_SEED_ADDRESSES)" || exit 1
|
CMD ["python", "/usr/local/bin/healthy_check.py"]
|
||||||
|
|
||||||
|
|||||||
23
docker/healthy_check.py
Normal file
23
docker/healthy_check.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import xmlrpclib
|
||||||
|
import json
|
||||||
|
|
||||||
|
api_user=os.getenv('BITMESSAGE_API_USER', 'bitmessage_api_user') ;
|
||||||
|
api_password=os.getenv('BITMESSAGE_API_PASSWORD', 'bitmessage_api_password') ;
|
||||||
|
api_port=os.getenv('BITMESSAGE_API_PORT', '8442') ;
|
||||||
|
|
||||||
|
api_link="http://{}:{}@127.0.0.1:{}/".format(api_user, api_password, api_port)
|
||||||
|
|
||||||
|
api = xmlrpclib.ServerProxy(api_link)
|
||||||
|
|
||||||
|
network_connections=json.loads(api.clientStatus())['networkConnections']
|
||||||
|
print "networkConnections:", network_connections
|
||||||
|
|
||||||
|
if network_connections > 0:
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
49
docker/run.sh
Normal file
49
docker/run.sh
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
export BITMESSAGE_API_USER=${BITMESSAGE_API_USER:-bitmessage_api_user}
|
||||||
|
export BITMESSAGE_API_PASSWORD=${BITMESSAGE_API_PASSWORD:-bitmessage_api_password}
|
||||||
|
export BITMESSAGE_SEED_ADDRESSES=${BITMESSAGE_SEED_ADDRESSES:-1}
|
||||||
|
export BITMESSAGE_API_PORT=${BITMESSAGE_API_PORT:-8442}
|
||||||
|
export BITMESSAGE_TTL=${BITMESSAGE_TTL:-172800}
|
||||||
|
export BITMESSAGE_STOPRESENDINGAFTERXDAYS=${BITMESSAGE_STOPRESENDINGAFTERXDAYS:-30}
|
||||||
|
export BITMESSAGE_APIVARIANT=${BITMESSAGE_APIVARIANT:-legacy}
|
||||||
|
|
||||||
|
SEED_FILE="address_seed.txt"
|
||||||
|
test -e "$SEED_FILE" || gosu bitmessage touch "$SEED_FILE"
|
||||||
|
|
||||||
|
# Save seed to file, or use saved seed
|
||||||
|
if [ -n "$BITMESSAGE_SEED_PHRASE" ]
|
||||||
|
then
|
||||||
|
export BITMESSAGE_SEED_PHRASE
|
||||||
|
grep -q "$BITMESSAGE_SEED_PHRASE" "$SEED_FILE" \
|
||||||
|
|| echo "$BITMESSAGE_SEED_PHRASE" >> "$SEED_FILE"
|
||||||
|
else
|
||||||
|
OLD_SEED="$(tail -n1 $SEED_FILE)"
|
||||||
|
NEW_SEED="$(cat /dev/random | tr -dc "a-z" | head -c32)"
|
||||||
|
export BITMESSAGE_SEED_PHRASE="${OLD_SEED:-$NEW_SEED}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# this command must be run as root (for bind mounts to container)
|
||||||
|
chown bitmessage:bitmessage keys.dat
|
||||||
|
chmod 600 keys.dat
|
||||||
|
|
||||||
|
# set config values
|
||||||
|
gosu bitmessage sed -i -e "s|\(apiinterface = \).*|\10\.0\.0\.0|g" \
|
||||||
|
-e "s|\(apivariant = \).*|\1$BITMESSAGE_APIVARIANT|g" \
|
||||||
|
-e "s|\(apiusername = \).*|\1$BITMESSAGE_API_USER|g" \
|
||||||
|
-e "s|\(apipassword = \).*|\1$BITMESSAGE_API_PASSWORD|g" \
|
||||||
|
-e "s|\(apiport = \).*|\1$BITMESSAGE_API_PORT|g" \
|
||||||
|
-e "s|\(apienabled = \).*|\1True|g" \
|
||||||
|
-e "s|\(ttl = \).*|\1$BITMESSAGE_TTL|g" \
|
||||||
|
-e "s|\(stopresendingafterxdays = \).*|\1$BITMESSAGE_STOPRESENDINGAFTERXDAYS|g" \
|
||||||
|
-e "s|\(udp = \).*|\1False|g" keys.dat
|
||||||
|
|
||||||
|
# generate address from seed
|
||||||
|
for i in {1..4}
|
||||||
|
do
|
||||||
|
sleep 15
|
||||||
|
gosu bitmessage /usr/bin/python /usr/local/bin/seed_addr_gen.py
|
||||||
|
done &
|
||||||
|
|
||||||
|
exec gosu bitmessage pybitmessage -d
|
||||||
|
|
||||||
17
docker/seed_addr_gen.py
Normal file
17
docker/seed_addr_gen.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import os
|
||||||
|
import xmlrpclib
|
||||||
|
|
||||||
|
api_user=os.getenv('BITMESSAGE_API_USER', 'bitmessage_api_user') ;
|
||||||
|
api_password=os.getenv('BITMESSAGE_API_PASSWORD', 'bitmessage_api_password') ;
|
||||||
|
api_port=os.getenv('BITMESSAGE_API_PORT', '8442') ;
|
||||||
|
addr_num=os.getenv('BITMESSAGE_SEED_ADDRESSES', '1') ;
|
||||||
|
addr_seed=os.getenv('BITMESSAGE_SEED_PHRASE') ;
|
||||||
|
|
||||||
|
api_link="http://{}:{}@127.0.0.1:{}/".format(api_user, api_password, api_port)
|
||||||
|
|
||||||
|
api = xmlrpclib.ServerProxy(api_link)
|
||||||
|
|
||||||
|
print api.createDeterministicAddresses(addr_seed.encode('base64'),int(addr_num))
|
||||||
|
|
||||||
Reference in New Issue
Block a user