Skip to content

Commit

Permalink
Merge tag 'v2.1.1' into release/v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Turcan committed Jun 12, 2023
2 parents 27df600 + 7ae83bb commit 88ea162
Show file tree
Hide file tree
Showing 187 changed files with 18,999 additions and 43,989 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
build_type: ['build-release-amd64']
build_type: ['build-release-arm64', 'build-release-amd64']
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set version tag
run: echo "VERSION=$(echo ${{github.ref_name}} | sed 's/^v//')" >> $GITHUB_ENV
- name: Create build directory
run: mkdir -p build/release
- name: Build ${{matrix.build_type}}
run: make ${{matrix.build_type}}
- name: Upload the artifacts to release
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
**/**.go
go.mod
go.sum
# Enable BuildKit
- name: Set BuildKit environment variable
run: |
echo "DOCKER_BUILDKIT=1" >> $GITHUB_ENV
- name: start localnet
run: |
make clean localnet-start
Expand All @@ -67,6 +71,10 @@ jobs:
app/upgrades/**/*.go
- name: echo diff
run: echo '${{ env.GIT_DIFF }}'
# Enable BuildKit
- name: Set BuildKit environment variable
run: |
echo "DOCKER_BUILDKIT=1" >> $GITHUB_ENV
- name: start localnet
run: |
make clean localnet-start-upgrade
Expand Down
138 changes: 105 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,54 +1,126 @@
# docker build . -t cosmwasm/wasmd:latest
# docker run --rm -it cosmwasm/wasmd:latest /bin/sh
FROM golang:1.18-alpine3.17 AS go-builder
ARG source=.
# syntax=docker/dockerfile:1

# this comes from standard alpine nightly file
# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile
# with some changes to support our toolchain, etc
RUN set -eux; apk add --no-cache ca-certificates build-base;
ARG source=./
ARG GO_VERSION="1.18"
ARG ALPINE_VERSION="3.17"
ARG BUILDPLATFORM=linux/amd64
ARG BASE_IMAGE="golang:${GO_VERSION}-alpine${ALPINE_VERSION}"
FROM --platform=${BUILDPLATFORM} ${BASE_IMAGE} as base

RUN apk add git cmake
# NOTE: add these to run with LEDGER_ENABLED=true
# RUN apk add libusb-dev linux-headers
###############################################################################
# Builder
###############################################################################

WORKDIR /code
COPY ${source} /code/
FROM base as builder-stage-1

# Install mimalloc
RUN git clone -b v2.0.0 --depth 1 https://github.com/microsoft/mimalloc; cd mimalloc; mkdir build; cd build; cmake ..; make -j$(nproc); make install
ENV MIMALLOC_RESERVE_HUGE_OS_PAGES=4
ARG source
ARG GIT_COMMIT
ARG GIT_VERSION
ARG BUILDPLATFORM
ARG GOOS=linux \
GOARCH=amd64

# Cosmwasm - download correct libwasmvm version and verify checksum
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) \
&& wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
-O /lib/libwasmvm_muslc.a \
&& wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt \
&& sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep $(uname -m) | cut -d ' ' -f 1)
ENV GOOS=$GOOS \
GOARCH=$GOARCH

# force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LDFLAGS="-linkmode=external -extldflags \"-L/code/mimalloc/build -lmimalloc -Wl,-z,muldefs -static\"" make build
# NOTE: add libusb-dev to run with LEDGER_ENABLED=true
RUN set -eux &&\
apk update &&\
apk add --no-cache \
ca-certificates \
linux-headers \
build-base \
cmake \
git

FROM alpine:3.17
# install mimalloc for musl
WORKDIR ${GOPATH}/src/mimalloc
RUN set -eux &&\
git clone --depth 1 --branch v2.0.9 \
https://github.com/microsoft/mimalloc . &&\
mkdir -p build &&\
cd build &&\
cmake .. &&\
make -j$(nproc) &&\
make install

RUN apk add wget lz4 aria2 curl jq gawk coreutils "zlib>1.2.12-r2" "libssl1.1>1.1.1q-r0" && apk update
# download dependencies to cache as layer
WORKDIR ${GOPATH}/src/app
COPY ${source}go.mod ${source}go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go mod download -x

RUN addgroup terra \
&& adduser -G terra -D -h /terra terra
# Cosmwasm - Download correct libwasmvm version and verify checksum
RUN set -eux &&\
WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && \
WASMVM_DOWNLOADS="https://github.com/CosmWasm/wasmvm/releases/download/${WASMVM_VERSION}"; \
wget ${WASMVM_DOWNLOADS}/checksums.txt -O /tmp/checksums.txt; \
if [ ${BUILDPLATFORM} = "linux/amd64" ]; then \
WASMVM_URL="${WASMVM_DOWNLOADS}/libwasmvm_muslc.x86_64.a"; \
elif [ ${BUILDPLATFORM} = "linux/arm64" ]; then \
WASMVM_URL="${WASMVM_DOWNLOADS}/libwasmvm_muslc.aarch64.a"; \
else \
echo "Unsupported Build Platfrom ${BUILDPLATFORM}"; \
exit 1; \
fi; \
wget ${WASMVM_URL} -O /lib/libwasmvm_muslc.a; \
CHECKSUM=`sha256sum /lib/libwasmvm_muslc.a | cut -d" " -f1`; \
grep ${CHECKSUM} /tmp/checksums.txt; \
rm /tmp/checksums.txt

WORKDIR /terra
###############################################################################

COPY --from=go-builder /code/build/terrad /usr/local/bin/terrad
FROM builder-stage-1 as builder-stage-2

USER terra
ARG source
ARG GOOS=linux \
GOARCH=amd64

ENV GOOS=$GOOS \
GOARCH=$GOARCH

# Copy the remaining files
COPY ${source} .

# Build app binary
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go install \
-mod=readonly \
-tags "netgo,muslc" \
-ldflags " \
-w -s -linkmode=external -extldflags \
'-L/go/src/mimalloc/build -lmimalloc -Wl,-z,muldefs -static' \
-X github.com/cosmos/cosmos-sdk/version.Name='terra' \
-X github.com/cosmos/cosmos-sdk/version.AppName='terrad' \
-X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \
-X github.com/cosmos/cosmos-sdk/version.Commit=${GIT_COMMIT} \
-X github.com/cosmos/cosmos-sdk/version.BuildTags='netgo,muslc' \
" \
-trimpath \
./...

################################################################################

FROM alpine:${ALPINE_VERSION} as terra-core

RUN apk update && apk add wget lz4 aria2 curl jq gawk coreutils "zlib>1.2.12-r2" "libssl1.1>1.1.1q-r0"

COPY --from=builder-stage-2 /go/bin/terrad /usr/local/bin/terrad

RUN addgroup -g 1000 terra && \
adduser -u 1000 -G terra -D -h /app terra

# rest server
EXPOSE 1317
# grpc
# grpc server
EXPOSE 9090
# tendermint p2p
EXPOSE 26656
# tendermint rpc
EXPOSE 26657

CMD ["/usr/local/bin/terrad", "version"]
WORKDIR /app

CMD ["terrad", "version"]
58 changes: 43 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SIMAPP = ./app
HTTPS_GIT := https://github.com/classic-terra/core.git
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
GO_VERSION ?= "1.20"
GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2)

#TESTNET PARAMETERS
TESTNET_NVAL := $(if $(TESTNET_NVAL),$(TESTNET_NVAL),7)
Expand Down Expand Up @@ -136,35 +136,66 @@ build-linux-with-shared-library:
docker cp temp:/lib/libwasmvm.so $(BUILDDIR)/
docker rm temp

build-release-amd64: go.sum $(BUILDDIR)/
build-release: build-release-amd64 build-release-arm64

build-release-amd64: go.sum
mkdir -p $(BUILDDIR)/release
$(DOCKER) buildx create --name core-builder || true
$(DOCKER) buildx use core-builder
$(DOCKER) buildx build \
--platform linux/amd64 \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg BUILDPLATFORM=linux/amd64 \
--build-arg GOOS=linux \
--build-arg GOARCH=amd64 \
-t core:local-amd64 \
--load \
-f Dockerfile .
$(DOCKER) rm -f core-builder || true
$(DOCKER) create -ti --name core-builder core:local-amd64
mkdir -p build/release
$(DOCKER) cp core-builder:/usr/local/bin/terrad $(BUILDDIR)/release/terrad
tar -czvf $(BUILDDIR)/release/terra_$(VERSION)_Linux_x86_64.tar.gz -C $(BUILDDIR)/release/ terrad
rm $(BUILDDIR)/release/terrad
$(DOCKER) rm -f core-builder

build-release-arm64: go.sum
mkdir -p $(BUILDDIR)/release
$(DOCKER) buildx create --name core-builder || true
$(DOCKER) buildx use core-builder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg BUILDPLATFORM=linux/arm64 \
--build-arg GOOS=linux \
--build-arg GOARCH=arm64 \
-t core:local-arm64 \
--load \
-f Dockerfile .
$(DOCKER) rm -f core-builder || true
$(DOCKER) create -ti --name core-builder core:local-arm64
$(DOCKER) cp core-builder:/usr/local/bin/terrad $(BUILDDIR)/release/terrad
tar -czvf $(BUILDDIR)/release/terra_$(VERSION)_Linux_arm64.tar.gz -C $(BUILDDIR)/release/ terrad
rm $(BUILDDIR)/release/terrad
$(DOCKER) rm -f core-builder

install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/terrad

update-swagger-docs: statik
$(BINDIR)/statik -src=client/docs/swagger-ui -dest=client/docs -f -m
docs:
@./scripts/protoc-swagger-gen.sh

@rm -f client/docs/statik/statik.go
@statik -src=client/docs/swagger-ui -dest=client/docs -f -m
@if [ -n "$(git status --porcelain)" ]; then \
echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
exit 1;\
else \
echo "\033[92mSwagger docs are in sync\033[0m";\
fi

.PHONY: build build-linux install update-swagger-docs
.PHONY: build build-linux install docs

########################################
### Tools & dependencies
Expand Down Expand Up @@ -220,10 +251,10 @@ benchmark:
###############################################################################

lint:
sudo golangci-lint run --out-format=tab
golangci-lint run --out-format=tab

lint-fix:
sudo golangci-lint run --fix --out-format=tab --issues-exit-code=0
golangci-lint run --fix --out-format=tab --issues-exit-code=0

lint-strict:
find . -path './_build' -prune -o -type f -name '*.go' -exec gofumpt -w -l {} +
Expand Down Expand Up @@ -254,17 +285,14 @@ proto-format:
@echo "Formatting Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${CONTAINER_PROTO_FMT}$$"; then docker start -a $(CONTAINER_PROTO_FMT); else docker run --name $(CONTAINER_PROTO_FMT) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/docker-build-proto \
find ./proto -name "*.proto" -exec clang-format -i {} \; ; fi

proto-swagger-gen:
@./scripts/protoc-swagger-gen.sh


proto-lint:
@$(DOCKER_BUF) lint --error-format=json

proto-check-breaking:
@$(DOCKER_BUF) breaking --against '$(HTTPS_GIT)#branch=main'

.PHONY: proto-all proto-gen proto-swagger-gen proto-format proto-lint proto-check-breaking
.PHONY: proto-all proto-gen proto-format proto-lint proto-check-breaking

###############################################################################
### Localnet ###
Expand Down Expand Up @@ -314,4 +342,4 @@ build-operator-img-node:
@if ! docker image inspect public.ecr.aws/classic-terra/core:${NODE_VERSION} &>/dev/null ; then make build-operator-img-core ; fi
docker-compose -f contrib/terra-operator/docker-compose.build.yml build node --no-cache

.PHONY: build-operator-img-all build-operator-img-core build-operator-img-node
.PHONY: build-operator-img-all build-operator-img-core build-operator-img-node
Loading

0 comments on commit 88ea162

Please sign in to comment.