Skip to content

Commit

Permalink
Merge pull request #39 from TRON-US/BTFS-1108
Browse files Browse the repository at this point in the history
BTFS-1108 Dockerfile to run make build and git diff protos dir
  • Loading branch information
wxue authored Dec 5, 2019
2 parents d543468 + acfbd57 commit 1ee5c0a
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM golang:1.13-stretch

MAINTAINER TRON-US <[email protected]>
# Dockerfile will build an image to run make build.

#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

# need to run trongogo before make build
RUN make trongogo build

# by default check protos dir for diffs
CMD make test_git_diff_protos
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
UNAME := $(shell uname)
default: lintf

TEST_DB_NAME ?= runtime
Expand Down Expand Up @@ -36,11 +37,20 @@ buildgo:
go build ./...

pgfix:
ifeq ($(UNAME), Linux)
for pb in $(PG_FIX_CANDIDATES); \
do \
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)
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

Expand All @@ -54,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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

14 changes: 14 additions & 0 deletions bin/test-git-diff-protos
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1ee5c0a

Please sign in to comment.