From 8cbd7b72410061a7ce06c25d747aa281f6d05916 Mon Sep 17 00:00:00 2001 From: richard lee Date: Wed, 27 Nov 2019 14:35:03 -0800 Subject: [PATCH 1/4] BTFS-1108 Dockerfile to build repo and check for errors --- Dockerfile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6da98b6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ +FROM golang:1.13-stretch + +MAINTAINER TRON-US +# Dockerfile.unit_testing will build an image to run the go unit tests. +# Use the regular Dockerfile to run a btfs daemon instead + +#ENV PATH="/go/bin:${PATH}" + +ENV PROTOC_VERSION=3.10.0 +ENV GOLANG_PROTOBUF_VERSION=1.3.2 +ENV PROTOTOOL_VERSION=1.9.0 + + +# Install patch +RUN apt-get update && apt-get install -y patch + +RUN apt-get install -y unzip + +# install standard c++ implementation of protocol buffers +RUN wget --quiet https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip +RUN unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip -d protoc3 +RUN mv protoc3/bin/* /usr/local/bin/ +RUN mv protoc3/include/* /usr/local/include + +# install golang proto package +RUN GO111MODULE=on go get \ + github.com/golang/protobuf/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} && \ + mv /go/bin/protoc-gen-go* /usr/local/bin/ + +# install prototool +RUN wget --quiet https://github.com/uber/prototool/releases/download/v${PROTOTOOL_VERSION}/prototool-Linux-x86_64.tar.gz +RUN tar -xf prototool-Linux-x86_64.tar.gz +RUN mv prototool/bin/prototool /usr/local/bin/prototool + +ENV SRC_DIR /go/src/github.com/tron-us/go-btfs-common + +# Download packages first so they can be cached. +COPY go.mod go.sum $SRC_DIR/ +RUN cd $SRC_DIR \ + && go mod download + +COPY . $SRC_DIR + +#WORKDIR /go-btfs-common +WORKDIR $SRC_DIR + +# by default lets run the go fmt, tidy and unit tests +CMD make trongogo build From 561b438338bce3b67c627612cfd09a0681128b6b Mon Sep 17 00:00:00 2001 From: richard lee Date: Mon, 2 Dec 2019 13:08:59 -0800 Subject: [PATCH 2/4] BTFS-1108 Makefile to work with sed on linux --- Dockerfile | 6 ++---- Makefile | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6da98b6..996a2b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,7 @@ FROM golang:1.13-stretch MAINTAINER TRON-US -# Dockerfile.unit_testing will build an image to run the go unit tests. -# Use the regular Dockerfile to run a btfs daemon instead +# Dockerfile will build an image to run make build. #ENV PATH="/go/bin:${PATH}" @@ -10,7 +9,6 @@ ENV PROTOC_VERSION=3.10.0 ENV GOLANG_PROTOBUF_VERSION=1.3.2 ENV PROTOTOOL_VERSION=1.9.0 - # Install patch RUN apt-get update && apt-get install -y patch @@ -44,5 +42,5 @@ COPY . $SRC_DIR #WORKDIR /go-btfs-common WORKDIR $SRC_DIR -# by default lets run the go fmt, tidy and unit tests +# need to run trongogo before make build CMD make trongogo build diff --git a/Makefile b/Makefile index 03fbb3b..c7ecbf9 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +UNAME := $(shell uname) default: lintf TEST_DB_NAME ?= runtime @@ -41,11 +42,20 @@ buildgo: go build ./... pgfix: +ifeq ($(UNAME), Linux) + for pb in $(PG_FIX_CANDIDATES); \ + do \ + sed -ne 's/TableName/tableName/g' $$pb; \ + sed -ne 's/protobuf:"bytes,[0-9]*,opt,name=table_name,json=tableName,proto[0-9]*" json:"table_name,omitempty" pg:"table_name" //g' $$pb; \ + done +endif +ifeq ($(UNAME), Darwin) for pb in $(PG_FIX_CANDIDATES); \ do \ sed -i '' -e 's/TableName/tableName/g' $$pb; \ sed -i '' -e 's/protobuf:"bytes,[0-9]*,opt,name=table_name,json=tableName,proto[0-9]*" json:"table_name,omitempty" pg:"table_name" //g' $$pb; \ done +endif build: lintf genproto buildgo pgfix From ff337cf9a2f6490ca8f38cf91cdb7a19e0afacf6 Mon Sep 17 00:00:00 2001 From: richard lee Date: Mon, 2 Dec 2019 15:10:31 -0800 Subject: [PATCH 3/4] BTFS-1108 add make script for git diff protos --- Dockerfile | 5 ++++- Makefile | 7 +++++-- bin/test-git-diff-protos | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100755 bin/test-git-diff-protos diff --git a/Dockerfile b/Dockerfile index 996a2b1..e6e8140 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,4 +43,7 @@ COPY . $SRC_DIR WORKDIR $SRC_DIR # need to run trongogo before make build -CMD make trongogo build +RUN make trongogo build + +# by default check protos dir for diffs +CMD make test_git_diff_protos diff --git a/Makefile b/Makefile index 2c34bb6..0d8f23f 100644 --- a/Makefile +++ b/Makefile @@ -40,8 +40,8 @@ pgfix: ifeq ($(UNAME), Linux) for pb in $(PG_FIX_CANDIDATES); \ do \ - sed -ne 's/TableName/tableName/g' $$pb; \ - sed -ne 's/protobuf:"bytes,[0-9]*,opt,name=table_name,json=tableName,proto[0-9]*" json:"table_name,omitempty" pg:"table_name" //g' $$pb; \ + sed -in 's/TableName/tableName/g' $$pb; \ + sed -in 's/protobuf:"bytes,[0-9]*,opt,name=table_name,json=tableName,proto[0-9]*" json:"table_name,omitempty" pg:"table_name" //g' $$pb; \ done endif ifeq ($(UNAME), Darwin) @@ -64,3 +64,6 @@ test: brew services stop postgresql brew services stop redis +test_git_diff_protos: + bin/test-git-diff-protos +.PHONY: test_git_dif_protos diff --git a/bin/test-git-diff-protos b/bin/test-git-diff-protos new file mode 100755 index 0000000..f3f673a --- /dev/null +++ b/bin/test-git-diff-protos @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail +git --no-pager diff protos/ >> diffs.txt +if [ -n "$(cat diffs.txt)" ]; then + echo "The following protos have changed." + echo "-----------------------------------" + cat diffs.txt + echo "-----------------------------------" + echo "Please regenerate code so protos are consistent with Master." + rm -f diffs.txt + exit 1 +fi +rm -f diffs.txt + From 0b868ef73675fc84d6080278a169ad359b9a5821 Mon Sep 17 00:00:00 2001 From: richard lee Date: Tue, 3 Dec 2019 14:38:59 -0800 Subject: [PATCH 4/4] BTFS-1108 add docker commands in README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 8cf6088..10b350f 100644 --- a/README.md +++ b/README.md @@ -85,3 +85,18 @@ make lintf ``` make build ``` + +## Use docker container to run 'git diff protos/' + +``` +$ docker build -f Dockerfile -t "go-btfs-common" . +$ docker run -i go-btfs-common +``` + +## Run interactive bash inside docker container for diagnosis + +``` +$ docker build -f Dockerfile -t "go-btfs-common" . +$ docker run -it go-btfs-common /bin/bash +``` +