Skip to content

Commit 3d85d97

Browse files
committed
new docker build
1 parent 9f6ba57 commit 3d85d97

6 files changed

Lines changed: 159 additions & 122 deletions

File tree

Dockerfile

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,48 @@
1+
# Use Go 1.23 bookworm as base image
2+
FROM golang:1.23-bookworm AS base
13

2-
FROM ignitehq/cli:v0.26.1
3-
4-
5-
USER root
64
RUN apt-get -y -qq update && \
7-
apt-get install -y -qq apt-transport-https curl wget unzip screen bash jq python3 pip && \
8-
apt-get clean
9-
5+
apt-get install -y -qq apt-transport-https curl wget unzip screen bash jq python3 python3-pip python3-venv && \
6+
rm -rf /var/lib/apt/lists/*
107

118
# install python script to download genesis
9+
RUN python3 -m venv /opt/venv
10+
ENV PATH="/opt/venv/bin:$PATH"
1211
RUN pip install tendermint-chunked-genesis-download
1312

13+
RUN pip install tendermint-chunked-genesis-download
1414

15-
# install correct go version
16-
RUN if [ $(uname -m) = "x86_64" ]; then \
17-
wget https://go.dev/dl/go1.23.6.linux-amd64.tar.gz; \
18-
tar -xvf go1.23.6.linux-amd64.tar.gz; \
19-
rm /usr/local/go -rf; \
20-
mv go /usr/local; \
21-
elif [ $(uname -m) = "aarch64" ]; then \
22-
wget https://go.dev/dl/go1.23.6.linux-arm64.tar.gz; \
23-
tar -xvf go1.23.6.linux-arm64.tar.gz; \
24-
rm /usr/local/go -rf; \
25-
mv go /usr/local; \
26-
else \
27-
echo "what the hell is your OS? Go will not work that way."; \
28-
fi
29-
15+
# Move to working directory /build
16+
WORKDIR /build
3017

31-
USER tendermint
32-
WORKDIR /home/tendermint
18+
# Copy the go.mod and go.sum files to the /build directory
19+
COPY . .
3320

34-
RUN export GOPATH=$HOME/go
3521
RUN wget https://github.com/DecentralCardGame/go-faucet/archive/master.zip && \
3622
unzip master.zip -d . && cd go-faucet-master && go build
3723

24+
# Install dependencies
25+
RUN go install github.com/lxgr-linux/ignite-vm@latest
26+
27+
# Build the application
28+
RUN ignite-vm install v0.26.2
29+
RUN ignite-vm set v0.26.2
30+
31+
RUN ~/.local/bin/ignite chain init --home /build/.cardchaind
32+
RUN ~/.local/bin/ignite chain build
33+
34+
# Document the port that may need to be published
3835
EXPOSE 1317
3936
EXPOSE 26657
4037
EXPOSE 26658
4138
EXPOSE 9090
4239
EXPOSE 9091
4340
EXPOSE 4500
4441

45-
COPY --chown=tendermint:tendermint . .
46-
47-
RUN ignite chain build --skip-proto
48-
RUN ignite chain init --skip-proto
49-
50-
RUN mv $HOME/.Cardchain $HOME/.cardchaind
51-
5242
COPY scripts/download_genesis.py download_genesis.py
5343
RUN python3 download_genesis.py
54-
RUN cp genesis.json files/
55-
RUN mv genesis.json $HOME/.cardchaind/config/genesis.json
44+
RUN mv genesis.json /build/.cardchaind/config/genesis.json
5645

46+
# Start the application
5747
RUN chmod +x ./docker-run.sh
58-
ENTRYPOINT bash docker-run.sh
48+
ENTRYPOINT bash docker-run.sh

config/faucetmnemonic.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<enter correct mnemonic here>

docker-compose.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ services:
55
build: .
66
command: ./docker-run.sh
77
volumes:
8-
- ./backup:/backup
9-
- ./docker-run.sh:/home/tendermint/docker-run.sh
10-
- ./peer_nodes.json:/home/tendermint/peer_nodes.json
11-
- ./files/:/home/tendermint/files/
8+
- ./backup:/build/backup
9+
- ./docker-run.sh:/build/docker-run.sh
10+
- ./peer_nodes.json:/build/peer_nodes.json
11+
- ./files/:/build/files/
1212
ports:
1313
- 26657:26657
1414
- 26658:26658
@@ -36,6 +36,6 @@ services:
3636
- 81:81
3737
- 443:443
3838
command: /bin/bash -c "exec nginx -g 'daemon off;'"
39-
depends_on:
39+
depends_on:
4040
- blockchain
41-
- goat
41+
- goat

docker-run.sh

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,89 +2,90 @@
22

33
#set -eo pipefail
44

5+
WORKDIR="/build"
6+
57
echo -e "\033[0;32mfasten your seatbelts\033[0m"
68
FAUCET_SECRET_KEY="0x6F1f5bd93f3D59d6eed1d5ec40E29C1821029759"
7-
USE_SNAP=false
9+
USE_SNAP=true
810

911
if [ -z "$FAUCET_SECRET_KEY" ]
1012
then
11-
echo -e "\033[0;31mNO SECRET KEY FOR FAUCET CONFIGURED! \033[0m"
12-
exit 1
13+
echo -e "\033[0;31mNO SECRET KEY FOR FAUCET CONFIGURED! \033[0m"
14+
exit 1
1315
fi
1416

1517
#we can derive the peer id from the rpc
1618
mapfile -t peers < <(
17-
jq -r '.peers[]' peer_nodes.json
19+
jq -r '.peers[]' peer_nodes.json
1820
)
1921

2022
for item in "${peers[@]}"; do
2123
echo "peers: ${item}"
2224
done
2325

2426
mapfile -t rpcs < <(
25-
jq -r '.rpcs[]' peer_nodes.json
27+
jq -r '.rpcs[]' peer_nodes.json
2628
)
2729

2830
echo "peers" $peers
2931

3032
for i in "${!rpcs[@]}"; do
31-
if curl --output /dev/null --silent --head --fail --connect-timeout 5 ${rpcs[$i]}; then
32-
echo "URL exists: ${rpcs[$i]}"
33-
PEER_ID=$(curl -s ${rpcs[$i]}"/status" | jq -r .result.node_info.id)
34-
35-
PEERS=$PEER_ID"@"${peers[$i]}
36-
break
37-
else
38-
echo "not reachable $i"
39-
fi
33+
if curl --output /dev/null --silent --head --fail --connect-timeout 5 ${rpcs[$i]}; then
34+
echo "URL exists: ${rpcs[$i]}"
35+
PEER_ID=$(curl -s ${rpcs[$i]}"/status" | jq -r .result.node_info.id)
36+
37+
PEERS=$PEER_ID"@"${peers[$i]}
38+
break
39+
else
40+
echo "not reachable $i"
41+
fi
4042
done
4143
if [ -z "$PEERS" ]
4244
then
43-
echo -e "\033[0;31mNo PEERS available\033[0m"
44-
exit
45+
echo -e "\033[0;31mNo PEERS available\033[0m"
46+
exit
4547
fi
4648

4749
SEEDS=""
4850
echo "peers is:" $PEERS
49-
sed -i.bak -e "s/^seeds *=.*/seeds = \"$SEEDS\"/; s/^persistent_peers *=.*/persistent_peers = \"$PEERS\"/" $HOME/.cardchaind/config/config.toml
51+
sed -i.bak -e "s/^seeds *=.*/seeds = \"$SEEDS\"/; s/^persistent_peers *=.*/persistent_peers = \"$PEERS\"/" $WORKDIR/.cardchaind/config/config.toml
5052

51-
if [ -z $USE_SNAP ]
53+
if $USE_SNAP
5254
then
5355

54-
mapfile -t snap_rpcs < <(
55-
jq -r '.snap_rpcs[]' peer_nodes.json
56-
)
57-
58-
for i in "${snap_rpcs[@]}"; do
59-
if curl --output /dev/null --silent --head --fail --connect-timeout 5 $i; then
60-
echo "URL exists: $i"
61-
SNAP_RPC=$i
62-
break
63-
else
64-
echo "not reachable $i"
65-
fi
66-
done
67-
if [ -z "$SNAP_RPC" ]
68-
then
69-
echo -e "\033[0;31mNo SNAP_RPC available\033[0m"
70-
exit
71-
fi
72-
73-
LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height)
74-
echo $LATEST_HEIGHT
75-
BLOCK_HEIGHT=$((LATEST_HEIGHT)); \
76-
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)
77-
echo -e "\033[0;36mlatest height: $LATEST_HEIGHT \nblock height: $BLOCK_HEIGHT \ntrust hash: $TRUST_HASH \033[0m"
78-
79-
sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
80-
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$SNAP_RPC,$SNAP_RPC\"| ; \
81-
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ; \
82-
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"|" $HOME/.cardchaind/config/config.toml ; \
83-
56+
mapfile -t snap_rpcs < <(
57+
jq -r '.snap_rpcs[]' peer_nodes.json
58+
)
59+
60+
for i in "${snap_rpcs[@]}"; do
61+
if curl --output /dev/null --silent --head --fail --connect-timeout 5 $i; then
62+
echo "URL exists: $i"
63+
SNAP_RPC=$i
64+
break
65+
else
66+
echo "not reachable $i"
67+
fi
68+
done
69+
if [ -z "$SNAP_RPC" ]
70+
then
71+
echo -e "\033[0;31mNo SNAP_RPC available\033[0m"
72+
exit
73+
fi
74+
75+
LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height)
76+
echo $LATEST_HEIGHT
77+
BLOCK_HEIGHT=$((LATEST_HEIGHT)); \
78+
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)
79+
echo -e "\033[0;36mlatest height: $LATEST_HEIGHT \nblock height: $BLOCK_HEIGHT \ntrust hash: $TRUST_HASH \033[0m"
80+
81+
sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
82+
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$SNAP_RPC,$SNAP_RPC\"| ; \
83+
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ; \
84+
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"|" $WORKDIR/.cardchaind/config/config.toml ; \
8485
fi
8586

8687
# copy genesis.json to nginx server
87-
cp $HOME/.cardchaind/config/genesis.json $HOME/files/genesis.json
88+
cp $WORKDIR/.cardchaind/config/genesis.json $WORKDIR/files/genesis.json
8889

8990
# config pruning
9091
indexer="kv"
@@ -93,24 +94,35 @@ pruning_keep_recent="100"
9394
pruning_keep_every="0"
9495
pruning_interval="10"
9596

96-
sed -i -e "s/^indexer *=.*/indexer = \"$indexer\"/" $HOME/.cardchaind/config/config.toml
97-
sed -i -e "s/^pruning *=.*/pruning = \"$pruning\"/" $HOME/.cardchaind/config/app.toml
98-
sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"$pruning_keep_recent\"/" $HOME/.cardchaind/config/app.toml
99-
sed -i -e "s/^pruning-keep-every *=.*/pruning-keep-every = \"$pruning_keep_every\"/" $HOME/.cardchaind/config/app.toml
100-
sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"$pruning_interval\"/" $HOME/.cardchaind/config/app.toml
97+
sed -i -e "s/^indexer *=.*/indexer = \"$indexer\"/" $WORKDIR/.cardchaind/config/config.toml
98+
sed -i -e "s/^pruning *=.*/pruning = \"$pruning\"/" $WORKDIR/.cardchaind/config/app.toml
99+
sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"$pruning_keep_recent\"/" $WORKDIR/.cardchaind/config/app.toml
100+
sed -i -e "s/^pruning-keep-every *=.*/pruning-keep-every = \"$pruning_keep_every\"/" $WORKDIR/.cardchaind/config/app.toml
101+
sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"$pruning_interval\"/" $WORKDIR/.cardchaind/config/app.toml
102+
101103

102104
echo -e "\033[0;32mstarting faucet \033[0m"
105+
KEYS=$(cardchaind keys list --keyring-backend test)
106+
echo -e "$KEYS"
107+
EXPECTED_KEY="cc164axafcd2pxeuumu9zm72nmdyfa65qpx4hdh52"
108+
109+
# Check if key exists
110+
if echo "$KEYS" | grep -q "$EXPECTED_KEY"; then
111+
echo "Key already exists. Skipping 'keys add'."
112+
else
113+
echo "Key not found. Importing from mnemonic..."
114+
cat "$WORKDIR/config/faucetmnemonic.txt" | cardchaind keys add alice --recover --keyring-backend test
115+
fi
116+
103117
sed -i -e "s/^SECRET_KEY *=.*/SECRET_KEY = \"$FAUCET_SECRET_KEY\"/" go-faucet-master/.env
104118
cd go-faucet-master
105119
./go-faucet &
106-
echo -e "\033[0;31mfaucet adress: \033[0;36m $(cardchaind keys show alice --address) \033[0;31m must be registered!\033[0m use scripts/register_faucet.sh for that"
107-
echo $(cardchaind keys show alice --address) > /backup/faucetaddress.txt
108120

109121
echo -e "\033[0;32mstarting Blockchain\033[0m"
110-
cardchaind start
122+
cardchaind start --home $WORKDIR/.cardchaind
111123

112124
# backup area (this will be executed if the cardchaind process is killed)
113125
now=$(date +"%d.%m.%Y")
114-
cardchaind export > /backup/genesis$now.json
126+
cardchaind export > $WORKDIR/backup/genesis$now.json --home $WORKDIR/.cardchaind
115127
echo "BACKUP should be in /backup/genesis$now - don't forget to use migrate_with_data.py script in case you need it"
116-
echo "fail? is backup folder owned by root? (no idea how this happens though)"
128+
echo "fail? is backup folder owned by root? (no idea how this happens though)"

0 commit comments

Comments
 (0)