gitservices

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypeReady = "ready"
	EventTypeError = "error"
	EventTypeLog   = "log"
)

Event type constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Attributes

type Attributes struct {
	// ServerRoot is the root filesystem path of the git server. URL paths
	// refer to repositories relative to this root
	ServerRoot string
	// PrivateRepoPath is the filesystem path, relative to `serverRoot`, where
	// the private git repository is hosted
	PrivateRepoPath string
	// privateRepoPath is the URI path in the name of the public go module;
	// this public go module has a private dependency on the repo at
	// `privateRepoPath`
	DependingRepoPath string
	// HTTP Server path is the filesystem path of the already-built HTTP
	// server, installed into its final location.
	HTTPServerPath string

	// PrivateGomoduleHost is the hostname of the git server
	PrivateGomoduleHost string

	// HTTPPort is the requested port on which the http git server listens. Use
	// 0 to request an ephemeral port; the actual bound port is reported back
	// and written here once the server is online.
	HTTPPort int
	// SSHPort is the port on which the ssh git server runs
	SSHPort int

	// HTTPServerBuildDir is the location at which the HTTP server program's
	// code will be loaded for building
	HTTPServerBuildDir string
	// HTTPServerBuildPath is the *local filesystem* location at which the HTTP server program's
	// code can be found
	HTTPServeCodeLocalPath string
	// OutDir is the location to which dalec will output files
	OutDir string

	// ModFileGoVersion is the go version for the go modules
	ModFileGoVersion string
	// contains filtered or unexported fields
}

Attributes are the basic pieces of information needed to host two git servers, one via SSH and one via HTTP

func (*Attributes) HTTPServerBase

func (g *Attributes) HTTPServerBase() string

func (*Attributes) HTTPServerDir

func (g *Attributes) HTTPServerDir() string

func (*Attributes) PrivateGoModuleGitTag

func (a *Attributes) PrivateGoModuleGitTag() string

func (*Attributes) PrivateRepoAbsPath

func (g *Attributes) PrivateRepoAbsPath() string

`PrivateRepoAbsPath` returns the resolved absolute filepath of the private git repo in the `gitHost` container.

func (*Attributes) RepoAbsDir

func (a *Attributes) RepoAbsDir() string

type ErrorEvent added in v0.21.0

type ErrorEvent struct {
	Message string `json:"message" yaml:"message"`
}

ErrorEvent indicates an error occurred.

type File

type File struct {
	Location string
	Template string
}

Wrapper types to make templating and injecting files into llb states

func (*File) Inject

func (f *File) Inject(t *testing.T, obj *Attributes) []byte

type LogEvent added in v0.21.0

type LogEvent struct {
	Message string `json:"message" yaml:"message"`
}

LogEvent is an informational log message.

type ReadyEvent added in v0.21.0

type ReadyEvent struct {
	// IP is the IP address the server is bound to (usually the container's IP).
	IP string `json:"ip" yaml:"ip"`
	// Port is the port the server is listening on.
	Port int `json:"port" yaml:"port"`
}

ReadyEvent indicates the server is ready to accept connections.

type Script

type Script struct {
	Basename string
	Template string
}

Wrapper types to make templating and injecting files into llb states. Scripts will typically be copied into `customScriptDir`

func (*Script) Inject

func (s *Script) Inject(t *testing.T, obj *Attributes) []byte

Completes a template and adds a shebang to a script.

type ServerEvent added in v0.21.0

type ServerEvent struct {
	// Type indicates the kind of event
	Type string `json:"type" yaml:"type"`

	// Ready is sent when the server is ready to accept connections.
	// It includes the IP address and port the server is listening on.
	Ready *ReadyEvent `json:"ready,omitempty" yaml:"ready,omitempty"`

	// Error is sent when an error occurs.
	Error *ErrorEvent `json:"error,omitempty" yaml:"error,omitempty"`

	// Log is sent for informational messages.
	Log *LogEvent `json:"log,omitempty" yaml:"log,omitempty"`
}

ServerEvent represents an event sent from a git server container to the test client. Events are sent as newline-delimited JSON on stdout.

type ServerResult added in v0.21.0

type ServerResult struct {
	// IP is the IP address of the container running the server.
	IP string
	// Port is the port the server is listening on.
	Port int
	// ErrChan receives errors from the server process.
	ErrChan <-chan error
}

ServerResult contains the result of starting a git server.

type TestState

type TestState struct {
	T    *testing.T
	Attr *Attributes
	// contains filtered or unexported fields
}

`TestState` is a bundle of stuff that the tests need access to in order to do their work.

func NewTestState

func NewTestState(t *testing.T, client gwclient.Client, attr *Attributes) TestState

func (*TestState) Client

func (ts *TestState) Client() gwclient.Client

func (*TestState) CustomFile

func (ts *TestState) CustomFile(f File) llb.StateOption

func (*TestState) GenerateSpec

func (ts *TestState) GenerateSpec(gomodContents string, auth dalec.GomodGitAuth) *dalec.Spec

Dalec spec boilerplate

func (*TestState) InitializeGitRepo

func (ts *TestState) InitializeGitRepo(worker llb.State) llb.StateOption

InitializeGitRepo returns a stateOption that uses `worker` to create an initialized git repository from the base state.

func (*TestState) StartHTTPGitServer

func (ts *TestState) StartHTTPGitServer(ctx context.Context, gitHost llb.State) ServerResult

`StartHTTPGitServer` starts a git HTTP server to serve the private go module as a git repo. It returns the container's IP address and an error channel.

func (*TestState) StartSSHServer

func (ts *TestState) StartSSHServer(ctx context.Context, gitHost llb.State) ServerResult

startSSHServer starts an sshd instance in a container hosting the git repo. It runs asynchronously and returns the container's IP and an error channel.

func (*TestState) UpdatedGitconfig

func (ts *TestState) UpdatedGitconfig() llb.StateOption

`UpdatedGitconfig` updatesd the gitconfig on the gomod worker. This is convoluted, but necessary. The `go` tool uses `git` under the hood to download go modules in response to an invocation of `go mod download`. Making such an invocation will cause go to open the `go.mod` file in the current directory and build a dependency graph of modules to download.

A go module cannot have a URI that includes a port number. Go uses the standard HTTP/HTTPS/SSH ports of 80, 443, and 22 respenctively, to attempt to fetch a module. Root privileges would be required to bind to those port numbers, so we run our HTTP and SSH servers on nonstandard ports.

Modifying the gitconfig as below will tell git to substitute http://host.com:port/ when it receives a request for a repository at http://host.com/ . That way, when go sees a module with URI path `host.com/module/name`, it will call `git` to look up the repository there. Git will first consult the gitconfig to see if there are any subsittutions, and will then make a request instead to http://host.com:<portnumber>/module/name .

Directories

Path Synopsis
cmd
server command

Jump to

Keyboard shortcuts

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