From 6c4dcb37d18a25ed29b1e0f478bed5493cf7d730 Mon Sep 17 00:00:00 2001 From: bestmike007 Date: Fri, 13 Oct 2023 05:05:41 +0000 Subject: [PATCH 1/7] feat: use asdf to pin toolchain versions Signed-off-by: bestmike007 --- .tool-versions | 4 ++++ README.md | 7 +++---- scripts/bootstrap.sh | 26 +++++++++++++++++++++++--- scripts/precheck.sh | 6 ++++++ 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..65247f0 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,4 @@ +golang 1.21.3 +protoc 24.4 +yq 4.35.2 +grpcurl 1.8.8 diff --git a/README.md b/README.md index ce11cee..b95c013 100644 --- a/README.md +++ b/README.md @@ -48,17 +48,16 @@ It aims to provide an efficient and flexible way to access the on-chain data: ## Quick Start -Make sure your local go version is 1.18 by running the following commands: +If you're not using [asdf](https://asdf-vm.com/), then make sure your local go version is 1.21.3 by running the following commands: ```shell -brew install go@1.18 +brew install go@1.21.3 brew unlink go -brew link go@1.18 +brew link go@1.21.3 brew install protobuf@3.21.12 brew unlink protobuf brew link protobuf - ``` To set up for the first time (only done once): diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 66f05a0..7218861 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -2,12 +2,28 @@ set -exo pipefail -source ./scripts/precheck.sh - +# Use asdf if it's available +if [ -x "$(command -v asdf)" ]; then + if ! asdf plugin-list | grep -e '^golang$' &> /dev/null; then + asdf plugin add golang https://github.com/asdf-community/asdf-golang.git + fi + if ! asdf plugin-list | grep -e '^yq$' &> /dev/null; then + asdf plugin-add yq https://github.com/beardix/asdf-yq.git + fi + if ! asdf plugin-list | grep -e '^protoc$' &> /dev/null; then + asdf plugin-add protoc https://github.com/paxosglobal/asdf-protoc.git + fi + if ! asdf plugin-list | grep -e '^grpcurl$' &> /dev/null; then + asdf plugin-add grpcurl https://github.com/asdf-community/asdf-grpcurl.git + fi + asdf install +else + source ./scripts/precheck.sh + go install github.com/mikefarah/yq/v4@v4.35.2 +fi go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31.0 go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0 -go install github.com/mikefarah/yq/v4@v4.35.2 go install github.com/golang/mock/mockgen@v1.6.0 go install github.com/gordonklaus/ineffassign@v0.0.0-20230610083614-0e73809eb601 go install github.com/kisielk/errcheck@v1.6.3 @@ -15,3 +31,7 @@ go install github.com/go-bindata/go-bindata/go-bindata@v3.1.2 go install golang.org/x/tools/cmd/goimports@v0.13.0 go mod download go mod tidy + +if [ -x "$(command -v asdf)" ]; then + asdf reshim +fi diff --git a/scripts/precheck.sh b/scripts/precheck.sh index 577bc15..cfa1acc 100755 --- a/scripts/precheck.sh +++ b/scripts/precheck.sh @@ -2,6 +2,12 @@ set -eo pipefail +# Check if golang is installed +if ! [ -x "$(command -v go)" ]; then + echo 'Error: go is not installed. Please refer https://golang.org/ for installation instruction' >&2 + exit 1 +fi + # Check if protobuf is installed if ! [ -x "$(command -v protoc)" ]; then echo 'Error: protobuf is not installed. Please refer https://grpc.io/docs/protoc-installation/ for installation instruction' >&2 From 8df31e3968db8eda1e3332f04b94920da936cc41 Mon Sep 17 00:00:00 2001 From: bestmike007 Date: Fri, 13 Oct 2023 05:09:05 +0000 Subject: [PATCH 2/7] chore: use go 1.21 Signed-off-by: bestmike007 --- Dockerfile | 4 ++-- go.mod | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8df0ec1..c1f4e4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.18 as build +FROM golang:1.21 as build ENV GO111MODULE on @@ -11,7 +11,7 @@ RUN go mod download COPY . ./ RUN make bin -FROM golang:1.18 as deploy +FROM golang:1.21 as deploy WORKDIR /app/ diff --git a/go.mod b/go.mod index d424cdd..96b4d65 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/coinbase/chainstorage -go 1.18 +go 1.21 require ( github.com/VividCortex/ewma v1.2.0 From f74fea50f88d1e88833dd33fd241a44d531e04a8 Mon Sep 17 00:00:00 2001 From: bestmike007 Date: Fri, 13 Oct 2023 05:13:24 +0000 Subject: [PATCH 3/7] chore: use another yq plugin Signed-off-by: bestmike007 --- scripts/bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 7218861..32f8efc 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -8,7 +8,7 @@ if [ -x "$(command -v asdf)" ]; then asdf plugin add golang https://github.com/asdf-community/asdf-golang.git fi if ! asdf plugin-list | grep -e '^yq$' &> /dev/null; then - asdf plugin-add yq https://github.com/beardix/asdf-yq.git + asdf plugin-add yq https://github.com/sudermanjr/asdf-yq.git fi if ! asdf plugin-list | grep -e '^protoc$' &> /dev/null; then asdf plugin-add protoc https://github.com/paxosglobal/asdf-protoc.git From 9b0bd6821d83ee16226b32b44c470bc7e9b3b2bb Mon Sep 17 00:00:00 2001 From: bestmike007 Date: Fri, 13 Oct 2023 05:16:51 +0000 Subject: [PATCH 4/7] chore: use asdf to install golang only if it's unavailable Signed-off-by: bestmike007 --- scripts/bootstrap.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 32f8efc..dc2a06a 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -4,8 +4,10 @@ set -exo pipefail # Use asdf if it's available if [ -x "$(command -v asdf)" ]; then - if ! asdf plugin-list | grep -e '^golang$' &> /dev/null; then - asdf plugin add golang https://github.com/asdf-community/asdf-golang.git + if ! [ -x "$(command -v go)" ]; then + if ! asdf plugin-list | grep -e '^golang$' &> /dev/null; then + asdf plugin add golang https://github.com/asdf-community/asdf-golang.git + fi fi if ! asdf plugin-list | grep -e '^yq$' &> /dev/null; then asdf plugin-add yq https://github.com/sudermanjr/asdf-yq.git From 04fae65e5ff1406191efd896bc119646502bf8a5 Mon Sep 17 00:00:00 2001 From: bestmike007 Date: Fri, 13 Oct 2023 05:17:31 +0000 Subject: [PATCH 5/7] chore: no need to install protoc in CI anymore Signed-off-by: bestmike007 --- .github/workflows/setup/action.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/setup/action.yaml b/.github/workflows/setup/action.yaml index 4e4f457..85914d7 100644 --- a/.github/workflows/setup/action.yaml +++ b/.github/workflows/setup/action.yaml @@ -11,8 +11,4 @@ runs: uses: asdf-vm/actions/setup@v2 - name: Setup shell: bash - run: | - asdf plugin-add protoc https://github.com/paxosglobal/asdf-protoc.git - asdf install protoc 24.4 - asdf global protoc 24.4 - make bootstrap + run: make bootstrap From dbe78c0a42640bf88b9a50b123c25d4cc7300867 Mon Sep 17 00:00:00 2001 From: bestmike007 Date: Fri, 13 Oct 2023 05:20:11 +0000 Subject: [PATCH 6/7] chore: use asdf to install golang only if it's unavailable Signed-off-by: bestmike007 --- .tool-versions | 1 - scripts/bootstrap.sh | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.tool-versions b/.tool-versions index 65247f0..52039c4 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,4 +1,3 @@ -golang 1.21.3 protoc 24.4 yq 4.35.2 grpcurl 1.8.8 diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index dc2a06a..692f675 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -7,6 +7,8 @@ if [ -x "$(command -v asdf)" ]; then if ! [ -x "$(command -v go)" ]; then if ! asdf plugin-list | grep -e '^golang$' &> /dev/null; then asdf plugin add golang https://github.com/asdf-community/asdf-golang.git + asdf install golang 1.21.3 + asdf global golang 1.21.3 fi fi if ! asdf plugin-list | grep -e '^yq$' &> /dev/null; then From ee75d7bd11d25194a0510d85f2f4070249a3e51f Mon Sep 17 00:00:00 2001 From: bestmike007 Date: Sat, 21 Oct 2023 07:39:30 +0000 Subject: [PATCH 7/7] chore: use go 1.20 Signed-off-by: bestmike007 --- .github/workflows/setup/action.yaml | 2 +- Dockerfile | 4 ++-- README.md | 6 +++--- go.mod | 2 +- scripts/bootstrap.sh | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/setup/action.yaml b/.github/workflows/setup/action.yaml index 85914d7..3320363 100644 --- a/.github/workflows/setup/action.yaml +++ b/.github/workflows/setup/action.yaml @@ -6,7 +6,7 @@ runs: - name: Set up go uses: actions/setup-go@v4 with: - go-version: 1.21.3 + go-version: 1.20.10 - name: Install asdf & tools uses: asdf-vm/actions/setup@v2 - name: Setup diff --git a/Dockerfile b/Dockerfile index c1f4e4d..b81b9fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21 as build +FROM golang:1.20 as build ENV GO111MODULE on @@ -11,7 +11,7 @@ RUN go mod download COPY . ./ RUN make bin -FROM golang:1.21 as deploy +FROM golang:1.20 as deploy WORKDIR /app/ diff --git a/README.md b/README.md index b95c013..b96f3b3 100644 --- a/README.md +++ b/README.md @@ -48,12 +48,12 @@ It aims to provide an efficient and flexible way to access the on-chain data: ## Quick Start -If you're not using [asdf](https://asdf-vm.com/), then make sure your local go version is 1.21.3 by running the following commands: +If you're not using [asdf](https://asdf-vm.com/), then make sure your local go version is 1.20+ by running the following commands: ```shell -brew install go@1.21.3 +brew install go@1.20.10 brew unlink go -brew link go@1.21.3 +brew link go@1.20.10 brew install protobuf@3.21.12 brew unlink protobuf diff --git a/go.mod b/go.mod index 96b4d65..73d23e9 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/coinbase/chainstorage -go 1.21 +go 1.20 require ( github.com/VividCortex/ewma v1.2.0 diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 692f675..58baf62 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -7,8 +7,8 @@ if [ -x "$(command -v asdf)" ]; then if ! [ -x "$(command -v go)" ]; then if ! asdf plugin-list | grep -e '^golang$' &> /dev/null; then asdf plugin add golang https://github.com/asdf-community/asdf-golang.git - asdf install golang 1.21.3 - asdf global golang 1.21.3 + asdf install golang 1.20.10 + asdf global golang 1.20.10 fi fi if ! asdf plugin-list | grep -e '^yq$' &> /dev/null; then