Compare commits

..

9 Commits

Author SHA1 Message Date
7761772dda add registry 2025-03-19 14:12:45 +03:00
28327d8604 add apivariant 2024-11-29 13:40:12 +03:00
ed91f1ba49 add NOCACHE arg 2024-11-15 15:51:29 +03:00
1f6e63ddad dockerfile fix 2024-11-03 13:49:16 +03:00
6253ed1f5f Docker fix 2024-08-14 17:12:40 +03:00
9a88767eaf Docker fix 2024-08-14 17:08:57 +03:00
7ed94e64f3 Docker fix 2024-08-12 09:38:30 +03:00
e270e0f616 Docker fix 2024-08-12 09:31:39 +03:00
604840eef9 add run.sh CMD in Dockerfile 2024-08-12 09:30:42 +03:00
6 changed files with 122 additions and 41 deletions

View File

@@ -16,7 +16,10 @@ Here are some example snippets to help you get started creating a container.
version: "3"
services:
pybitmessage:
image: bitdeals/pybitmessage
build:
context: https://git.bitdeals.org/private/bitmessage.git
dockerfile: ./docker/Dockerfile
image: registry.bitdeals.org/bitmessage
environment:
- BITMESSAGE_API_USER=bitmessage_api_user
- BITMESSAGE_API_PASSWORD=bitmessage_api_password
@@ -39,7 +42,7 @@ docker run -d \
-e BITMESSAGE_TTL=172800 \
-e BITMESSAGE_STOPRESENDINGAFTERXDAYS=60
-p 8442:8442 \
bitdeals/pybitmessage
registry.bitdeals.org/bitmessage
```
# Parameters
@@ -48,11 +51,12 @@ Container images are configured using parameters passed at runtime.
|Parameter|Function|
|:--------|:-------|
|-p 8442|XML-RPC API port TCP|
|-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_SEED_PHRASE|Create Deterministic Addresses password. Default: `bitmessage_seed_phrase`|
|-p 8442|API port|
|-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_SEED_PHRASE|Create Deterministic Addresses password. Default: created randomly. |
|-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_STOPRESENDINGAFTERXDAYS|Stop resending unreceived message after X days. Default: `60`|
|-e BITMESSAGE_APIVARIANT|provides xml or json-RPC API. Default: `legacy`|

View File

@@ -1,15 +1,20 @@
version: '3.9'
services:
bitmessage:
image: bitdeals/pybitmessage:0.6.3.2-ubuntu
build: ./docker
build:
context: ./docker
dockerfile: Dockerfile
image: registry.bitdeals.org/bitmessage
environment:
- BITMESSAGE_API_USER=bitmessage_api_user
- BITMESSAGE_API_PASSWORD=bitmessage_api_password
- BITMESSAGE_SEED_PHRASE=bitmessage_seed_phrase
- BITMESSAGE_SEED_PHRASE=
- BITMESSAGE_SEED_ADDRESSES=1
- BITMESSAGE_TTL=172800
- BITMESSAGE_STOPRESENDINGAFTERXDAYS=60
ports:
- 8442:8442
volumes:
- bitmessage:/home/bitmessage
volumes:
bitmessage:

View File

@@ -1,5 +1,5 @@
# A container for PyBitmessage daemon
FROM ubuntu:bionic-20220401
FROM ubuntu:bionic
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 \
git
WORKDIR /root
RUN git clone https://github.com/Bitmessage/PyBitmessage
## Do not use cache when building next layers of the image.
ARG NOCACHE=0
WORKDIR /root/PyBitmessage
RUN git clone https://github.com/Bitmessage/PyBitmessage .
# Install
RUN pip2 install jsonrpclib .
FROM ubuntu:bionic-20220401
FROM ubuntu:bionic
EXPOSE 8442
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
EXPOSE 8442/tcp
ENV USER_UID=2000
ENV USER_GID=2000
@@ -37,6 +30,9 @@ ENV HOME=/home/bitmessage
ENV BITMESSAGE_HOME=${HOME}
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
RUN apt-get update \
@@ -45,29 +41,16 @@ RUN apt-get update \
# Create a user
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}
# Generate default config
RUN su bitmessage -c "pybitmessage -t"
# Setup environment
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
CMD ["sh", "/usr/local/bin/run.sh"]
# Generate Deterministic address
HEALTHCHECK --retries=3 --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
## Check PyBitmessage active network connections
HEALTHCHECK --retries=0 --interval=15s \
CMD ["python", "/usr/local/bin/healthy_check.py"]

23
docker/healthy_check.py Normal file
View 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
View 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
View 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))