Skip to content
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

adding tests, Make file and interfaces #27

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
outputs
outputs

bin

.vscode
138 changes: 138 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
RUSTFLAGS="-C target-feature=+crt-static"

# Detect OS
OS := $(shell uname | tr "[:upper:]" "[:lower:]")
ARCH := $(shell uname -m | tr "[:upper:]" "[:lower:]")
GOPATH ?= $(shell go env GOPATH)
GOFLAGS ?= $(GOFLAGS:)
GO=go
GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
GO_OS = $(shell $(GO) version | cut -c 14- | cut -d' ' -f2 | cut -d'/' -f1 | tr "[:upper:]" "[:lower:]")
GO_ARCH = $(shell $(GO) version | cut -c 14- | cut -d' ' -f2 | cut -d'/' -f2 | tr "[:upper:]" "[:lower:]")

define GO_MISMATCH_ERROR

Your go binary does not match your architecture.
Go binary: $(GO_OS) - $(GO_ARCH)
Environment: $(OS) - $(ARCH)
GOPATH: $(GOPATH)

endef
export GO_MISMATCH_ERROR

all: go-arch-alignment build
.PHONY: all

build:
go build
.PHONY: build

go-arch-alignment:
mismatch =
ifeq ($(OS), darwin)
ifneq ($(ARCH), $(GO_ARCH))
mismatch = yes
endif
endif

ifdef mismatch
$(info $(GO_MISMATCH_ERROR))
$(error Please change your go binary)
endif
.PHONY: go-arch-alignment

all: build

# Run go fmt against code
fmt:
@${GO} fmt ./cmd/...


# Run go vet against code
vet:
@${GO} vet ./cmd/...

################################################################################
# Target: modtidy #
################################################################################
.PHONY: modtidy
modtidy:
go mod tidy

################################################################################
# Target: check-diff #
################################################################################
.PHONY: check-diff
check-diff:
git diff --exit-code ./go.mod # check no changes
git diff --exit-code ./go.sum # check no changes

## Run all pre-commit hooks
################################################################################
# Target: precommit #
################################################################################
.PHONY: precommit
precommit:
${PRECOMMIT} run --all

################################################################################
# Target: build #
################################################################################
.PHONY: build
build: build-bacalhau


################################################################################
# Target: build-bacalhau #
################################################################################
.PHONY: build-bacalhau
build-bacalhau: fmt vet
CGO_ENABLED=0 GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) ${GO} build -gcflags '-N -l' -ldflags "-X main.VERSION=$(TAG)" -o bin/$(ARCH)/bacalhau main.go
cp bin/$(ARCH)/bacalhau bin/bacalhau


################################################################################
# Target: clean #
################################################################################
.PHONY: clean
clean:
go clean


################################################################################
# Target: test #
################################################################################
.PHONY: test
test: build-bacalhau
go test ./test/... -v

################################################################################
# Target: lint #
################################################################################
.PHONY: lint
lint: build-bacalhau
golangci-lint run --timeout 10m

# Run the unittests and output a junit report for use with prow
################################################################################
# Target: test-junit #
################################################################################
.PHONY: test-junit
test-junit: build-bacalhau
echo Running tests ... junit_file=$(JUNIT_FILE)
go test ./... -v 2>&1 | go-junit-report > $(JUNIT_FILE) --set-exit-code

.PHONY: generate
generate:
CGO_ENABLED=0 GOARCH=$(shell go env GOARCH) ${GO} generate -gcflags '-N -l' -ldflags "-X main.VERSION=$(TAG)" ./...
echo "[OK] Files added to pipeline template directory!"

.PHONY: security
security:
gosec -exclude=G204,G304 -exclude-dir=test ./...
echo "[OK] Go security check was completed!"

release:
echo "Executing 'make release'"
# NOOP
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# Bacalhau - The Filecoin Distributed Computation Framework

## demo!
## demo

https://user-images.githubusercontent.com/264658/152514573-b7b115ce-4123-486c-983a-8e26acf4b86d.mp4
<https://user-images.githubusercontent.com/264658/152514573-b7b115ce-4123-486c-983a-8e26acf4b86d.mp4>

## running locally

### requirements

* linux
* go >= 1.16
* [ignite](https://ignite.readthedocs.io/en/stable/installation/)
* linux
* go >= 1.16 (<https://go.dev/doc/install>)
* [ignite](https://ignite.readthedocs.io/en/stable/installation/)

### start compute nodes

The first

Have a few terminal windows.

This starts the first compute node listening on port 8080 so we can connect to a known port.
Expand Down
12 changes: 6 additions & 6 deletions cmd/bacalhau/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ var jsonrpcPort int
var developmentMode bool

func init() {
rootCmd.AddCommand(serveCmd)
rootCmd.AddCommand(submitCmd)
rootCmd.PersistentFlags().IntVar(
RootCmd.AddCommand(ServeCmd)
RootCmd.AddCommand(submitCmd)
RootCmd.PersistentFlags().IntVar(
&jsonrpcPort, "jsonrpc-port", 1234,
`The port for the client and server to communicate on over localhost (via jsonrpc).`,
)
rootCmd.PersistentFlags().BoolVar(
RootCmd.PersistentFlags().BoolVar(
&developmentMode, "dev", false,
`Development mode makes it easier to run multiple bacalhau nodes on the same machine.`,
)
}

var rootCmd = &cobra.Command{
var RootCmd = &cobra.Command{
Use: "bacalhau",
Short: "Compute over data",
Long: `Compute over data`,
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
if err := RootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
Expand Down
16 changes: 11 additions & 5 deletions cmd/bacalhau/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"

"github.com/filecoin-project/bacalhau/internal"
"github.com/filecoin-project/bacalhau/pkg/networker"
"github.com/phayes/freeport"
"github.com/spf13/cobra"
)
Expand All @@ -15,21 +16,21 @@ var hostAddress string
var hostPort int

func init() {
serveCmd.PersistentFlags().StringVar(
ServeCmd.PersistentFlags().StringVar(
&peerConnect, "peer", "",
`The libp2p multiaddress to connect to.`,
)
serveCmd.PersistentFlags().StringVar(
ServeCmd.PersistentFlags().StringVar(
&hostAddress, "host", "127.0.0.1",
`The port to listen on.`,
)
serveCmd.PersistentFlags().IntVar(
ServeCmd.PersistentFlags().IntVar(
&hostPort, "port", 0,
`The port to listen on.`,
)
}

var serveCmd = &cobra.Command{
var ServeCmd = &cobra.Command{
Use: "serve",
Short: "Start the bacalhau compute node",
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -63,10 +64,15 @@ Command to connect other peers:
go run . serve --peer /ip4/%s/tcp/%d/p2p/%s%s%s

`, hostAddress, hostPort, computeNode.Host.ID(), jsonRpcString, devString)
i := networker.GetNetworker(cmd, args)

// run the jsonrpc server, passing it a reference to the pubsub topic so
// that the CLI can also send messages to the chat room
internal.RunBacalhauRpcServer(hostAddress, jsonrpcPort, computeNode)
err = i.RunBacalhauRpcServer(hostAddress, jsonrpcPort, computeNode)

if err != nil {
return err
}

return nil

Expand Down
Empty file added experimental/.keep
Empty file.
17 changes: 17 additions & 0 deletions experimental/sample.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// THIS FILE IS NOT FOR PRODUCTION USE OR INCLUSION IN ANY PACKAGE
// It is a convient place to add libraries from the rest of the

package bacalhau

import (
"crypto/rand"
"fmt"
"math/big"
)


func bacalhau() {
// ...
r, _ := rand.Int(rand.Reader, big.NewInt(10))
fmt.Printf("Test: %v", r)
}
Loading