From 91ff9fa417eea4eaa15276e675dba9b15a063ef5 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Mon, 31 Aug 2020 09:39:05 -0400 Subject: [PATCH] buildsystem: simplify Makefile and ci automation (#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 Co-authored-by: Alexander Bezobchuk Co-authored-by: Alessio Treglia --- .github/workflows/test.yml | 6 ++---- Makefile | 16 +++++++++------ contrib/images/Makefile | 6 ++++++ contrib/images/simd-env/Dockerfile | 18 +++++++++++++++++ contrib/images/simd-env/wrapper.sh | 25 +++++++++++++++++++++++ contrib/localnet_liveness.sh | 2 +- docker-compose.yml | 32 +++++++++++++----------------- 7 files changed, 76 insertions(+), 29 deletions(-) create mode 100644 contrib/images/Makefile create mode 100644 contrib/images/simd-env/Dockerfile create mode 100755 contrib/images/simd-env/wrapper.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8afd74132e22..831523bc6a69 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: id: git_diff with: PREFIX_FILTER: | - cosmovisor + cosmovisor SUFFIX_FILTER: | .go .mod @@ -204,6 +204,7 @@ jobs: with: file: ./coverage.txt if: "env.GIT_DIFF != ''" + liveness-test: runs-on: ubuntu-latest timeout-minutes: 10 @@ -216,9 +217,6 @@ jobs: .go .mod .sum - - name: build image - run: | - make build-docker-local-simapp - name: start localnet run: | make clean localnet-start diff --git a/Makefile b/Makefile index c3f3a06d6d28..1678d990a3ff 100644 --- a/Makefile +++ b/Makefile @@ -395,15 +395,19 @@ proto-update-deps: ### Localnet ### ############################################################################### -build-docker-local-simapp: - docker build -t cosmos-sdk/simapp . - # Run a 4-node testnet locally -localnet-start: localnet-stop - @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 +localnet-start: build-simd-linux localnet-stop + $(if $(shell docker inspect -f '{{ .Id }}' cosmossdk/simd-env 2>/dev/null),$(info found image cosmossdk/simd-env),$(MAKE) -C contrib/images simd-env) + if ! [ -f build/node0/simd/config/genesis.json ]; then docker run --rm \ + --user $(shell id -u):$(shell id -g) \ + -v $(BUILDDIR):/simd:Z \ + -v /etc/group:/etc/group:ro \ + -v /etc/passwd:/etc/passwd:ro \ + -v /etc/shadow:/etc/shadow:ro \ + cosmossdk/simd-env testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi docker-compose up -d localnet-stop: docker-compose down -.PHONY: build-docker-local-simapp localnet-start localnet-stop +.PHONY: localnet-start localnet-stop diff --git a/contrib/images/Makefile b/contrib/images/Makefile new file mode 100644 index 000000000000..c0ec5240fdb8 --- /dev/null +++ b/contrib/images/Makefile @@ -0,0 +1,6 @@ +all: simd-env + +simd-env: + docker build --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag cosmossdk/simd-env simd-env + +.PHONY: all simd-env diff --git a/contrib/images/simd-env/Dockerfile b/contrib/images/simd-env/Dockerfile new file mode 100644 index 000000000000..3be7eb5c847e --- /dev/null +++ b/contrib/images/simd-env/Dockerfile @@ -0,0 +1,18 @@ +FROM ubuntu:18.04 + +RUN apt-get update && \ + apt-get -y upgrade && \ + apt-get -y install curl jq file + +ARG UID=1000 +ARG GID=1000 + +USER ${UID}:${GID} +VOLUME [ /simd ] +WORKDIR /simd +EXPOSE 26656 26657 +ENTRYPOINT ["/usr/bin/wrapper.sh"] +CMD ["start"] +STOPSIGNAL SIGTERM + +COPY wrapper.sh /usr/bin/wrapper.sh diff --git a/contrib/images/simd-env/wrapper.sh b/contrib/images/simd-env/wrapper.sh new file mode 100755 index 000000000000..a2250098577c --- /dev/null +++ b/contrib/images/simd-env/wrapper.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env sh + +BINARY=/simd/${BINARY:-simd} +ID=${ID:-0} +LOG=${LOG:-simd.log} + +if ! [ -f "${BINARY}" ]; then + 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'" + exit 1 +fi + +BINARY_CHECK="$(file "$BINARY" | grep 'ELF 64-bit LSB executable, x86-64')" + +if [ -z "${BINARY_CHECK}" ]; then + echo "Binary needs to be OS linux, ARCH amd64" + exit 1 +fi + +export SIMDHOME="/simd/node${ID}/simd" + +if [ -d "$(dirname "${SIMDHOME}"/"${LOG}")" ]; then + "${BINARY}" --home "${SIMDHOME}" "$@" | tee "${SIMDHOME}/${LOG}" +else + "${BINARY}" --home "${SIMDHOME}" "$@" +fi diff --git a/contrib/localnet_liveness.sh b/contrib/localnet_liveness.sh index 90c02e1a6cb1..00c360b98dc7 100755 --- a/contrib/localnet_liveness.sh +++ b/contrib/localnet_liveness.sh @@ -29,7 +29,7 @@ fi docker_containers=( $(docker ps -q -f name=simd --format='{{.Names}}') ) while [ ${CNT} -lt $ITER ]; do - curr_block=$(curl -s $NODEADDR:26655/status | jq -r '.result.sync_info.latest_block_height') + curr_block=$(curl -s $NODEADDR:26657/status | jq -r '.result.sync_info.latest_block_height') if [ ! -z ${curr_block} ] ; then echo "Number of Blocks: ${curr_block}" diff --git a/docker-compose.yml b/docker-compose.yml index 56e1fbff39b6..d335b9a06c47 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,68 +3,64 @@ version: "3" services: simdnode0: container_name: simdnode0 - image: "cosmos-sdk/simapp" + image: "cosmossdk/simd-env" ports: - - "26654-26655:26656-26657" - - "1316:1317" - - "9089:9090" - command: ["simd", "start"] + - "26656-26657:26656-26657" + - "1317:1317" + - "9090:9090" environment: - ID=0 - LOG=${LOG:-simd.log} volumes: - - ./build/node0/simd/:/root/.simapp:Z + - ./build:/simd:Z networks: localnet: ipv4_address: 192.168.10.2 simdnode1: container_name: simdnode1 - image: "cosmos-sdk/simapp" + image: "cosmossdk/simd-env" ports: - - "26659-26660:26656-26657" + - "26666-26667:26656-26657" - "1318:1317" - "9091:9090" - command: ["simd", "start"] environment: - ID=1 - LOG=${LOG:-simd.log} volumes: - - ./build/node1/simd/:/root/.simapp:Z + - ./build:/simd:Z networks: localnet: ipv4_address: 192.168.10.3 simdnode2: container_name: simdnode2 - image: "cosmos-sdk/simapp" + image: "cosmossdk/simd-env" environment: - ID=2 - LOG=${LOG:-simd.log} - command: ["simd", "start"] ports: - - "26661-26662:26656-26657" + - "26676-26677:26656-26657" - "1319:1317" - "9092:9090" volumes: - - ./build/node2/simd/:/root/.simapp:Z + - ./build:/simd:Z networks: localnet: ipv4_address: 192.168.10.4 simdnode3: container_name: simdnode3 - image: "cosmos-sdk/simapp" + image: "cosmossdk/simd-env" environment: - ID=3 - LOG=${LOG:-simd.log} - command: ["simd", "start"] ports: - - "26663-26664:26656-26657" + - "26686-26687:26656-26657" - "1320:1317" - "9093:9090" volumes: - - ./build/node3/simd/:/root/.simapp:Z + - ./build:/simd:Z networks: localnet: ipv4_address: 192.168.10.5