From bf0ae31e08825cfec433b17d475e1905d088d82e Mon Sep 17 00:00:00 2001 From: Richard Safier Date: Sun, 24 Mar 2024 17:32:53 -0400 Subject: [PATCH] cleanup custom docker files, 27rc1 bitcoin --- Docker/bitcoin/27.0rc1/Dockerfile | 33 +++++++++++++++++++++ Docker/{ => bitcoin/27.0rc1}/bashrc | 0 Docker/bitcoin/27.0rc1/docker-entrypoint.sh | 29 ++++++++++++++++++ Docker/{ => lnd}/Dockerfile | 0 Docker/lnd/bashrc | 8 +++++ Docker/{ => lnd}/docker-entrypoint.sh | 0 LNUnit.Tests/ABCLightningScenario.cs | 5 ++-- LNUnit.Tests/DataSync.cs | 2 +- LNUnit.Tests/DockerTest.cs | 8 ++++- LNUnit.sln.DotSettings | 7 +---- LNUnit/Setup/LNUnitBuilder.cs | 8 ++--- 11 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 Docker/bitcoin/27.0rc1/Dockerfile rename Docker/{ => bitcoin/27.0rc1}/bashrc (100%) mode change 100644 => 100755 create mode 100755 Docker/bitcoin/27.0rc1/docker-entrypoint.sh rename Docker/{ => lnd}/Dockerfile (100%) create mode 100644 Docker/lnd/bashrc rename Docker/{ => lnd}/docker-entrypoint.sh (100%) diff --git a/Docker/bitcoin/27.0rc1/Dockerfile b/Docker/bitcoin/27.0rc1/Dockerfile new file mode 100644 index 0000000..cb5baf5 --- /dev/null +++ b/Docker/bitcoin/27.0rc1/Dockerfile @@ -0,0 +1,33 @@ +FROM debian:stable-slim + +ARG BITCOIN_VERSION=27.0rc1 +ENV PATH=/opt/bitcoin-${BITCOIN_VERSION}/bin:$PATH + +RUN apt-get update -y \ + && apt-get install -y curl gosu \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +RUN SYS_ARCH="$(uname -m)" \ + && curl -SLO https://bitcoincore.org/bin/bitcoin-core-27.0/test.rc1/bitcoin-${BITCOIN_VERSION}-${SYS_ARCH}-linux-gnu.tar.gz \ + && tar -xzf *.tar.gz -C /opt \ + && rm *.tar.gz + +RUN curl -SLO https://raw.githubusercontent.com/bitcoin/bitcoin/master/contrib/bitcoin-cli.bash-completion \ + && mkdir /etc/bash_completion.d \ + && mv bitcoin-cli.bash-completion /etc/bash_completion.d/ \ + && curl -SLO https://raw.githubusercontent.com/scop/bash-completion/master/bash_completion \ + && mv bash_completion /usr/share/bash-completion/ + +COPY docker-entrypoint.sh /entrypoint.sh +COPY bashrc /home/bitcoin/.bashrc + +RUN chmod a+x /entrypoint.sh + +VOLUME ["/home/bitcoin/.bitcoin"] + +EXPOSE 18443 18444 28334 28335 + +ENTRYPOINT ["/entrypoint.sh"] + +CMD ["bitcoind"] \ No newline at end of file diff --git a/Docker/bashrc b/Docker/bitcoin/27.0rc1/bashrc old mode 100644 new mode 100755 similarity index 100% rename from Docker/bashrc rename to Docker/bitcoin/27.0rc1/bashrc diff --git a/Docker/bitcoin/27.0rc1/docker-entrypoint.sh b/Docker/bitcoin/27.0rc1/docker-entrypoint.sh new file mode 100755 index 0000000..d06dc79 --- /dev/null +++ b/Docker/bitcoin/27.0rc1/docker-entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -e + +# containers on linux share file permissions with hosts. +# assigning the same uid/gid from the host user +# ensures that the files can be read/write from both sides +if ! id bitcoin > /dev/null 2>&1; then + USERID=${USERID:-1000} + GROUPID=${GROUPID:-1000} + + echo "adding user bitcoin ($USERID:$GROUPID)" + groupadd -f -g $GROUPID bitcoin + useradd -r -u $USERID -g $GROUPID bitcoin + chown -R $USERID:$GROUPID /home/bitcoin +fi + +if [ $(echo "$1" | cut -c1) = "-" ]; then + echo "$0: assuming arguments for bitcoind" + + set -- bitcoind "$@" +fi + +if [ "$1" = "bitcoind" ] || [ "$1" = "bitcoin-cli" ] || [ "$1" = "bitcoin-tx" ]; then + echo "Running as bitcoin user: $@" + exec gosu bitcoin "$@" +fi + +echo "$@" +exec "$@" \ No newline at end of file diff --git a/Docker/Dockerfile b/Docker/lnd/Dockerfile similarity index 100% rename from Docker/Dockerfile rename to Docker/lnd/Dockerfile diff --git a/Docker/lnd/bashrc b/Docker/lnd/bashrc new file mode 100644 index 0000000..ccd7457 --- /dev/null +++ b/Docker/lnd/bashrc @@ -0,0 +1,8 @@ +# enable bash completion in interactive shells +if ! shopt -oq posix; then + if [ -f /usr/share/bash-completion/bash_completion ]; then + . /usr/share/bash-completion/bash_completion + elif [ -f /etc/bash_completion ]; then + . /etc/bash_completion + fi +fi \ No newline at end of file diff --git a/Docker/docker-entrypoint.sh b/Docker/lnd/docker-entrypoint.sh similarity index 100% rename from Docker/docker-entrypoint.sh rename to Docker/lnd/docker-entrypoint.sh diff --git a/LNUnit.Tests/ABCLightningScenario.cs b/LNUnit.Tests/ABCLightningScenario.cs index 9335632..c5d5c4b 100644 --- a/LNUnit.Tests/ABCLightningScenario.cs +++ b/LNUnit.Tests/ABCLightningScenario.cs @@ -141,7 +141,8 @@ public async Task OneTimeSetUp() // f.Database.Migrate(); var tag = "polar_lnd_0_16_3:latest"; - await _client.CreateDockerImageFromPath("./../../../../Docker/", new List { tag }); + await _client.CreateDockerImageFromPath("./../../../../Docker/lnd", new List { tag }); + await _client.CreateDockerImageFromPath("./../../../../Docker/bitcoin/27.0rc1", new List { "bitcoin:27.0rc1" }); await _client.Networks.PruneNetworksAsync(new NetworksDeleteUnusedParameters()); await RemoveContainer("miner"); await RemoveContainer("alice"); @@ -164,7 +165,7 @@ public async Task OneTimeSetUp() // _LNUnitBuilder.Configuration.DockerNetworkId = "bridge"; // } - _LNUnitBuilder.AddBitcoinCoreNode(); + _LNUnitBuilder.AddBitcoinCoreNode("miner","bitcoin","27.0rc1",pullImage:false); _LNUnitBuilder.AddPolarLNDNode("alice", new List { new() diff --git a/LNUnit.Tests/DataSync.cs b/LNUnit.Tests/DataSync.cs index bef8fe9..4fd077a 100644 --- a/LNUnit.Tests/DataSync.cs +++ b/LNUnit.Tests/DataSync.cs @@ -4,7 +4,7 @@ namespace LNUnit.Tests; -public partial class ABCLightningScenario +public partial class ABCLightningScenario { [Test] [Category("Payment")] diff --git a/LNUnit.Tests/DockerTest.cs b/LNUnit.Tests/DockerTest.cs index 9f176a5..0eb1026 100644 --- a/LNUnit.Tests/DockerTest.cs +++ b/LNUnit.Tests/DockerTest.cs @@ -111,7 +111,13 @@ private string GetRandomHexString(int size = 8) [Category("Docker")] public async Task BuildDockerImage() { - await _client.CreateDockerImageFromPath("./../../../../Docker/", new List { "polar_lnd_0_16_1_test" }); + await _client.CreateDockerImageFromPath("./../../../../Docker/lnd", new List { "custom_lnd","custom_lnd:latest" }); + } + [Test] + [Category("Docker")] + public async Task BuildBitcoin_27_0_rc1_DockerImage() + { + await _client.CreateDockerImageFromPath("./../../../../Docker/bitcoin/27.0rc1", new List { "bitcoin:27.0rc1" }); } diff --git a/LNUnit.sln.DotSettings b/LNUnit.sln.DotSettings index b723466..f6f79f7 100644 --- a/LNUnit.sln.DotSettings +++ b/LNUnit.sln.DotSettings @@ -2,15 +2,12 @@ False LND True - True + True True True True True True - True - True - True True True True @@ -19,9 +16,7 @@ True True True - True True - True True True True diff --git a/LNUnit/Setup/LNUnitBuilder.cs b/LNUnit/Setup/LNUnitBuilder.cs index 9084042..4ab650e 100644 --- a/LNUnit/Setup/LNUnitBuilder.cs +++ b/LNUnit/Setup/LNUnitBuilder.cs @@ -783,14 +783,14 @@ public static class LNUnitBuilderExtensions } - public static LNUnitBuilder AddBitcoinCoreNode(this LNUnitBuilder b, string name = "miner", bool txIndex = true) + public static LNUnitBuilder AddBitcoinCoreNode(this LNUnitBuilder b, string name = "miner", string image = "polarlightning/bitcoind", string tag= "26.0", bool txIndex = true,bool pullImage = true) { return b.AddBitcoinCoreNode(new LNUnitNetworkDefinition.BitcoinNode { - Image = "polarlightning/bitcoind", - Tag = "24.0", + Image = image, + Tag = tag, Name = name, - PullImage = true, + PullImage = pullImage, EnvironmentVariables = new Dictionary(), Cmd = new List {