ci

package
v0.0.0-...-4a58531 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultContainerTimeout = time.Duration(10 * time.Minute)
	QuickFeedPath           = "/quickfeed"
)

Functions

func EnvVars

func EnvVars(sessionSecret, home, repoName, currentAssignment string) []string

func TestExecutionMetricsCollectors

func TestExecutionMetricsCollectors() []prometheus.Collector

TestExecutionMetricsCollectors returns a list of Prometheus metrics collectors for test execution.

Types

type Docker

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

Docker is an implementation of the CI interface using Docker.

func NewDockerCI

func NewDockerCI(logger *zap.SugaredLogger) (*Docker, error)

NewDockerCI returns a runner to run CI tests.

func (*Docker) Close

func (d *Docker) Close() error

Close ensures that the docker client is closed.

func (*Docker) Run

func (d *Docker) Run(ctx context.Context, job *Job) (string, error)

Run implements the CI interface. This method blocks until the job has been completed or an error occurs, e.g., the context times out.

type Job

type Job struct {
	// Name describes the running job; mainly used to name docker containers.
	Name string
	// Image names the image to use to run the job.
	Image string
	// Dockerfile contents.
	// If empty, the image is assumed to exist.
	// If non-empty, the image is built from this Dockerfile.
	Dockerfile string
	// BindDir is the directory to bind to the container's /quickfeed directory.
	BindDir string
	// Env is a list of environment variables to set for the job.
	Env []string
	// Commands is a list of shell commands to run as part of the job.
	Commands []string
}

Job describes how to execute a CI job.

type Local

type Local struct{}

Local is an implementation of the CI interface executing code locally.

func (*Local) Run

func (*Local) Run(_ context.Context, job *Job) (string, error)

Run implements the CI interface. This method blocks until the job has been completed or an error occurs, e.g., the context times out.

type RunData

type RunData struct {
	Course     *qf.Course
	Assignment *qf.Assignment
	Repo       *qf.Repository
	EnvVarsFn  func(secret, homeDir string) []string
	BranchName string
	CommitID   string
	JobOwner   string
	Rebuild    bool
}

RunData stores CI data

func (RunData) GetOwners

func (r RunData) GetOwners(db database.Database) ([]uint64, error)

GetOwners returns the UserIDs of a user or group repository's owners. Returns an error if no owners could be found. This method should only be called for a user or group repository.

func (RunData) RecordResults

func (r RunData) RecordResults(logger *zap.SugaredLogger, db database.Database, results *score.Results) (*qf.Submission, error)

RecordResults for the course and assignment given by the run data structure. If the results argument is nil, then the submission is considered to be a manual review.

func (*RunData) RunTests

func (r *RunData) RunTests(ctx context.Context, logger *zap.SugaredLogger, sc scm.SCM, runner Runner) (*score.Results, error)

RunTests runs the tests for the assignment specified in the provided RunData structure, and returns the score results or an error. The method is idempotent and can be called concurrently on multiple RunData objects. The method clones the student or group repository from GitHub as specified in RunData, and copies the course's tests and assignment repositories from the host machine's file system. runs the tests and returns the score results.

The os.MkdirTemp() function ensures that any concurrent calls to this method will always use distinct temp directories. Specifically, the method creates a temporary directory on the host machine running the quickfeed server that holds the cloned/copied repositories and will be mounted as '/quickfeed' inside the container. This allows the docker container to run the tests on the student code and manipulate the folders as needed for a particular lab assignment's test requirements. The temporary directory is deleted when the container exits at the end of this method.

func (RunData) String

func (r RunData) String() string

String returns a string representation of the run data structure.

type Runner

type Runner interface {
	// Run should synchronously execute the described job and return the output.
	Run(context.Context, *Job) (string, error)
}

Runner contains methods for running user provided code in isolation.

Jump to

Keyboard shortcuts

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