Skip to content
This repository has been archived by the owner on Feb 12, 2019. It is now read-only.

Commit

Permalink
allow setting server addrs for the GRH and GitHandler; Dockerfile cha…
Browse files Browse the repository at this point in the history
…nges (#1236)
  • Loading branch information
songgao committed Oct 5, 2017
1 parent 7bae51f commit faa10d4
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 22 deletions.
7 changes: 4 additions & 3 deletions kbfsfuse/Dockerfile → Dockerfile
Expand Up @@ -11,6 +11,7 @@ ENV KEYBASE_TEST_ROOT_CERT_PEM=$KEYBASE_TEST_ROOT_CERT_PEM \

ENTRYPOINT ["kbfsfuse.sh"]

ADD kbfsfuse.sh /home/keybase/
ADD kbfsfuse /home/keybase/
ADD revision /home/keybase/kbfs_revision
ADD kbfsfuse/kbfsfuse.sh /home/keybase/
ADD kbfsfuse/kbfsfuse /home/keybase/
ADD kbfsgit/git-remote-keybase/git-remote-keybase /home/keybase/
ADD kbfsfuse/revision /home/keybase/kbfs_revision
4 changes: 3 additions & 1 deletion Jenkinsfile
Expand Up @@ -154,11 +154,13 @@ helpers.rootLinuxNode(env, {
// Install kbfsfuse first so we can start on dockerizing.
sh "go install github.com/keybase/kbfs/kbfsfuse"
sh "cp ${env.GOPATH}/bin/kbfsfuse ./kbfsfuse/kbfsfuse"
sh "go install github.com/keybase/kbfs/kbfsgit/git-remote-keybase"
sh "cp ${env.GOPATH}/bin/git-remote-keybase ./kbfsgit/git-remote-keybase/git-remote-keybase"
withCredentials([[$class: 'StringBinding', credentialsId: 'kbfs-docker-cert-b64-new', variable: 'KBFS_DOCKER_CERT_B64']]) {
println "Building Docker"
sh '''
set +x
docker build -t keybaseprivate/kbfsfuse --build-arg KEYBASE_TEST_ROOT_CERT_PEM_B64=\"$KBFS_DOCKER_CERT_B64\" kbfsfuse
docker build -t keybaseprivate/kbfsfuse --build-arg KEYBASE_TEST_ROOT_CERT_PEM_B64=\"$KBFS_DOCKER_CERT_B64\" .
'''
}
sh "docker save keybaseprivate/kbfsfuse | gzip > kbfsfuse.tar.gz"
Expand Down
3 changes: 3 additions & 0 deletions kbfsfuse/kbfsfuse.sh
Expand Up @@ -23,6 +23,9 @@ if [ -f client_revision ]; then
echo "Client revision $(cat client_revision)"
fi

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

keybase -debug service &
SERVICE=$!
# Journaling is turned off for all tests until we change the tests to
Expand Down
3 changes: 2 additions & 1 deletion kbfsgit/git-remote-keybase/main.go
Expand Up @@ -72,7 +72,8 @@ func start() (startErr *libfs.Error) {
panic(fmt.Sprintf("Unexpected run mode: %s", kbCtx.GetRunMode()))
}

defaultParams, storageRoot, err := libgit.Params(kbCtx, kbCtx.GetDataDir())
defaultParams, storageRoot, err := libgit.Params(kbCtx,
kbCtx.GetDataDir(), nil)
if err != nil {
return libfs.InitError(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion libdokan/start.go
Expand Up @@ -49,7 +49,7 @@ func Start(options StartOptions, kbCtx libkbfs.Context) *libfs.Error {
// Hook git implementation in.
options.KbfsParams.CreateGitHandlerInstance =
func(config libkbfs.Config) keybase1.KBFSGitInterface {
return libgit.NewRPCHandlerWithCtx(kbCtx, config)
return libgit.NewRPCHandlerWithCtx(kbCtx, config, &options.KbfsParams)
}

log, err := libkbfs.InitLog(options.KbfsParams, kbCtx)
Expand Down
2 changes: 1 addition & 1 deletion libfuse/start.go
Expand Up @@ -83,7 +83,7 @@ func Start(options StartOptions, kbCtx libkbfs.Context) *libfs.Error {
// Hook git implementation in.
options.KbfsParams.CreateGitHandlerInstance =
func(config libkbfs.Config) keybase1.KBFSGitInterface {
return libgit.NewRPCHandlerWithCtx(kbCtx, config)
return libgit.NewRPCHandlerWithCtx(kbCtx, config, &options.KbfsParams)
}

log, err := libkbfs.InitLog(options.KbfsParams, kbCtx)
Expand Down
31 changes: 26 additions & 5 deletions libgit/init.go
Expand Up @@ -21,14 +21,20 @@ const (

type ctxGitTagKey int

const (
paramKeybaseGitMDServerAddr = "KEYBASE_GIT_MDSERVER_ADDR"
paramKeybaseGitBServerAddr = "KEYBASE_GIT_BSERVER_ADDR"
)

const (
ctxGitIDKey ctxGitTagKey = iota
)

// Params returns a set of default parameters for git-related
// operations, along with a temp directory that should be cleaned
// after the git work is complete.
func Params(kbCtx libkbfs.Context, storageRoot string) (
func Params(kbCtx libkbfs.Context,
storageRoot string, paramsBase *libkbfs.InitParams) (
params libkbfs.InitParams, tempDir string, err error) {
// TODO(KBFS-2443): Also remove all kbfsgit directories older than
// an hour.
Expand All @@ -37,29 +43,44 @@ func Params(kbCtx libkbfs.Context, storageRoot string) (
return libkbfs.InitParams{}, "", err
}

params = libkbfs.DefaultInitParams(kbCtx)
if paramsBase != nil {
params = *paramsBase
} else {
params = libkbfs.DefaultInitParams(kbCtx)
}
params.LogToFile = true
// Set the debug default to true only if the env variable isn't
// explicitly set to a false option.
envDebug := os.Getenv("KBFSGIT_DEBUG")
if envDebug != "0" && envDebug != "false" && envDebug != "no" {
params.Debug = true
}
// This is set to false in docker tests for now, but we need it. So
// override it to true here.
params.EnableJournal = true
params.EnableDiskCache = false
params.StorageRoot = tempDir
params.Mode = libkbfs.InitSingleOpString
params.TLFJournalBackgroundWorkStatus =
libkbfs.TLFJournalSingleOpBackgroundWorkEnabled

if baddr := os.Getenv(paramKeybaseGitBServerAddr); len(baddr) > 0 {
params.BServerAddr = baddr
}
if mdaddr := os.Getenv(paramKeybaseGitMDServerAddr); len(mdaddr) > 0 {
params.MDServerAddr = mdaddr
}

return params, tempDir, nil
}

// Init initializes a context and a libkbfs.Config for git operations.
// The config should be shutdown when it is done being used.
func Init(ctx context.Context, kbfsParams libkbfs.InitParams,
func Init(ctx context.Context, gitKBFSParams libkbfs.InitParams,
kbCtx libkbfs.Context, keybaseServiceCn libkbfs.KeybaseServiceCn,
defaultLogPath string) (context.Context, libkbfs.Config, error) {
log, err := libkbfs.InitLogWithPrefix(
kbfsParams, kbCtx, "git", defaultLogPath)
gitKBFSParams, kbCtx, "git", defaultLogPath)
if err != nil {
return ctx, nil, err
}
Expand All @@ -75,7 +96,7 @@ func Init(ctx context.Context, kbfsParams libkbfs.InitParams,
log.CDebugf(ctx, "Initialized new git config")

config, err := libkbfs.InitWithLogPrefix(
ctx, kbCtx, kbfsParams, keybaseServiceCn, nil, log, "git")
ctx, kbCtx, gitKBFSParams, keybaseServiceCn, nil, log, "git")
if err != nil {
return ctx, nil, err
}
Expand Down
23 changes: 13 additions & 10 deletions libgit/rpc.go
Expand Up @@ -19,25 +19,27 @@ import (

// RPCHandler handles service->KBFS git RPC calls.
type RPCHandler struct {
kbCtx libkbfs.Context
config libkbfs.Config
log logger.Logger
kbCtx libkbfs.Context
config libkbfs.Config
kbfsInitParams *libkbfs.InitParams
log logger.Logger
}

// NewRPCHandlerWithCtx returns a new instance of a Git RPC handler.
func NewRPCHandlerWithCtx(
kbCtx libkbfs.Context, config libkbfs.Config) keybase1.KBFSGitInterface {
func NewRPCHandlerWithCtx(kbCtx libkbfs.Context, config libkbfs.Config,
kbfsInitParams *libkbfs.InitParams) keybase1.KBFSGitInterface {
return &RPCHandler{
kbCtx: kbCtx,
config: config,
log: config.MakeLogger(""),
kbCtx: kbCtx,
config: config,
kbfsInitParams: kbfsInitParams,
log: config.MakeLogger(""),
}
}

// NewRPCHandler returns a new instance of a Git RPC handler using the
// default environment context.
func NewRPCHandler(config libkbfs.Config) keybase1.KBFSGitInterface {
return NewRPCHandlerWithCtx(env.NewContext(), config)
return NewRPCHandlerWithCtx(env.NewContext(), config, nil)
}

var _ keybase1.KBFSGitInterface = (*RPCHandler)(nil)
Expand Down Expand Up @@ -117,7 +119,8 @@ func (rh *RPCHandler) getHandleAndConfig(
}

// Initialize libgit.
params, tempDir, err := Params(rh.kbCtx, rh.config.StorageRoot())
params, tempDir, err := Params(rh.kbCtx,
rh.config.StorageRoot(), rh.kbfsInitParams)
if err != nil {
return nil, nil, nil, "", err
}
Expand Down

0 comments on commit faa10d4

Please sign in to comment.