Skip to content

Commit 70a3a90

Browse files
authored
build: fix build environment for the liveness test (cosmos#10551)
Extracted from cosmos#10210. Make the test more reproducible, so that it does not require coordination between the build container and the run container. - Use layers to more advantage. - Include bash in the run container. - Put writable output onto a volume.
1 parent 7043dde commit 70a3a90

File tree

6 files changed

+26
-32
lines changed

6 files changed

+26
-32
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ jobs:
228228

229229
liveness-test:
230230
runs-on: ubuntu-latest
231-
timeout-minutes: 10
231+
timeout-minutes: 15
232232
steps:
233233
- uses: actions/checkout@v2
234234
- uses: actions/[email protected]

Makefile

+2-7
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,8 @@ proto-update-deps:
498498
# Run a 4-node testnet locally via docker compose
499499
localnet-start: build-linux localnet-stop
500500
$(if $(shell $(DOCKER) inspect -f '{{ .Id }}' cosmossdk/simd-env 2>/dev/null),$(info found image cosmossdk/simd-env),$(MAKE) -C contrib/images simd-env)
501-
if ! test -f build/node0/simd/config/genesis.json; then $(DOCKER) run --rm \
502-
--user $(shell id -u):$(shell id -g) \
503-
-v $(BUILDDIR):/simd:Z \
504-
-v /etc/group:/etc/group:ro \
505-
-v /etc/passwd:/etc/passwd:ro \
506-
-v /etc/shadow:/etc/shadow:ro \
507-
cosmossdk/simd-env testnet init-files --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi
501+
$(DOCKER) run --rm -v $(CURDIR)/localnet:/data cosmossdk/simd-env \
502+
testnet init-files --v 4 -o /data --starting-ip-address 192.168.10.2 --keyring-backend=test
508503
docker-compose up -d
509504

510505
localnet-stop:

contrib/images/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
all: simd-env
22

33
simd-env:
4-
docker build --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag cosmossdk/simd-env simd-env
4+
docker build --tag cosmossdk/simd-env -f simd-env/Dockerfile \
5+
$(shell git rev-parse --show-toplevel)
56

67
.PHONY: all simd-env

contrib/images/simd-env/Dockerfile

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
FROM ubuntu:18.04
1+
FROM golang:1.17-alpine AS build
2+
RUN apk add build-base git linux-headers
3+
WORKDIR /work
4+
COPY go.mod go.sum /work/
5+
COPY db/go.mod db/go.sum /work/db/
6+
RUN go mod download
7+
COPY ./ /work
8+
RUN LEDGER_ENABLED=false make clean build
29

3-
RUN apt-get update && \
4-
apt-get -y upgrade && \
5-
apt-get -y install curl jq file
10+
FROM alpine:3.14 AS run
11+
RUN apk add bash curl jq
12+
COPY contrib/images/simd-env/wrapper.sh /usr/bin/wrapper.sh
613

7-
ARG UID=1000
8-
ARG GID=1000
9-
10-
USER ${UID}:${GID}
11-
VOLUME [ "/simd" ]
14+
VOLUME /simd
15+
COPY --from=build /work/build/simd /simd/
1216
WORKDIR /simd
17+
1318
EXPOSE 26656 26657
1419
ENTRYPOINT ["/usr/bin/wrapper.sh"]
1520
CMD ["start", "--log_format", "plain"]
1621
STOPSIGNAL SIGTERM
17-
18-
COPY wrapper.sh /usr/bin/wrapper.sh

contrib/images/simd-env/wrapper.sh

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env sh
2+
set -euo pipefail
3+
set -x
24

35
BINARY=/simd/${BINARY:-simd}
46
ID=${ID:-0}
@@ -9,14 +11,7 @@ if ! [ -f "${BINARY}" ]; then
911
exit 1
1012
fi
1113

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"
14+
export SIMDHOME="/data/node${ID}/simd"
2015

2116
if [ -d "$(dirname "${SIMDHOME}"/"${LOG}")" ]; then
2217
"${BINARY}" --home "${SIMDHOME}" "$@" | tee "${SIMDHOME}/${LOG}"

docker-compose.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services:
1212
- ID=0
1313
- LOG=${LOG:-simd.log}
1414
volumes:
15-
- ./build:/simd:Z
15+
- ./localnet:/data:Z
1616
networks:
1717
localnet:
1818
ipv4_address: 192.168.10.2
@@ -28,7 +28,7 @@ services:
2828
- ID=1
2929
- LOG=${LOG:-simd.log}
3030
volumes:
31-
- ./build:/simd:Z
31+
- ./localnet:/data:Z
3232
networks:
3333
localnet:
3434
ipv4_address: 192.168.10.3
@@ -44,7 +44,7 @@ services:
4444
- "1319:1317"
4545
- "9092:9090"
4646
volumes:
47-
- ./build:/simd:Z
47+
- ./localnet:/data:Z
4848
networks:
4949
localnet:
5050
ipv4_address: 192.168.10.4
@@ -60,7 +60,7 @@ services:
6060
- "1320:1317"
6161
- "9093:9090"
6262
volumes:
63-
- ./build:/simd:Z
63+
- ./localnet:/data:Z
6464
networks:
6565
localnet:
6666
ipv4_address: 192.168.10.5

0 commit comments

Comments
 (0)