import "github.com/egdaemon/eg/runtime/wasi/egenv"
func AccountID() string
Read the account ID from the environment
func Base64(fallback []byte, keys ...string) []byte
Base64 read value as a base64 encoded string, the standard alphabet is attempted first and then the url alphabet.
func Base64URL(fallback []byte, keys ...string) []byte
Base64URL read value as a base64 encoded string, see Base64.
func Boolean(fallback bool, keys ...string) bool
Extract a boolean formatted environment variable from the given keys returns the first valid result if none of the keys exist then the fallback is returned.
func Build() *envx.Builder
func CacheDirectory(paths ...string) string
CacheDirectory returns the absolute path to the cache directory, joined with paths when provided.
Deprecated: use DirectoryCache.
func CloneEnabled() bool
CloneEnabled reports whether the repository is cloned from, and so pushed to, a remote. false for `eg compute local`, which works on the local checkout where there is nothing to push to.
func DirectoryCache(paths ...string) string
DirectoryCache returns the absolute path to the cache directory, EG_COMPUTE_CACHE_DIRECTORY or the systemd CACHE_DIRECTORY, falling back to os.TempDir() when neither is set.
lifecycle: survives across workloads on a best effort basis. entries prefixed with .eg are reserved for system use.
paths are joined onto the directory. e.g.) DirectoryCache("foo", "bar") -> "/workload/.eg.cache/foo/bar"
func DirectoryTemp(paths ...string) string
DirectoryTemp returns the absolute path to the temporary directory, which is os.TempDir(). every module is given its own temporary directory, so it is unique to the module.
lifecycle: lives for the duration of a single module's execution.
paths are joined onto the directory. e.g.) DirectoryTemp("foo", "bar") -> "/tmp/foo/bar"
func DirectoryWorking(paths ...string) string
DirectoryWorking returns the absolute path to the working directory, EG_COMPUTE_WORKING_DIRECTORY, falling back to eg.DefaultWorkingDirectory() when it is not set. this is the initial working directory of the workload and is where the repository is cloned.
lifecycle: lives for the duration of a single workload.
paths are joined onto the directory. e.g.) DirectoryWorking("foo", "bar") -> "/workload/eg/foo/bar"
func DirectoryWorkload(paths ...string) string
DirectoryWorkload returns the absolute path to the workload directory, EG_COMPUTE_WORKSPACE_DIRECTORY, falling back to eg.DefaultWorkspaceDirectory() when it is not set.
lifecycle: shared by every module and lives for the duration of a single workload.
paths are joined onto the directory. e.g.) DirectoryWorkload("foo", "bar") -> "/workload/.eg.workspace/foo/bar"
func Draft() bool
Draft reports whether the workload may upload its artifacts to a draft release, set by `eg compute --draft`. workloads build into the workspace by default and only push when this is true.
func Duration(fallback time.Duration, keys ...string) time.Duration
Extract a time.Duration formatted environment variable from the given keys returns the first valid result if none of the keys exist then the fallback is returned.
func Environ() ([]string, error)
Environ provides the environ the runner stored for the workload. the host reads it since commands run as an unprivileged user that cannot.
func EphemeralDirectory(paths ...string) string
EphemeralDirectory returns the absolute path to the ephemeral directory, joined with paths when provided.
Deprecated: use DirectoryTemp.
func HostOS() string
func Initiated() time.Time
Initiated provides the instant the billed run duration started at. returns time.Now() as an approximation: when the runtime did not provide it, the time of the first call is used. the environment is only parsed once.
func Int(fallback int, keys ...string) int
Int retrieve a integer flag from the environment, checks each key in order first to parse successfully is returned.
func MustEnviron(env *envx.Builder) []string
func PathRelative(dir string, path string) string
PathRelative reports paths within dir relative to it. relative paths and paths outside dir are returned as is.
func PathRelativeCache(path string) string
PathRelativeCache reports paths within the cache directory relative to it. relative paths and paths outside the cache directory are returned as is.
func PathRelativeEphemeral(path string) string
PathRelativeEphemeral reports paths within the ephemeral directory relative to it. relative paths and paths outside the ephemeral directory are returned as is.
func PathRelativeWorking(path string) string
PathRelativeWorking reports paths within the working directory relative to it, so they hold wherever the working directory is located. relative paths and paths outside the working directory are returned as is.
func PathRelativeWorkspace(path string) string
PathRelativeWorkspace reports paths within the workspace directory relative to it, so they hold wherever the workspace is located, e.g.) a git worktree. relative paths and paths outside the workspace are returned as is.
func Pattern(format string, args ...any) string
Pattern substitutes values from the environment into the provided pattern.
{eg.run.id} -> the run id of the compute workload, see RunID. {eg.account.id} -> the account id of the compute workload, see AccountID. {eg.workload} -> the workload directory, see DirectoryWorkload. {eg.workload.name} -> the name of the module the workload runs, see WorkloadName. {eg.host.arch} -> the cpu architecture of the host machine. {eg.host.os} -> the operating system of the host machine. {eg.working} -> the working directory, see DirectoryWorking. {eg.cache} -> the cache directory, see DirectoryCache. {eg.tmp} -> the temporary directory of the module, see DirectoryTemp.
the %eg.token% style of tokens is deprecated, use the braces. %eg.run.id% is {eg.run.id}, %eg.workload% is {eg.workload.name} and %eg.workspace% is {eg.workload}.
the tokens are substituted first and the result is then formatted with fmt.Sprintf, e.g.) Pattern("{eg.workload}/%s", "foo") -> "/workload/.eg.workspace/foo".
func Release() bool
Release reports whether the workload may publish the release, set by `eg compute --release`. publishing builds on a draft, so it is only true when Draft is.
func RunID() string
Read the run ID from the environment
func RuntimeDirectory(paths ...string) string
RuntimeDirectory returns the absolute path to the runtime directory, EG_COMPUTE_RUNTIME_DIRECTORY, falling back to os.TempDir() when it is not set. the directory holds the files eg itself uses, e.g.) sockets.
lifecycle: lives for the duration of a workload and is readable by every module.
paths are joined onto the directory. e.g.) RuntimeDirectory("foo", "bar") -> "/eg.mnt/.eg.runtime/foo/bar"
Deprecated: the directory is owned by eg and is not for use by workloads, use egunsafe.RuntimeDirectory if it is required.
func String(fallback string, keys ...string) string
Extract a string formatted environment variable from the given keys. returns the first valid result if none of the keys exist then the fallback is returned.
func TTL() time.Duration
Provides the TTL specified by the runtime. used for setting context durations. defaults to an hour. currently not fully implemented.
func User() *user.User
User returns the current user.
func WorkingDirectory(paths ...string) string
WorkingDirectory returns the absolute path to the working directory, joined with paths when provided.
Deprecated: use DirectoryWorking.
func Workload() string
Read the entry path of the workload from the environment, empty when the runtime did not provide it.
func WorkloadName() string
Read the name of the workload (the module it runs, i.e. the folder name within the module directory) from the environment, empty for the default workload (see eg.DefaultWorkload).
func WorkspaceDirectory(paths ...string) string
WorkspaceDirectory returns the absolute path to the workspace directory, EG_COMPUTE_WORKSPACE_DIRECTORY, falling back to eg.DefaultWorkspaceDirectory() when it is not set.
lifecycle: shared by every module and lives for the duration of a single workload.
paths are joined onto the directory. e.g.) WorkspaceDirectory("foo", "bar") -> "/workload/.eg.workspace/foo/bar"
Deprecated: use DirectoryWorkload.