Skip to content

672 makefile binary built #678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,16 @@ jobs:
- /go/pkg/mod
test:
<<: *defaults
environment:
- GOLANGCI_LINT: 1.20.0
steps:
- checkout
- restore_cache:
key: gopkg-{{ .Branch }}-{{ checksum "go.sum" }}
- run:
name: ↓ GOLANGCI-LINT
command: |
curl -sfL https://github.com/raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v${GOLANGCI_LINT}
- run:
name: ↓ GOLINT
command: go get -u golang.org/x/lint/golint
- run:
name: TEST
command: go test `go list ./... | egrep -v 'common/model|common/service'` --short
- run:
name: GO FMT
command: go fmt `go list ./... | egrep -v 'common/model|common/service|vendor'`
- run:
name: GOLANGCI-LINT RUN
command: golangci-lint run
name: GO Test
command: make test
- run:
name: GOLINT RUN
command: golint `go list ./... | egrep -v 'vendor|common/model|common/service'`
Expand Down Expand Up @@ -81,7 +69,7 @@ jobs:
name: BUILD
command: |
go build -o ./dist/zoobc
# rsync -va --exclude='*.db' ./resource ./dist
# rsync -va --exclude='*.db' ./resource ./dist
- save_cache:
key: build-cache-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
paths:
Expand Down Expand Up @@ -169,4 +157,4 @@ workflows:
- build
filters:
branches:
only: staging
only: staging
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ cmd/*.new
accounts.txt
.editorconfig
.manual
release/
github.token
79 changes: 79 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
BIN_DIR := $(GOPATH)/bin
GOLANGCILINT := $(BIN_DIR)/golangci-lint
GOLANGCILINT_VERSION := v1.20.0
XGO := $(BIN_DIR)/xgo
VERSION ?= latest
BINARY_CORE := zoobc
BINARY_CLI := zoomd
GITHUB_TOKEN ?= $(shell cat github.token)

.PHONY: test
test: go-fmt golangci-lint
$(info running unit tests...)
go test `go list ./... | egrep -v 'common/model|common/service'` --short

$(GOLANGCILINT):
$(info fetching golangci-lint...)
curl -sSfL https://github.com/raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin $(GOLANGCILINT_VERSION)

$(XGO):
$(info fetching zoobc/xgo...)
go get github.com/zoobc/xgo

.PHONY: golangci-lint
golangci-lint: $(GOLANGCILINT)
$(info running linter...)
golangci-lint run

.PHONY: go-fmt
go-fmt:
$(info running go-fmt...)
go fmt `go list ./... | egrep -v 'common/model|common/service|vendor'`

.PHONY: build
build:
$(info build core with host os as target...)
mkdir -p release
go build -o release/$(BINARY_CORE)-$(VERSION)

.PHONY: core-linux
core-linux: $(XGO)
$(info build core with linux as target...)
mkdir -p release
xgo --targets=linux/amd64 -out=release/$(BINARY_CORE)-$(VERSION) --go-private=github.com/zoobc/* --github-token=$(GITHUB_TOKEN) ./

.PHONY: core-windows
core-windows: $(XGO)
$(info build core with windows as target...)
mkdir -p release
xgo --targets=windows/* -out=release/$(BINARY_CORE)-$(VERSION) --go-private=github.com/zoobc/* --github-token=$(GITHUB_TOKEN) ./

.PHONY: core-darwin
core-darwin: $(XGO)
$(info build core with darwin/macos as target...)
mkdir -p release
xgo --targets=darwin/* -out=release/$(BINARY_CORE)-$(VERSION) --go-private=github.com/zoobc/* --github-token=$(GITHUB_TOKEN) ./

.PHONY: cmd-darwin
cmd-darwin: $(XGO)
$(info build cmd with darwin/macos as target...)
mkdir -p cmd/release
xgo --targets=darwin/* -out=cmd/release/$(BINARY_CORE)-$(VERSION) --go-private=github.com/zoobc/* --github-token=$(GITHUB_TOKEN) ./cmd/

.PHONY: cmd-linux
cmd-linux: $(XGO)
$(info build cmd with linux as target...)
mkdir -p release
xgo --targets=linux/amd64 -out=cmd/release/$(BINARY_CORE)-$(VERSION) --go-private=github.com/zoobc/* --github-token=$(GITHUB_TOKEN) ./

.PHONY: cmd-windows
cmd-windows: $(XGO)
$(info build cmd with windows as target...)
mkdir -p release
xgo --targets=windows/* -out=cmd/release/$(BINARY_CORE)-$(VERSION) --go-private=github.com/zoobc/* --github-token=$(GITHUB_TOKEN) ./

.PHONY: release-core
release-core: core-linux

.PHONY: release-cmd
release-cmd: cmd-linux
1 change: 1 addition & 0 deletions github.token.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
your-github-token-here
133 changes: 89 additions & 44 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,69 +12,114 @@
</a>
</p>

>Zoobc-core is the main node application to run the zoobc blockchain. This repository consist of the main node application and the `command line interface` tools to help with development, which is located in the `cmd/` directory.
> Zoobc-core is the main node application to run the zoobc blockchain. This repository consist of the main node application and the `command line interface` tools to help with development, which is located in the `cmd/` directory.

Table of Contents:
- [Environments](#environments)
- [Install](#install)
- [Build](#build)
- [Run](#run)
- [Tests](#tests)
- [Swagger](#swagger)
- [Contributing](#contributing)
- [GRPC web proxy for browser](#grpc-web-proxy-for-browser)

- [Environments](#environments)
- [Install](#install)
- [Build](#build)
- [Run](#run)
- [Tests](#tests)
- [Swagger](#swagger)
- [Contributing](#contributing)
- [GRPC web proxy for browser](#grpc-web-proxy-for-browser)

### Environments
- [golang](https://golang.org/doc/install), currently using go.1.14
- [go-swagger](https://github.com/go-swagger/go-swagger) optional. Used as tools to document the rpc endpoint.
- [gopherbadger](https://github.com/jpoles1/gopherbadger) optional. Used to calculate total test coverage.
- [protoc](https://github.com/protocolbuffers/protobuf), optional as we are pushing the generated go file to the repo.
- [protoc-gen-go](https://github.com/golang/protobuf), optional as we are pushing the generated go file to the repo.

- [golang](https://golang.org/doc/install), currently using go.1.14
- [go-swagger](https://github.com/go-swagger/go-swagger) optional. Used as tools to document the rpc endpoint.
- [gopherbadger](https://github.com/jpoles1/gopherbadger) optional. Used to calculate total test coverage.
- [protoc](https://github.com/protocolbuffers/protobuf), optional as we are pushing the generated go file to the repo.
- [protoc-gen-go](https://github.com/golang/protobuf), optional as we are pushing the generated go file to the repo.
- [golangci-lint](https://github.com/golangci/golangci-lint) lint tools we used to keep the code clean and well structured.

### Install
- clone the repository.
- Dep user: run `dep ensure -v --vendor-only` to install the dependencies read from Gopkg.toml only.
- Go mod user: `go mod download` to generate vendor directory which is should download the packages from `Gopkg.toml` or read from project recursively
- run `git submodule update --init --recursive --remote` to update / fetch submodule.

VSCode go modules support with this config:
- clone the repository.
- Dep user: run `dep ensure -v --vendor-only` to install the dependencies read from Gopkg.toml only.
- Go mod user: `go mod download` to generate vendor directory which is should download the packages from `Gopkg.toml` or read from project recursively
- run `git submodule update --init --recursive --remote` to update / fetch submodule.
- run `make test` to run the test and linter.
VSCode go modules support with this config:

```json
"go.useLanguageServer": true
```

### Build
`go build -o zoobc`

To make use of the `Makefile` please rename `github.token.example` to `github.token` and place your github token there. This is required since we are accessing private repository for one of our dependencies.

- Core

note: For cross compilation please install and activate docker.

For:

- host: `go build -o zoobc`
- darwin: `make VERSION=v1.10.1 core-darwin`
- linux (386 & amd64): `make VERSION=v1.10.1 core-linux`
- windows (32 & 64bit): `make VERSION=v1.10.1 core-windows`

- CMD

For:

- host: `go build -o zoobc`
- darwin: `make VERSION=v1.10.1 cmd-darwin`
- linux (386 & amd64): `make VERSION=v1.10.1 cmd-linux`
- windows (32 & 64bit): `make VERSION=v1.10.1 cmd-windows`

### Run
>If already build, just run the binary

> If already build, just run the binary

```bash
./zoobc
```
>Main node application run manually
```bash
go run main.go
```
- Flags:
1. `debug` (bool): enters debug mode with capabilities like `prometheus monitoring` (uses port defined by `monitoringPort` in the config file).
2. `config-postfix` (string): defines which config file with defined postfix to use. It will use the config file in `./resource/config{postfix}`.toml.
3. `config-path` (string): defines the directory that will hold the resources and configs. by default it will use `./resource`. This will be useful particularly for robust resource placements, for example while used in Zoobc-Testing-Framework.
- Command line tools
```bash
cd cmd
go run main.go --help
go run main.go tx generate -t registerNode
```
for more detail check this out [cmd session](https://github.com/zoobc/zoobc-core/tree/develop/cmd)

> Main node application run manually

```bash
go run main.go
```

- Flags:
1. `debug` (bool): enters debug mode with capabilities like `prometheus monitoring` (uses port defined by `monitoringPort` in the config file).
2. `config-postfix` (string): defines which config file with defined postfix to use. It will use the config file in `./resource/config{postfix}`.toml.
3. `config-path` (string): defines the directory that will hold the resources and configs. by default it will use `./resource`. This will be useful particularly for robust resource placements, for example while used in Zoobc-Testing-Framework.
- Command line tools
```bash
cd cmd
go run main.go --help
go run main.go tx generate -t registerNode
```
for more detail check this out [cmd session](https://github.com/zoobc/zoobc-core/tree/develop/cmd)

### Tests
- #### Unit tests
- run all tests without cache `go test ./... -count=1`
- run all test with coverage report `go test ./... -coverprofile=cover.out && go tool cover -html=cover.out`
- #### Linter
- run `golangci-lint run` to check any linting error in the changes.
- remember to run tests, and lint before submitting PR.

- #### Unit tests
- run all tests without cache `go test ./... -count=1`
- run all test with coverage report `go test ./... -coverprofile=cover.out && go tool cover -html=cover.out`
- #### Linter
- install linter tools `curl -sSfL https://github.com/raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.20.0`
- run `golangci-lint run` to check any linting error in the changes.
- remember to run tests, and lint before submitting PR.

### Swagger
- install
- pull newest `schema` and run `./compile-go.sh` to recompile the go file and produce swagger definition from it.

- install
- pull newest `schema` and run `./compile-go.sh` to recompile the go file and produce swagger definition from it.

### Contributing

please refer to [contribute.md](contribute.md) and [code of conduct](code_of_conduct.md).

### GRPC web proxy for browser

[GRPC Web Proxy](https://github.com/improbable-eng/grpc-web/tree/master/go/grpcwebproxy)

```
nohup grpcwebproxy --backend_addr=localhost:7000 --run_tls_server=false --allow_all_origins --server_http_debug_port=7001 --server_http_max_write_timeout 1h &
```