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
- Variables
- func BackendBinDir(container *dagger.Container, distro executil.Distribution) *dagger.Directory
- func BackendTestIntegration(d *dagger.Client, platform dagger.Platform, dir *dagger.Directory) *dagger.Container
- func BackendTestShort(d *dagger.Client, platform dagger.Platform, dir *dagger.Directory) *dagger.Container
- func BuildOptsDynamic(distro executil.Distribution, buildinfo *BuildInfo) *executil.GoBuildOpts
- func BuildOptsDynamicARM(distro executil.Distribution, buildinfo *BuildInfo) *executil.GoBuildOpts
- func BuildOptsDynamicDarwin(distro executil.Distribution, buildinfo *BuildInfo) *executil.GoBuildOpts
- func BuildOptsDynamicWindows(distro executil.Distribution, buildinfo *BuildInfo) *executil.GoBuildOpts
- func BuildOptsStatic(distro executil.Distribution, buildinfo *BuildInfo) *executil.GoBuildOpts
- func Clone(d *dagger.Client, url, ref string) (*dagger.Directory, error)
- func CloneContainer(d *dagger.Client, opts *GitCloneOptions) (*dagger.Container, error)
- func CloneWithGitHubToken(d *dagger.Client, token, url, ref string) (*dagger.Directory, error)
- func CloneWithSSHAuth(d *dagger.Client, sshKeyPath, url, ref string) (*dagger.Directory, error)
- func CompileBackend(d *dagger.Client, opts *CompileBackendOpts) *dagger.Directory
- func CompileBackendBuilder(d *dagger.Client, opts *CompileBackendOpts) *dagger.Container
- func CompileFrontend(d *dagger.Client, src *dagger.Directory, opts *YarnCacheOpts, ...) *dagger.Directory
- func CypressContainer(d *dagger.Client, base string) *dagger.Container
- func CypressImage(version string) string
- func DockerBuild(d *dagger.Client, opts *DockerBuildOpts) *dagger.Container
- func DownloadGolangDependencies(d *dagger.Client, platform dagger.Platform, gomod, gosum *dagger.File) *dagger.Directory
- func ExitError(ctx context.Context, container *dagger.Container) error
- func ExtractedArchive(d *dagger.Client, f *dagger.File, name string) *dagger.Directory
- func FPMContainer(d *dagger.Client) *dagger.Container
- func GCSDownloadFile(d *dagger.Client, image string, auth GCPAuthenticator, url string) (*dagger.File, error)
- func GCSUploadDirectory(d *dagger.Client, image string, auth GCPAuthenticator, dir *dagger.Directory, ...) (*dagger.Container, error)
- func GCSUploadFile(d *dagger.Client, image string, auth GCPAuthenticator, file *dagger.File, ...) (*dagger.Container, error)
- func GetPackageJSONVersion(ctx context.Context, d *dagger.Client, src *dagger.Directory) (string, error)
- func GetPackages(ctx context.Context, d *dagger.Client, packageOpts *PackageInputOpts, ...) ([]*dagger.File, error)
- func GolangContainer(d *dagger.Client, platform dagger.Platform, base string) *dagger.Container
- func GrafanaContainer(d *dagger.Client, platform dagger.Platform, base string, ...) *dagger.Container
- func HostDir(d *dagger.Client, localPath string) (*dagger.Directory, error)
- func InitializeEnterprise(d *dagger.Client, grafana *dagger.Directory, enterprise *dagger.Directory) *dagger.Directory
- func LookupGitHubToken(ctx context.Context) (string, error)
- func NPMPackages(d *dagger.Client, src *dagger.Directory, opts *YarnCacheOpts, ...) *dagger.Directory
- func NodeContainer(d *dagger.Client, base string) *dagger.Container
- func NodeImage(version string) string
- func NodeVersion(d *dagger.Client, src *dagger.Directory) *dagger.Container
- func PublishDirectory(ctx context.Context, d *dagger.Client, dir *dagger.Directory, opts *GCPOpts, ...) (string, error)
- func PublishFile(ctx context.Context, d *dagger.Client, opts *PublishFileOpts) ([]string, error)
- func RPMContainer(d *dagger.Client, opts *GPGOpts) *dagger.Container
- func Run(ctx context.Context, containers []*dagger.Container) error
- func ValidatePackage(d *dagger.Client, service *dagger.Container, src *dagger.Directory, ...) *dagger.Directory
- func ViceroyContainer(d *dagger.Client, distro executil.Distribution, base string) *dagger.Container
- func WithCachedGoDependencies(container *dagger.Container, dir *dagger.Directory, cache *dagger.CacheVolume) *dagger.Container
- func WithEnv(c *dagger.Container, env map[string]string) *dagger.Container
- func WithViceroyEnv(container *dagger.Container, opts *executil.GoBuildOpts) *dagger.Container
- func WithYarnCache(container *dagger.Container, opts *YarnCacheOpts) *dagger.Container
- func YarnInstall(ctx context.Context, d *dagger.Client, opts *YarnInstallOpts) error
- func ZigCC(distro executil.Distribution) string
- func ZigCXX(distro executil.Distribution) string
- type BuildInfo
- type CompileBackendOpts
- type DistroBuildOptsFunc
- type DockerBuildOpts
- type DockerOpts
- type GCPAuthenticator
- type GCPInheritedAuth
- type GCPOpts
- type GCPServiceAccount
- type GPGOpts
- type GitCloneOptions
- type GrafanaOpts
- func (g *GrafanaOpts) DetectVersion(ctx context.Context, client *dagger.Client, grafanaDir *dagger.Directory) (string, error)
- func (g *GrafanaOpts) Enterprise(ctx context.Context, grafana *dagger.Directory, client *dagger.Client) (*dagger.Directory, error)
- func (g *GrafanaOpts) Grafana(ctx context.Context, client *dagger.Client) (*dagger.Directory, error)
- type PackageInputOpts
- type PackageOpts
- type ProImageOpts
- type PublishFileOpts
- type PublishOpts
- type YarnCacheOpts
- type YarnInstallOpts
Constants ¶
const ( GoURL = "https://go.dev/dl/go1.20.2.linux-%s.tar.gz" ViceroyImage = "rfratto/viceroy:v0.3.0" )
const BusyboxImage = "busybox:1.36"
const GitImage = "alpine/git:v2.36.3"
const (
GoImageAlpine = "golang:1.20.2-alpine"
)
const GoogleCloudImage = "google/cloud-sdk:alpine"
const RPMMacros = `` /* 372-byte string literal not displayed */
const RubyContainer = "ruby:3.2.2-bullseye"
Variables ¶
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(), }, } }
var DefaultTags = []string{
"netgo",
"osusergo",
}
var DistributionGoOpts = map[executil.Distribution]DistroBuildOptsFunc{ executil.DistLinuxARM: BuildOptsDynamicARM, executil.DistLinuxARMv6: BuildOptsDynamicARM, executil.DistLinuxARMv7: BuildOptsDynamicARM, executil.DistLinuxARM64: BuildOptsStatic, executil.DistLinuxARM64Dynamic: BuildOptsDynamic, executil.DistLinuxAMD64: BuildOptsStatic, executil.DistLinuxAMD64Dynamic: BuildOptsDynamic, executil.DistDarwinAMD64: BuildOptsDynamicDarwin, executil.DistDarwinARM64: BuildOptsDynamicDarwin, executil.DistWindowsAMD64: BuildOptsDynamicWindows, executil.DistWindowsARM64: BuildOptsDynamicWindows, executil.DistPlan9AMD64: BuildOptsDynamic, }
var (
ErrorNonZero = errors.New("container exited with non-zero exit code")
)
var ErrorUnrecognizedScheme = errors.New("unrecognized scheme")
var GrafanaCommands = []string{
"grafana",
"grafana-server",
"grafana-cli",
}
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 BackendTestIntegration ¶
func BackendTestShort ¶
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 ¶
Clone returns the directory with the cloned repository ('url') and checked out ref ('ref').
func CloneContainer ¶
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 CloneWithSSHAuth ¶
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:
- 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`.
- 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.
- When building for `arm/v6` or `arm/v7` we want to build these exclusively on Alpine with musl.
- When building anything statically we only want to build them on Alpine with musl.
func CompileFrontend ¶
func CypressContainer ¶
CypressContainer returns a docker container with everything set up that is needed to build or run e2e tests.
func CypressImage ¶
func DockerBuild ¶
func DockerBuild(d *dagger.Client, opts *DockerBuildOpts) *dagger.Container
func ExitError ¶
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 ¶
ExtractedActive returns a directory that holds an extracted tar.gz
func GCSDownloadFile ¶
func GCSUploadDirectory ¶
func GCSUploadFile ¶
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 ¶
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 InitializeEnterprise ¶
func LookupGitHubToken ¶
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 ¶
NodeContainer returns a docker container with everything set up that is needed to build or run frontend tests.
func NodeVersion ¶
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 ¶
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 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 WithViceroyEnv ¶
func WithYarnCache ¶
func WithYarnCache(container *dagger.Container, opts *YarnCacheOpts) *dagger.Container
WithYarnCache mounts the given YarnCacheDir in the provided container
func YarnInstall ¶
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 ¶
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.
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.
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 ¶
type GCPOpts ¶
GCPOpts are options used when using Google Cloud Platform / the Google Cloud SDK.
func GCPOptsFromFlags ¶
func GCPOptsFromFlags(c cliutil.CLIContext) *GCPOpts
type GCPServiceAccount ¶
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 ¶
type GPGOpts ¶
type GPGOpts struct { Sign bool GPGPrivateKeyBase64 string GPGPublicKeyBase64 string GPGPassphraseBase64 string }
func GPGOptsFromFlags ¶
func GPGOptsFromFlags(c cliutil.CLIContext) *GPGOpts
type GitCloneOptions ¶
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 (*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 ¶
Source Files ¶
- base_cypress.go
- base_fpm.go
- base_golang.go
- base_grafana.go
- base_node.go
- base_rpm.go
- base_viceroy.go
- build_backend.go
- build_backend_platforms.go
- build_frontend.go
- buildinfo.go
- cache.go
- clone.go
- dependencies_golang.go
- docker.go
- docs.go
- enterprise.go
- extracted_package.go
- google_cloud.go
- npm_packages.go
- ops_gcp.go
- opts_docker.go
- opts_gpg.go
- opts_grafana.go
- opts_package.go
- opts_pro_image.go
- package_input.go
- package_validate.go
- publish.go
- publish_dir.go
- run.go
- test_backend.go
- version.go
- withenv.go