containers

package
v0.0.0-test Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

package containers defines individual containers that are used to assemble pipelines. running most of these functions that return directories or containers will not actually execute code; container execution is determined by the dagger daemon whenever data is needed from a container.

Index

Constants

View Source
const (
	GoURL        = "https://go.dev/dl/go1.20.2.linux-%s.tar.gz"
	ViceroyImage = "rfratto/viceroy:v0.3.0"
)
View Source
const BusyboxImage = "busybox:1.36"
View Source
const GitImage = "alpine/git:v2.36.3"
View Source
const (
	GoImageAlpine = "golang:1.20.2-alpine"
)
View Source
const GoogleCloudImage = "google/cloud-sdk:alpine"
View Source
const RPMMacros = `` /* 372-byte string literal not displayed */
View Source
const RubyContainer = "ruby:3.2.2-bullseye"

Variables

View Source
var DefaultBuildOpts = func(distro executil.Distribution, buildinfo *BuildInfo) *executil.GoBuildOpts {
	os, arch := executil.OSAndArch(distro)

	return &executil.GoBuildOpts{
		CC:                ZigCC(distro),
		CXX:               ZigCXX(distro),
		ExperimentalFlags: []string{},
		OS:                os,
		Arch:              arch,
		CGOEnabled:        true,
		TrimPath:          true,
		LDFlags: map[string][]string{
			"-X": buildinfo.LDFlags(),
		},
	}
}
View Source
var DefaultTags = []string{
	"netgo",
	"osusergo",
}
View Source
var (
	ErrorNonZero = errors.New("container exited with non-zero exit code")
)
View Source
var ErrorUnrecognizedScheme = errors.New("unrecognized scheme")
View Source
var GrafanaCommands = []string{
	"grafana",
	"grafana-server",
	"grafana-cli",
}
View Source
var ZigTargets = map[executil.Distribution]string{
	executil.DistLinuxAMD64:        "x86_64-linux-musl",
	executil.DistLinuxAMD64Dynamic: "x86_64-linux-musl",
	executil.DistLinuxARM64:        "aarch64-linux-musl",
	executil.DistLinuxARM64Dynamic: "aarch64-linux-musl",
	executil.DistLinuxARM:          "arm-linux-musleabihf",
	executil.DistLinuxARMv6:        "arm-linux-musleabihf",
	executil.DistLinuxARMv7:        "arm-linux-musleabihf",
}

Functions

func BackendBinDir

func BackendBinDir(container *dagger.Container, distro executil.Distribution) *dagger.Directory

func BackendTestIntegration

func BackendTestIntegration(d *dagger.Client, platform dagger.Platform, dir *dagger.Directory) *dagger.Container

func BackendTestShort

func BackendTestShort(d *dagger.Client, platform dagger.Platform, dir *dagger.Directory) *dagger.Container

func BuildOptsDynamic

func BuildOptsDynamic(distro executil.Distribution, buildinfo *BuildInfo) *executil.GoBuildOpts

func BuildOptsDynamicARM

func BuildOptsDynamicARM(distro executil.Distribution, buildinfo *BuildInfo) *executil.GoBuildOpts

BuildOptsDynamicARM builds Grafana statically for the armv6/v7 architectures (not aarch64/arm64)

func BuildOptsDynamicDarwin

func BuildOptsDynamicDarwin(distro executil.Distribution, buildinfo *BuildInfo) *executil.GoBuildOpts

func BuildOptsDynamicWindows

func BuildOptsDynamicWindows(distro executil.Distribution, buildinfo *BuildInfo) *executil.GoBuildOpts

func BuildOptsStatic

func BuildOptsStatic(distro executil.Distribution, buildinfo *BuildInfo) *executil.GoBuildOpts

func Clone

func Clone(d *dagger.Client, url, ref string) (*dagger.Directory, error)

Clone returns the directory with the cloned repository ('url') and checked out ref ('ref').

func CloneContainer

func CloneContainer(d *dagger.Client, opts *GitCloneOptions) (*dagger.Container, error)

CloneContainer returns the container definition that uses git clone to clone the 'git url' and checks out the ref provided at 'ref'. Multiple refs can be provided via a space character (' '). If multiple refs are provided, then the container will attempt to checkout each ref at a time, stopping at the first one that is successful. This can be useful in PRs which have a coupled association with another codebase. A practical example (and why this exists): "${pr_source_branch} ${pr_target_branch} ${main}" will first attempt to checkout the PR source branch, then the PR target branch, then "main"; whichever is successul first.

func CloneWithGitHubToken

func CloneWithGitHubToken(d *dagger.Client, token, url, ref string) (*dagger.Directory, error)

func CloneWithSSHAuth

func CloneWithSSHAuth(d *dagger.Client, sshKeyPath, url, ref string) (*dagger.Directory, error)

CloneWithSSHAuth returns the directory with the cloned repository ('url') and checked out ref ('ref').

func CompileBackend

func CompileBackend(d *dagger.Client, opts *CompileBackendOpts) *dagger.Directory

CompileBackend returns a reference to a dagger directory that contains a usable Grafana binary from the cloned source code at 'grafanaPath'. The returned directory can be exported, which will cause the container to execute the build, or can be mounted into other containers.

func CompileBackendBuilder

func CompileBackendBuilder(d *dagger.Client, opts *CompileBackendOpts) *dagger.Container

CompileBackendBuilder returns the dagger container that will build the requested CompileBackendOpts. Goals:

  1. Attempt to build Grafana using the platform given by the --platform argument. The efficacy of this argument will depend on the docker buildkit capabilties, which can be checked with `docker buildx ls`.
  2. If building for a different OS than Linux, then we use rfratto/vicery to accomplish that. Almost all users' docker buildx capabilities will include linux/amd64, so this should at least be functional. On Mac OS (especially using Apple Silicon chips), this will be incredibly slow. A 5 minute build on linux/amd64 could take 30+ minutes on darwin/arm64.
  3. When building for `arm/v6` or `arm/v7` we want to build these exclusively on Alpine with musl.
  4. When building anything statically we only want to build them on Alpine with musl.

func CompileFrontend

func CompileFrontend(d *dagger.Client, src *dagger.Directory, opts *YarnCacheOpts, nodeVersion string) *dagger.Directory

func CypressContainer

func CypressContainer(d *dagger.Client, base string) *dagger.Container

CypressContainer returns a docker container with everything set up that is needed to build or run e2e tests.

func CypressImage

func CypressImage(version string) string

func DockerBuild

func DockerBuild(d *dagger.Client, opts *DockerBuildOpts) *dagger.Container

func DownloadGolangDependencies

func DownloadGolangDependencies(d *dagger.Client, platform dagger.Platform, gomod, gosum *dagger.File) *dagger.Directory

func ExitError

func ExitError(ctx context.Context, container *dagger.Container) error

ExitError functionally replaces '(*container).ExitCode' in a more usable way. It will return an error with the container's stderr and stdout if the exit code is not zero.

func ExtractedArchive

func ExtractedArchive(d *dagger.Client, f *dagger.File, name string) *dagger.Directory

ExtractedActive returns a directory that holds an extracted tar.gz

func FPMContainer

func FPMContainer(d *dagger.Client) *dagger.Container

func GCSDownloadFile

func GCSDownloadFile(d *dagger.Client, image string, auth GCPAuthenticator, url string) (*dagger.File, error)

func GCSUploadDirectory

func GCSUploadDirectory(d *dagger.Client, image string, auth GCPAuthenticator, dir *dagger.Directory, dst string) (*dagger.Container, error)

func GCSUploadFile

func GCSUploadFile(d *dagger.Client, image string, auth GCPAuthenticator, file *dagger.File, dst string) (*dagger.Container, error)

func GetPackageJSONVersion

func GetPackageJSONVersion(ctx context.Context, d *dagger.Client, src *dagger.Directory) (string, error)

GetPackageJSONVersion gets the "version" field from package.json in the 'src' directory.

func GetPackages

func GetPackages(ctx context.Context, d *dagger.Client, packageOpts *PackageInputOpts, gcpOpts *GCPOpts) ([]*dagger.File, error)

GetPackage uses the PackageInputOpts to get a Grafana package, either from the local filesystem (if the package is of type 'file://...') or Google Cloud Storage if the package is a 'gs://' URL.

func GolangContainer

func GolangContainer(d *dagger.Client, platform dagger.Platform, base string) *dagger.Container

GolangContainer returns a dagger container with everything set up that is needed to build Grafana's Go backend or run the Golang tests.

func GrafanaContainer

func GrafanaContainer(d *dagger.Client, platform dagger.Platform, base string, grafana *dagger.Directory) *dagger.Container

GrafanaContainer is the base Golang image with everything set up to build and test Grafana. Mostly that means that: * The grafana source code is mounted. * 'make' is installed. * the wire dependency graph has been generated (using 'make gen-go') * schemas have been generated (using 'make gen-cue')

func HostDir

func HostDir(d *dagger.Client, localPath string) (*dagger.Directory, error)

func InitializeEnterprise

func InitializeEnterprise(d *dagger.Client, grafana *dagger.Directory, enterprise *dagger.Directory) *dagger.Directory

func LookupGitHubToken

func LookupGitHubToken(ctx context.Context) (string, error)

LookupGitHubToken will try to find a GitHub access token that can then be used for various API calls but also cloning of private repositories.

func NPMPackages

func NPMPackages(d *dagger.Client, src *dagger.Directory, opts *YarnCacheOpts, version, nodeVersion string) *dagger.Directory

NPMPackages returns a dagger.Directory which contains the Grafana NPM packages from the grafana source code.

func NodeContainer

func NodeContainer(d *dagger.Client, base string) *dagger.Container

NodeContainer returns a docker container with everything set up that is needed to build or run frontend tests.

func NodeImage

func NodeImage(version string) string

func NodeVersion

func NodeVersion(d *dagger.Client, src *dagger.Directory) *dagger.Container

NodeVersionContainer returns a container whose `stdout` will return the node version from the '.nvmrc' file in the directory 'src'.

func PublishDirectory

func PublishDirectory(ctx context.Context, d *dagger.Client, dir *dagger.Directory, opts *GCPOpts, dst string) (string, error)

PublishDirectory publishes a directory to the given destination.

func PublishFile

func PublishFile(ctx context.Context, d *dagger.Client, opts *PublishFileOpts) ([]string, error)

PublishFile publishes the *dagger.File to the specified location. If the destination involves a remote URL or authentication in some way, that information should be populated in the `opts *PublishOpts` argument.

func RPMContainer

func RPMContainer(d *dagger.Client, opts *GPGOpts) *dagger.Container

func Run

func Run(ctx context.Context, containers []*dagger.Container) error

func ValidatePackage

func ValidatePackage(d *dagger.Client, service *dagger.Container, src *dagger.Directory, yarnCacheVolume *dagger.CacheVolume, nodeVersion string) *dagger.Directory

NodeContainer returns a docker container with everything set up that is needed to build or run frontend tests.

func ViceroyContainer

func ViceroyContainer(d *dagger.Client, distro executil.Distribution, base string) *dagger.Container

ViceroyContainer returns a dagger container with everything set up that is needed to build Grafana's Go backend with CGO using Viceroy, which makes setting up the C compiler toolchain easier.

func WithCachedGoDependencies

func WithCachedGoDependencies(container *dagger.Container, dir *dagger.Directory, cache *dagger.CacheVolume) *dagger.Container

func WithEnv

func WithEnv(c *dagger.Container, env map[string]string) *dagger.Container

func WithViceroyEnv

func WithViceroyEnv(container *dagger.Container, opts *executil.GoBuildOpts) *dagger.Container

func WithYarnCache

func WithYarnCache(container *dagger.Container, opts *YarnCacheOpts) *dagger.Container

WithYarnCache mounts the given YarnCacheDir in the provided container

func YarnInstall

func YarnInstall(ctx context.Context, d *dagger.Client, opts *YarnInstallOpts) error

YarnInstall mounts all of the necessary files to run a `yarn install` and then runs `yarn install` to populate the cache before being reused elsewhere.

func ZigCC

func ZigCC(distro executil.Distribution) string

func ZigCXX

func ZigCXX(distro executil.Distribution) string

Types

type BuildInfo

type BuildInfo struct {
	Version   string
	Commit    string
	Branch    string
	Timestamp time.Time
}

func GetBuildInfo

func GetBuildInfo(ctx context.Context, d *dagger.Client, dir *dagger.Directory, version string) (*BuildInfo, error)

GetBuildInfo runs a dagger pipeline using the alpine/git image to get information from the git repository. Because this function both creates containers and pulls data from them, it will actually run containers to get the build info for the git repository.

func (*BuildInfo) LDFlags

func (b *BuildInfo) LDFlags() []string

type CompileBackendOpts

type CompileBackendOpts struct {
	Distribution executil.Distribution
	Platform     dagger.Platform
	Source       *dagger.Directory
	BuildInfo    *BuildInfo
	Env          map[string]string
	GoTags       []string

	CombinedExecutables bool
}

CompileBackendOpts is similar to pipelines.CompileGrafanaOpts, but with more options specific to the backend compilation. CompileBackendOpts defines the options that are required to build the Grafana backend for a single distribution.

type DistroBuildOptsFunc

type DistroBuildOptsFunc func(executil.Distribution, *BuildInfo) *executil.GoBuildOpts

type DockerBuildOpts

type DockerBuildOpts struct {
	// Dockerfile is the path to the dockerfile with the '-f' command.
	// If it's not provided, then the docker command will default to 'Dockerfile' in `pwd`.
	Dockerfile string

	// Tags are provided as the '-t' argument, and can include the registry domain as well as the repository.
	// Docker build supports building the same image with multiple tags.
	// You might want to also include a 'latest' version of the tag.
	Tags []string
	// BuildArgs are provided to the docker command as '--build-arg'
	BuildArgs []string

	// UnixSocket should be created with the 'd.Host().UnixSocket(...)' function.
	// Most of the time, you will use 'd.Host().UnixSocket("/var/run/docker.sock")', but this unfortunately won't work on Windows machines.
	// TODO: Support an option to use the docker HTTP server.
	UnixSocket *dagger.Socket

	// Before allows the caller to add file and directory mounts, environment variables, etc before 'docker build' is called.
	// This is where you should add your context using relative paths; the docker context will be provided as '.'
	Before func(*dagger.Container) *dagger.Container

	// Platform, if set to the non-default value, will use buildkit's emulation to build the docker image. This can be useful if building a docker image for a platform that doesn't match the host platform.
	Platform dagger.Platform
}

type DockerOpts

type DockerOpts struct {
	// Registry is the docker Registry for the image.
	// If using '--save', then this will have no effect.
	// Uses docker hub by default.
	// Example: us.gcr.io/12345
	Registry string

	// AlpineBase is supplied as a build-arg when building the Grafana docker image.
	// When building alpine versions of Grafana it uses this image as its base.
	AlpineBase string

	// UbuntuBase is supplied as a build-arg when building the Grafana docker image.
	// When building ubuntu versions of Grafana it uses this image as its base.
	UbuntuBase string
}

func DockerOptsFromFlags

func DockerOptsFromFlags(c cliutil.CLIContext) *DockerOpts

type GCPAuthenticator

type GCPAuthenticator interface {
	Authenticate(*dagger.Client, *dagger.Container) (*dagger.Container, error)
}

GCPAuthenticator injects authentication information into the provided container.

func GCSAuth

func GCSAuth(d *dagger.Client, opts *GCPOpts) GCPAuthenticator

type GCPInheritedAuth

type GCPInheritedAuth struct{}

InheritedServiceAccount uses `gcloud` command in the current shell to get the GCS credentials. This type should really only be used when running locally.

func (*GCPInheritedAuth) Authenticate

func (a *GCPInheritedAuth) Authenticate(d *dagger.Client, c *dagger.Container) (*dagger.Container, error)

type GCPOpts

type GCPOpts struct {
	ServiceAccountKey       string
	ServiceAccountKeyBase64 string
}

GCPOpts are options used when using Google Cloud Platform / the Google Cloud SDK.

func GCPOptsFromFlags

func GCPOptsFromFlags(c cliutil.CLIContext) *GCPOpts

type GCPServiceAccount

type GCPServiceAccount struct {
	DaggerFile *dagger.File
	JSONFile   string
}

GCPServiceAccount satisfies GCPAuthenticator and injects the provided ServiceAccount into the filesystem and adds a 'gcloud auth activate-service-account'

func NewGCPServiceAccount

func NewGCPServiceAccount(filepath string) *GCPServiceAccount

func NewGCPServiceAccountWithFile

func NewGCPServiceAccountWithFile(file *dagger.File) *GCPServiceAccount

func (*GCPServiceAccount) Authenticate

func (a *GCPServiceAccount) Authenticate(d *dagger.Client, c *dagger.Container) (*dagger.Container, error)

type GPGOpts

type GPGOpts struct {
	Sign                bool
	GPGPrivateKeyBase64 string
	GPGPublicKeyBase64  string
	GPGPassphraseBase64 string
}

func GPGOptsFromFlags

func GPGOptsFromFlags(c cliutil.CLIContext) *GPGOpts

type GitCloneOptions

type GitCloneOptions struct {
	Ref string
	URL string

	SSHKeyPath string

	// Username is injected into the final URL used for cloning
	Username string
	// Password is injected into the final URL used for cloning
	Password string
}

type GrafanaOpts

type GrafanaOpts struct {
	BuildGrafana bool
	// GrafanaDir is the path to the Grafana source tree.
	GrafanaDir      string
	GrafanaRepo     string
	GrafanaRef      string
	BuildEnterprise bool
	EnterpriseRepo  string
	EnterpriseRef   string
	// EnterpriseDir is the path to the Grafana Enterprise source tree.
	EnterpriseDir string
	BuildID       string
	GitHubToken   string
	Env           map[string]string
	GoTags        []string

	// Version will be set by the '--version' flag if provided, and returned in the 'Version' function.
	// If not set, then the version function will attempt to retrieve the version from Grafana's package.json or some other method.
	Version          string
	YarnCacheHostDir string
}

GrafnaaOpts are populated by the 'GrafanaFlags' flags. These options define how to mount or clone the grafana/enterprise source code.

func GrafanaOptsFromFlags

func GrafanaOptsFromFlags(ctx context.Context, c cliutil.CLIContext) (*GrafanaOpts, error)

func (*GrafanaOpts) DetectVersion

func (g *GrafanaOpts) DetectVersion(ctx context.Context, client *dagger.Client, grafanaDir *dagger.Directory) (string, error)

func (*GrafanaOpts) Enterprise

func (g *GrafanaOpts) Enterprise(ctx context.Context, grafana *dagger.Directory, client *dagger.Client) (*dagger.Directory, error)

Entrerprise will attempt to mount or clone Grafana Enterprise based on the arguments provided. If, for example, the enterprise-dir argument was supplied, then this function will mount that directory. If it was not set then it will attempt to clone, optionally using the 'enterprise-ref' argument.

func (*GrafanaOpts) Grafana

func (g *GrafanaOpts) Grafana(ctx context.Context, client *dagger.Client) (*dagger.Directory, error)

Grafana will attempt to mount or clone Grafana based on the arguments provided. If, for example, the grafana-dir argument was supplied, then this function will mount that directory. If it was not set then it will attempt to clone, optionally using the 'grafana-ref' argument.

type PackageInputOpts

type PackageInputOpts struct {
	Packages []string
}

func PackageInputOptsFromFlags

func PackageInputOptsFromFlags(c cliutil.CLIContext) *PackageInputOpts

type PackageOpts

type PackageOpts struct {
	Distros []executil.Distribution
	Edition string
}

func PackageOptsFromFlags

func PackageOptsFromFlags(c cliutil.CLIContext) *PackageOpts

type ProImageOpts

type ProImageOpts struct {
	// Github token used to clone private repositories.
	GitHubToken string

	// The path to a Grafana debian package.
	Deb string

	// The Grafana version.
	GrafanaVersion string

	// The docker image tag.
	ImageTag string

	// The release type.
	ReleaseType string

	// True if the pro image should be pushed to the container registry.
	Push bool

	// The container registry that the image should be pushed to. Required if Push is true.
	ContainerRegistry string
}

func ProImageOptsFromFlags

func ProImageOptsFromFlags(c cliutil.CLIContext) *ProImageOpts

type PublishFileOpts

type PublishFileOpts struct {
	File        *dagger.File
	PublishOpts *PublishOpts
	GCPOpts     *GCPOpts
	Destination string
}

type PublishOpts

type PublishOpts struct {
	// Destination is any URL to publish an artifact(s) to.
	// Examples:
	// * '/tmp/package.tar.gz'
	// * 'file:///tmp/package.tar.gz'
	// * 'gcs://bucket/package.tar.gz'
	Destination string

	// Checksum defines if the PublishFile function should also produce / publish a checksum of the given `*dagger.File'
	Checksum bool
}

PublishOpts fields are selectively used based on the protocol field of the destination. Be sure to fill out the applicable fields (or all of them) when calling a 'Publish' func.

func PublishOptsFromFlags

func PublishOptsFromFlags(c cliutil.CLIContext) *PublishOpts

type YarnCacheOpts

type YarnCacheOpts struct {
	// If HostDir is set, then that will be mounted to the .yarn/cache directory.
	HostDir *dagger.Directory

	// If HostDir is not set, then CacheVolume will be mounted in the container.
	CacheVolume *dagger.CacheVolume
}

type YarnInstallOpts

type YarnInstallOpts struct {
	CacheOpts   *YarnCacheOpts
	Files       map[string]*dagger.File
	Directories map[string]*dagger.Directory
	NodeVersion string
}

Jump to

Keyboard shortcuts

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