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

plugin: support system-wide plugins #4244

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ PROTOC = protoc --gogo_out=. --proto_path=.:/usr/local/opt/protobuf/include:$(di
# enable second expansion
.SECONDEXPANSION:

include config.mk
include Rules.mk
11 changes: 6 additions & 5 deletions Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ help:
@echo ''
@echo 'BUILD TARGETS:'
@echo ''
@echo ' all - print this help message'
@echo ' build - Build binary at ./cmd/ipfs/ipfs'
@echo ' nofuse - Build binary with no fuse support'
@echo ' install - Build binary and install into $$GOPATH/bin'
# @echo ' dist_install - TODO: c.f. ./cmd/ipfs/dist/README.md'
@echo ' all - print this help message'
@echo ' build - Build binary at ./cmd/ipfs/ipfs'
@echo ' nofuse - Build binary with no fuse support'
@echo ' install - Build binary and install into $$GOPATH/bin'
# @echo ' dist_install - TODO: c.f. ./cmd/ipfs/dist/README.md'
@echo ' build_plugins - Build plugin binaries'
@echo ''
@echo 'CLEANING TARGETS:'
@echo ''
Expand Down
5 changes: 4 additions & 1 deletion cmd/ipfs/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ PATH := $(realpath $(d)):$(PATH)
# DEPS_OO_$(d) += merkledag/pb/merkledag.pb.go namesys/pb/namesys.pb.go
# DEPS_OO_$(d) += pin/internal/pb/header.pb.go unixfs/pb/unixfs.pb.go

$(d)_flags =-ldflags="-X "github.com/ipfs/go-ipfs/repo/config".CurrentCommit=$(shell git rev-parse --short HEAD)"
$(d)_flags =-ldflags="
$(d)_flags += -X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=${CONFIG_COMMIT}
$(d)_flags += -X github.com/ipfs/go-ipfs/repo/config.SystemPluginPath=${CONFIG_PLUGIN_PATH}
$(d)_flags += "

$(d)-try-build $(IPFS_BIN_$(d)): GOFLAGS += $(cmd/ipfs_flags)

Expand Down
11 changes: 8 additions & 3 deletions cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const (
type cmdInvocation struct {
req *cmds.Request
node *core.IpfsNode
ctx *oldcmds.Context
}

type exitErr int
Expand Down Expand Up @@ -181,19 +180,25 @@ func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) {
exctr = client.(cmds.Executor)
} else {
cctx := env.(*oldcmds.Context)
pluginpath := filepath.Join(cctx.ConfigRoot, "plugins")
pluginPath := filepath.Join(cctx.ConfigRoot, "plugins")

// check if repo is accessible before loading plugins
ok, err := checkPermissions(cctx.ConfigRoot)
if err != nil {
return nil, err
}
if ok {
if _, err := loader.LoadPlugins(pluginpath); err != nil {
if _, err := loader.LoadPlugins(pluginPath); err != nil {
log.Warning("error loading plugins: ", err)
}
}

if config.SystemPluginPath != "" {
if _, err := loader.LoadPlugins(config.SystemPluginPath); err != nil {
return nil, err
}
}

exctr = cmds.NewExecutor(req.Root)
}

Expand Down
2 changes: 2 additions & 0 deletions config.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_COMMIT := $(shell git rev-parse --short HEAD)
CONFIG_PLUGIN_PATH = ${PLUGIN_PATH}
3 changes: 3 additions & 0 deletions repo/config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package config
// CurrentCommit is the current git commit, this is set as a ldflag in the Makefile
var CurrentCommit string

// SystemPluginPath is the a system-global plugin path, this is set as a ldflag in the Makefile
var SystemPluginPath string

// CurrentVersionNumber is the current application's version literal
const CurrentVersionNumber = "0.4.14-dev"

Expand Down
7 changes: 5 additions & 2 deletions test/sharness/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ T_$(d) = $(sort $(wildcard $(d)/t[0-9][0-9][0-9][0-9]-*.sh))
DEPS_$(d) := test/bin/random test/bin/multihash test/bin/pollEndpoint \
test/bin/iptb test/bin/go-sleep test/bin/random-files \
test/bin/go-timeout test/bin/hang-fds test/bin/ma-pipe-unidir
DEPS_$(d) += cmd/ipfs/ipfs
DEPS_$(d) += $(d)/clean-test-results
DEPS_$(d) += $(SHARNESS_$(d))
DEPS_$(d) += $(d)/sharness-ipfs

ifeq ($(OS),Linux)
PLUGINS_DIR_$(d) := $(d)/plugins/
Expand Down Expand Up @@ -49,13 +49,16 @@ $(SHARNESS_$(d)): $(d) ALWAYS
$(d)/deps: $(SHARNESS_$(d)) $$(DEPS_$(d)) # use second expansion so coverage can inject dependency
.PHONY: $(d)/deps

$(d)/sharness-ipfs: PLUGIN_PATH=./system_plugins
$(d)/sharness-ipfs: cmd/ipfs/ipfs
.PHONY: $(d)/sharness-ipfs

test_sharness_deps: $(d)/deps
.PHONY: test_sharness_deps

test_sharness_short: $(d)/aggregate
.PHONY: test_sharness_short


test_sharness_expensive: export TEST_EXPENSIVE=1
test_sharness_expensive: test_sharness_short
.PHONY: test_sharness_expensive
Expand Down
32 changes: 27 additions & 5 deletions test/sharness/t0280-plugin-git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ fi

test_init_ipfs

test_expect_success "copy plugin" '
mkdir -p "$IPFS_PATH/plugins" &&
cp ../plugins/git.so "$IPFS_PATH/plugins/"
'

# from https://github.com/ipfs/go-ipld-git/blob/master/make-test-repo.sh
test_expect_success "prepare test data" '
tar xzf ../t0280-plugin-git-data/git.tar.gz
Expand All @@ -46,6 +41,33 @@ test_dag_git() {
'
}

test_expect_success "copy plugin to local plugin directory" '
mkdir -p "$IPFS_PATH/plugins" &&
chmod +x ../plugins/git.so &&
cp ../plugins/git.so "$IPFS_PATH/plugins/"
'

# should work offline
#test_dag_git

# should work online
test_launch_ipfs_daemon
test_dag_git
test_kill_ipfs_daemon

test_expect_success "copy plugin to global plugin directory" '
mkdir -p "./system_plugins" &&
cp ../plugins/git.so "./system_plugins/"
'

test_expect_success "fail with duplicate plugin" '
echo 123 | test_must_fail ipfs dag put
'

test_expect_success "remove local plugin" '
rm -r "$IPFS_PATH/plugins/"
'

# should work offline
#test_dag_git

Expand Down