Skip to content

Commit 91ff9fa

Browse files
alexanderbeztac0turtleAlessio Treglia
authored
buildsystem: simplify Makefile and ci automation (cosmos#7189)
Move images into contrib/images/. Replace "bad tag" cosmos-sdk/simapp with cosmos-sdk/simd-env. 'simapp' is a misnomer as the images serves only as host environment for the binaries that are in fact built by the developer on their machine. Remove the build-docker-local-simapp target altogether from the Makefile in favor of an inline conditional statement that causes the image to be rebuilt if and only if it had not been built before. simd binary won't run as root anymore as root privileges are dropped upon simd binary installation. Co-authored-by: Marko Baricevic <[email protected]> Co-authored-by: Alexander Bezobchuk <[email protected]> Co-authored-by: Alessio Treglia <[email protected]>
1 parent db9b69d commit 91ff9fa

File tree

7 files changed

+76
-29
lines changed

7 files changed

+76
-29
lines changed

.github/workflows/test.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
id: git_diff
2424
with:
2525
PREFIX_FILTER: |
26-
cosmovisor
26+
cosmovisor
2727
SUFFIX_FILTER: |
2828
.go
2929
.mod
@@ -204,6 +204,7 @@ jobs:
204204
with:
205205
file: ./coverage.txt
206206
if: "env.GIT_DIFF != ''"
207+
207208
liveness-test:
208209
runs-on: ubuntu-latest
209210
timeout-minutes: 10
@@ -216,9 +217,6 @@ jobs:
216217
.go
217218
.mod
218219
.sum
219-
- name: build image
220-
run: |
221-
make build-docker-local-simapp
222220
- name: start localnet
223221
run: |
224222
make clean localnet-start

Makefile

+10-6
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,19 @@ proto-update-deps:
395395
### Localnet ###
396396
###############################################################################
397397

398-
build-docker-local-simapp:
399-
docker build -t cosmos-sdk/simapp .
400-
401398
# Run a 4-node testnet locally
402-
localnet-start: localnet-stop
403-
@if ! [ -f build/node0/simd/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/root:Z cosmos-sdk/simapp simd testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi
399+
localnet-start: build-simd-linux localnet-stop
400+
$(if $(shell docker inspect -f '{{ .Id }}' cosmossdk/simd-env 2>/dev/null),$(info found image cosmossdk/simd-env),$(MAKE) -C contrib/images simd-env)
401+
if ! [ -f build/node0/simd/config/genesis.json ]; then docker run --rm \
402+
--user $(shell id -u):$(shell id -g) \
403+
-v $(BUILDDIR):/simd:Z \
404+
-v /etc/group:/etc/group:ro \
405+
-v /etc/passwd:/etc/passwd:ro \
406+
-v /etc/shadow:/etc/shadow:ro \
407+
cosmossdk/simd-env testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi
404408
docker-compose up -d
405409

406410
localnet-stop:
407411
docker-compose down
408412

409-
.PHONY: build-docker-local-simapp localnet-start localnet-stop
413+
.PHONY: localnet-start localnet-stop

contrib/images/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
all: simd-env
2+
3+
simd-env:
4+
docker build --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag cosmossdk/simd-env simd-env
5+
6+
.PHONY: all simd-env

contrib/images/simd-env/Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM ubuntu:18.04
2+
3+
RUN apt-get update && \
4+
apt-get -y upgrade && \
5+
apt-get -y install curl jq file
6+
7+
ARG UID=1000
8+
ARG GID=1000
9+
10+
USER ${UID}:${GID}
11+
VOLUME [ /simd ]
12+
WORKDIR /simd
13+
EXPOSE 26656 26657
14+
ENTRYPOINT ["/usr/bin/wrapper.sh"]
15+
CMD ["start"]
16+
STOPSIGNAL SIGTERM
17+
18+
COPY wrapper.sh /usr/bin/wrapper.sh

contrib/images/simd-env/wrapper.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env sh
2+
3+
BINARY=/simd/${BINARY:-simd}
4+
ID=${ID:-0}
5+
LOG=${LOG:-simd.log}
6+
7+
if ! [ -f "${BINARY}" ]; then
8+
echo "The binary $(basename "${BINARY}") cannot be found. Please add the binary to the shared folder. Please use the BINARY environment variable if the name of the binary is not 'simd'"
9+
exit 1
10+
fi
11+
12+
BINARY_CHECK="$(file "$BINARY" | grep 'ELF 64-bit LSB executable, x86-64')"
13+
14+
if [ -z "${BINARY_CHECK}" ]; then
15+
echo "Binary needs to be OS linux, ARCH amd64"
16+
exit 1
17+
fi
18+
19+
export SIMDHOME="/simd/node${ID}/simd"
20+
21+
if [ -d "$(dirname "${SIMDHOME}"/"${LOG}")" ]; then
22+
"${BINARY}" --home "${SIMDHOME}" "$@" | tee "${SIMDHOME}/${LOG}"
23+
else
24+
"${BINARY}" --home "${SIMDHOME}" "$@"
25+
fi

contrib/localnet_liveness.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fi
2929
docker_containers=( $(docker ps -q -f name=simd --format='{{.Names}}') )
3030

3131
while [ ${CNT} -lt $ITER ]; do
32-
curr_block=$(curl -s $NODEADDR:26655/status | jq -r '.result.sync_info.latest_block_height')
32+
curr_block=$(curl -s $NODEADDR:26657/status | jq -r '.result.sync_info.latest_block_height')
3333

3434
if [ ! -z ${curr_block} ] ; then
3535
echo "Number of Blocks: ${curr_block}"

docker-compose.yml

+14-18
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,64 @@ version: "3"
33
services:
44
simdnode0:
55
container_name: simdnode0
6-
image: "cosmos-sdk/simapp"
6+
image: "cosmossdk/simd-env"
77
ports:
8-
- "26654-26655:26656-26657"
9-
- "1316:1317"
10-
- "9089:9090"
11-
command: ["simd", "start"]
8+
- "26656-26657:26656-26657"
9+
- "1317:1317"
10+
- "9090:9090"
1211
environment:
1312
- ID=0
1413
- LOG=${LOG:-simd.log}
1514
volumes:
16-
- ./build/node0/simd/:/root/.simapp:Z
15+
- ./build:/simd:Z
1716
networks:
1817
localnet:
1918
ipv4_address: 192.168.10.2
2019

2120
simdnode1:
2221
container_name: simdnode1
23-
image: "cosmos-sdk/simapp"
22+
image: "cosmossdk/simd-env"
2423
ports:
25-
- "26659-26660:26656-26657"
24+
- "26666-26667:26656-26657"
2625
- "1318:1317"
2726
- "9091:9090"
28-
command: ["simd", "start"]
2927
environment:
3028
- ID=1
3129
- LOG=${LOG:-simd.log}
3230
volumes:
33-
- ./build/node1/simd/:/root/.simapp:Z
31+
- ./build:/simd:Z
3432
networks:
3533
localnet:
3634
ipv4_address: 192.168.10.3
3735

3836
simdnode2:
3937
container_name: simdnode2
40-
image: "cosmos-sdk/simapp"
38+
image: "cosmossdk/simd-env"
4139
environment:
4240
- ID=2
4341
- LOG=${LOG:-simd.log}
44-
command: ["simd", "start"]
4542
ports:
46-
- "26661-26662:26656-26657"
43+
- "26676-26677:26656-26657"
4744
- "1319:1317"
4845
- "9092:9090"
4946
volumes:
50-
- ./build/node2/simd/:/root/.simapp:Z
47+
- ./build:/simd:Z
5148
networks:
5249
localnet:
5350
ipv4_address: 192.168.10.4
5451

5552
simdnode3:
5653
container_name: simdnode3
57-
image: "cosmos-sdk/simapp"
54+
image: "cosmossdk/simd-env"
5855
environment:
5956
- ID=3
6057
- LOG=${LOG:-simd.log}
61-
command: ["simd", "start"]
6258
ports:
63-
- "26663-26664:26656-26657"
59+
- "26686-26687:26656-26657"
6460
- "1320:1317"
6561
- "9093:9090"
6662
volumes:
67-
- ./build/node3/simd/:/root/.simapp:Z
63+
- ./build:/simd:Z
6864
networks:
6965
localnet:
7066
ipv4_address: 192.168.10.5

0 commit comments

Comments
 (0)