externalbuilder

package
v2.0.0-beta+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DialTimeout        = 3 * time.Second
	CCServerReleaseDir = "chaincode/server"
)

Variables

View Source
var (
	// DefaultEnvWhitelist enumerates the list of environment variables that are
	// implicitly propagated to external builder and launcher commands.
	DefaultEnvWhitelist = []string{"LD_LIBRARY_PATH", "LIBPATH", "PATH", "TMPDIR"}
)

Functions

func CopyDir

func CopyDir(srcroot, destroot string) error

CopyDir creates a copy of a dir

func MoveOrCopyDir

func MoveOrCopyDir(logger *flogging.FabricLogger, srcroot, destroot string) error

MoveOrCopyDir attempts to copy src to dest by firstly trying to move, then copy upon failure.

func SanitizeCCIDPath

func SanitizeCCIDPath(ccid string) string

SanitizeCCIDPath is used to ensure that special characters are removed from file names.

func Untar

func Untar(buffer io.Reader, dst string) error

Untar takes a gzip-ed tar archive, and extracts it to dst. It returns an error if the tar contains any files which would escape to a parent of dst, or if the archive contains any files whose type is not a regular file or directory.

func ValidPath

func ValidPath(uncleanPath string) bool

ValidPath checks to see if the path is absolute, or if it is a relative path higher in the tree. In these cases it returns false.

Types

type BuildContext

type BuildContext struct {
	CCID        string
	ScratchDir  string
	SourceDir   string
	ReleaseDir  string
	MetadataDir string
	BldDir      string
}

BuildContext holds references to the various assets locations necessary to execute the detect, build, release, and run programs for external builders

func NewBuildContext

func NewBuildContext(ccid string, mdBytes []byte, codePackage io.Reader) (bc *BuildContext, err error)

NewBuildContext creates the directories required to runt he external build process and extracts the chaincode package assets.

Users of the BuildContext must call Cleanup when the build process is complete to remove the transient file system assets.

func (*BuildContext) Cleanup

func (bc *BuildContext) Cleanup()

Cleanup removes the build context artifacts.

type BuildInfo

type BuildInfo struct {
	// BuilderName is the user provided name of the external builder.
	BuilderName string `json:"builder_name"`
}

BuildInfo contains metadata is that is saved to the local file system with the assets generated by an external builder. This is used to associate build output with the builder that generated it.

type Builder

type Builder struct {
	EnvWhitelist []string
	Location     string
	Logger       *flogging.FabricLogger
	Name         string
}

A Builder is used to interact with an external chaincode builder and launcher.

func CreateBuilders

func CreateBuilders(builderConfs []peer.ExternalBuilder) []*Builder

CreateBuilders will construct builders from the peer configuration.

func (*Builder) Build

func (b *Builder) Build(buildContext *BuildContext) error

Build runs the `build` script.

func (*Builder) Detect

func (b *Builder) Detect(buildContext *BuildContext) bool

Detect runs the `detect` script.

func (*Builder) NewCommand

func (b *Builder) NewCommand(name string, args ...string) *exec.Cmd

NewCommand creates an exec.Cmd that is configured to prune the calling environment down to the environment variables specified in the external builder's EnvironmentWhitelist and the DefaultEnvWhitelist.

func (*Builder) Release

func (b *Builder) Release(buildContext *BuildContext) error

Release runs the `release` script.

func (*Builder) Run

func (b *Builder) Run(ccid, bldDir string, peerConnection *ccintf.PeerConnection) (*Session, error)

Run starts the `run` script and returns a Session that can be used to signal it and wait for termination.

type ChaincodeServerUserData

type ChaincodeServerUserData struct {
	Address            string   `json:"address"`
	DialTimeout        Duration `json:"dial_timeout"`
	TlsRequired        bool     `json:"tls_required"`
	ClientAuthRequired bool     `json:"client_auth_required"`
	KeyPath            string   `json:"key_path"`
	CertPath           string   `json:"cert_path"`
	RootCertPath       string   `json:"root_cert_path"`
}

ChaincodeServerUserData holds "connection.json" information

func (*ChaincodeServerUserData) ChaincodeServerInfo

func (ccdata *ChaincodeServerUserData) ChaincodeServerInfo(cryptoDir string) (*ccintf.ChaincodeServerInfo, error)

type Detector

type Detector struct {
	// DurablePath is the file system location where chaincode assets are persisted.
	DurablePath string
	// Builders are the builders that detect and build processing will use.
	Builders []*Builder
}

A Detector is responsible for orchestrating the external builder detection and build process.

func (*Detector) Build

func (d *Detector) Build(ccid string, mdBytes []byte, codeStream io.Reader) (*Instance, error)

Build executes the external builder detect and build process.

Before running the detect and build process, the detector first checks the durable path for the results of a previous build for the provided package. If found, the detect and build process is skipped and the existing instance is returned.

func (*Detector) CachedBuild

func (d *Detector) CachedBuild(ccid string) (*Instance, error)

CachedBuild returns a build instance that was already built or nil when no instance has been found. An error is returned only when an unexpected condition is encountered.

type Duration

type Duration struct {
	time.Duration
}

Duration used for the DialTimeout property

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type Instance

type Instance struct {
	PackageID   string
	BldDir      string
	ReleaseDir  string
	Builder     *Builder
	Session     *Session
	TermTimeout time.Duration
}

func (*Instance) ChaincodeServerInfo

func (i *Instance) ChaincodeServerInfo() (*ccintf.ChaincodeServerInfo, error)

func (*Instance) ChaincodeServerReleaseDir

func (i *Instance) ChaincodeServerReleaseDir() string

func (*Instance) Start

func (i *Instance) Start(peerConnection *ccintf.PeerConnection) error

func (*Instance) Stop

func (i *Instance) Stop() error

Stop signals the process to terminate with SIGTERM. If the process doesn't terminate within TermTimeout, the process is killed with SIGKILL.

func (*Instance) Wait

func (i *Instance) Wait() (int, error)

type MetadataProvider

type MetadataProvider struct {
	DurablePath string
}

func (*MetadataProvider) PackageMetadata

func (mp *MetadataProvider) PackageMetadata(ccid string) ([]byte, error)

PackageMetadata returns a set of bytes encoded as a tar file, containing the release metadata as provided by the external builder. If no directory with build output from the external builder is found, the tar bytes will be nil. If the build output is found, but there is no metadata, the bytes will be an empty tar. An error is returned only if the build output is found but some other error occurs.

type Session

type Session struct {
	// contains filtered or unexported fields
}

func Start

func Start(logger *flogging.FabricLogger, cmd *exec.Cmd) (*Session, error)

Start will start the provided command and return a Session that can be used to await completion or signal the process.

The provided logger is used log stderr from the running process.

func (*Session) Signal

func (s *Session) Signal(sig os.Signal)

Signal will send a signal to the running process.

func (*Session) Wait

func (s *Session) Wait() error

Wait waits for the running command to terminate and returns the exit error from the command. If the command has already exited, the exit err will be returned immediately.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL