Documentation
¶
Index ¶
- Constants
- Variables
- func CloneRepo(ctx context.Context, opts CloneRepoOptions) (bool, error)
- func DefaultWorkspaceFolder(repoURL string) (string, error)
- func HijackLogrus(callback func(entry *logrus.Entry))
- func LogHostKeyCallback(log LoggerFunc) gossh.HostKeyCallback
- func ReadPrivateKey(path string) (gossh.Signer, error)
- func Run(ctx context.Context, options Options) error
- func SetupRepoAuth(options *Options) transport.AuthMethod
- func WithEnvPrefix(str string) string
- type CloneRepoOptions
- type DockerConfig
- type LoggerFunc
- type Options
Constants ¶
const ( // WorkspacesDir is the path to the directory where // all workspaces are stored by default. WorkspacesDir = "/workspaces" // EmptyWorkspaceDir is the path to a workspace that has // nothing going on... it's empty! EmptyWorkspaceDir = WorkspacesDir + "/empty" // MagicDir is where all envbuilder related files are stored. // This is a special directory that must not be modified // by the user or images. MagicDir = "/.envbuilder" )
Variables ¶
var ( ErrNoFallbackImage = errors.New("no fallback image has been specified") // MagicFile is a file that is created in the workspace // when envbuilder has already been run. This is used // to skip building when a container is restarting. // e.g. docker stop -> docker start MagicFile = filepath.Join(MagicDir, "built") )
Functions ¶
func CloneRepo ¶
func CloneRepo(ctx context.Context, opts CloneRepoOptions) (bool, error)
CloneRepo will clone the repository at the given URL into the given path. If a repository is already initialized at the given path, it will not be cloned again.
The bool returned states whether the repository was cloned or not.
func DefaultWorkspaceFolder ¶
DefaultWorkspaceFolder returns the default workspace folder for a given repository URL.
func HijackLogrus ¶
HijackLogrus hijacks the logrus logger and calls the callback for each log entry. This is an abuse of logrus, the package that Kaniko uses, but it exposes no other way to obtain the log entries.
func LogHostKeyCallback ¶
func LogHostKeyCallback(log LoggerFunc) gossh.HostKeyCallback
LogHostKeyCallback is a HostKeyCallback that just logs host keys and does nothing else.
func ReadPrivateKey ¶
ReadPrivateKey attempts to read an SSH private key from path and returns an ssh.Signer.
func Run ¶
Run runs the envbuilder. Logger is the logf to use for all operations. Filesystem is the filesystem to use for all operations. Defaults to the host filesystem.
func SetupRepoAuth ¶
func SetupRepoAuth(options *Options) transport.AuthMethod
SetupRepoAuth determines the desired AuthMethod based on options.GitURL:
| Git URL format | GIT_USERNAME | GIT_PASSWORD | Auth Method | | ------------------------|--------------|--------------|-------------| | https?://host.tld/repo | Not Set | Not Set | None | | https?://host.tld/repo | Not Set | Set | HTTP Basic | | https?://host.tld/repo | Set | Not Set | HTTP Basic | | https?://host.tld/repo | Set | Set | HTTP Basic | | All other formats | - | - | SSH |
For SSH authentication, the default username is "git" but will honour GIT_USERNAME if set.
If SSH_PRIVATE_KEY_PATH is set, an SSH private key will be read from that path and the SSH auth method will be configured with that key.
If SSH_KNOWN_HOSTS is not set, the SSH auth method will be configured to accept and log all host keys. Otherwise, host key checking will be performed as usual.
func WithEnvPrefix ¶
Types ¶
type CloneRepoOptions ¶
type DockerConfig ¶ added in v0.0.3
type DockerConfig configfile.ConfigFile
DockerConfig represents the Docker configuration file.
type LoggerFunc ¶
type LoggerFunc func(level notcodersdk.LogLevel, format string, args ...interface{})
type Options ¶
type Options struct { // SetupScript is the script to run before the init script. It runs as the // root user regardless of the user specified in the devcontainer.json file. // SetupScript is ran as the root user prior to the init script. It is used to // configure envbuilder dynamically during the runtime. e.g. specifying // whether to start systemd or tiny init for PID 1. SetupScript string // InitScript is the script to run to initialize the workspace. InitScript string // InitCommand is the command to run to initialize the workspace. InitCommand string // InitArgs are the arguments to pass to the init command. They are split // according to /bin/sh rules with https://github.com/kballard/go-shellquote. InitArgs string // CacheRepo is the name of the container registry to push the cache image to. // If this is empty, the cache will not be pushed. CacheRepo string // BaseImageCacheDir is the path to a directory where the base image can be // found. This should be a read-only directory solely mounted for the purpose // of caching the base image. BaseImageCacheDir string // LayerCacheDir is the path to a directory where built layers will be stored. // This spawns an in-memory registry to serve the layers from. LayerCacheDir string // DevcontainerDir is the path to the folder containing the devcontainer.json // file that will be used to build the workspace and can either be an absolute // path or a path relative to the workspace folder. If not provided, defaults // to `.devcontainer`. DevcontainerDir string // DevcontainerJSONPath is a path to a devcontainer.json file // that is either an absolute path or a path relative to // DevcontainerDir. This can be used in cases where one wants // to substitute an edited devcontainer.json file for the one // that exists in the repo. // If neither `DevcontainerDir` nor `DevcontainerJSONPath` is provided, // envbuilder will browse following directories to locate it: // 1. `.devcontainer/devcontainer.json` // 2. `.devcontainer.json` // 3. `.devcontainer/<folder>/devcontainer.json` DevcontainerJSONPath string // DockerfilePath is the relative path to the Dockerfile that will be used to // build the workspace. This is an alternative to using a devcontainer that // some might find simpler. DockerfilePath string // BuildContextPath can be specified when a DockerfilePath is specified // outside the base WorkspaceFolder. This path MUST be relative to the // WorkspaceFolder path into which the repo is cloned. BuildContextPath string // CacheTTLDays is the number of days to use cached layers before expiring // them. Defaults to 7 days. CacheTTLDays int64 // DockerConfigBase64 is the base64 encoded Docker config file that will be // used to pull images from private container registries. DockerConfigBase64 string // FallbackImage specifies an alternative image to use when neither an image // is declared in the devcontainer.json file nor a Dockerfile is present. If // there's a build failure (from a faulty Dockerfile) or a misconfiguration, // this image will be the substitute. Set ExitOnBuildFailure to true to halt // the container if the build faces an issue. FallbackImage string // ExitOnBuildFailure terminates the container upon a build failure. This is // handy when preferring the FALLBACK_IMAGE in cases where no // devcontainer.json or image is provided. However, it ensures that the // container stops if the build process encounters an error. ExitOnBuildFailure bool // ForceSafe ignores any filesystem safety checks. This could cause serious // harm to your system! This is used in cases where bypass is needed to // unblock customers. ForceSafe bool // Insecure bypasses TLS verification when cloning and pulling from container // registries. Insecure bool // IgnorePaths is the comma separated list of paths to ignore when building // the workspace. IgnorePaths []string // SkipRebuild skips building if the MagicFile exists. This is used to skip // building when a container is restarting. e.g. docker stop -> docker start // This value can always be set to true - even if the container is being // started for the first time. SkipRebuild bool // GitURL is the URL of the Git repository to clone. This is optional. GitURL string // GitCloneDepth is the depth to use when cloning the Git repository. GitCloneDepth int64 // GitCloneSingleBranch clone only a single branch of the Git repository. GitCloneSingleBranch bool // GitUsername is the username to use for Git authentication. This is // optional. GitUsername string // GitPassword is the password to use for Git authentication. This is // optional. GitPassword string // GitSSHPrivateKeyPath is the path to an SSH private key to be used for // Git authentication. GitSSHPrivateKeyPath string // GitHTTPProxyURL is the URL for the HTTP proxy. This is optional. GitHTTPProxyURL string // WorkspaceFolder is the path to the workspace folder that will be built. // This is optional. WorkspaceFolder string // SSLCertBase64 is the content of an SSL cert file. This is useful for // self-signed certificates. SSLCertBase64 string // ExportEnvFile is the optional file path to a .env file where envbuilder // will dump environment variables from devcontainer.json and the built // container image. ExportEnvFile string // PostStartScriptPath is the path to a script that will be created by // envbuilder based on the postStartCommand in devcontainer.json, if any is // specified (otherwise the script is not created). If this is set, the // specified InitCommand should check for the presence of this script and // execute it after successful startup. PostStartScriptPath string // Logger is the logger to use for all operations. Logger LoggerFunc // Filesystem is the filesystem to use for all operations. Defaults to the // host filesystem. Filesystem billy.Filesystem // These options are specifically used when envbuilder is invoked as part of a // Coder workspace. // Revert to `*url.URL` once https://github.com/coder/serpent/issues/14 is fixed. CoderAgentURL string // CoderAgentToken is the authentication token for a Coder agent. CoderAgentToken string // CoderAgentSubsystem is the Coder agent subsystems to report when forwarding // logs. The envbuilder subsystem is always included. CoderAgentSubsystem []string // PushImage is a flag to determine if the image should be pushed to the // container registry. This option implies reproducible builds. PushImage bool // GetCachedImage is a flag to determine if the cached image is available, // and if it is, to return it. GetCachedImage bool }
Options contains the configuration for the envbuilder.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
internal
|
|
notcodersdk
Package notcodersdk contains manually-vendored code from github.com/coder/coder/v2/codersdk.
|
Package notcodersdk contains manually-vendored code from github.com/coder/coder/v2/codersdk. |
scripts
|
|
testutil
|
|