Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertEnv(env map[string]string) []string
- func ConvertFromEnv(env []string) map[string]string
- func ConvertStringToHumanFriendly(str string) string
- func ConvertStringToMachineFriendly(str string) string
- func ConvertToMapOfStrings(m map[string]interface{}) map[string]string
- func FileExists(file string) bool
- func GetFullPath(path string) string
- func IsExitError(err error) bool
- func IsURL(s string) bool
- func LastLine(r io.Reader) (l string)
- func MapKeys(m interface{}) (keys []string)
- func MustGetUserHomeDir() string
- func MustGetwd() string
- func ReadEnvFile(r io.ReadCloser) (map[string]string, error)
- func RenderString(tmpl string, variables map[string]interface{}) (string, error)
- type Binary
- type Container
- type EnvFileOpts
- type Envfile
- type ModifyEnv
Constants ¶
const REPLACE_CHAR_DEFAULT = " "
Variables ¶
var ErrInvalidOptionsEnvFile = errors.New("invalid options on envfile")
Functions ¶
func ConvertEnv ¶
ConvertEnv converts map representing the environment to array of strings in the form "key=value"
func ConvertFromEnv ¶
ConvertFromEnv takes a string array and coverts it to a map of strings since an env variable can only really be a string it's safe to convert to string and not interface downstream programs need to cast values to what they expect
func ConvertStringToHumanFriendly ¶
ConvertStringToHumanFriendly takes a ConvertStringToMachineFriendly generated string and and converts it back to its original human friendly form
func ConvertStringToMachineFriendly ¶
ConvertStringToMachineFriendly takes astring and replaces any occurrence of non machine friendly chars with machine friendly ones
func ConvertToMapOfStrings ¶
ConvertToMapOfStrings converts map of interfaces to map of strings
func IsExitError ¶
IsExitError checks if given error is an instance of exec.ExitError
func MustGetUserHomeDir ¶
func MustGetUserHomeDir() string
MustGetUserHomeDir returns current working directory. Panics is os.UserHomeDir() returns error
func MustGetwd ¶
func MustGetwd() string
MustGetwd returns current working directory. Panics is os.Getwd() returns error
func ReadEnvFile ¶
func ReadEnvFile(r io.ReadCloser) (map[string]string, error)
ReadEnvFile reads env file inv `k=v` format
Types ¶
type Binary ¶
type Binary struct {
// IsContainer marks the binary as the container native implementation
IsContainer bool `jsonschema:"-"`
// Bin is the name of the executable to run
// it must exist on the path
// If using a default mvdn.sh context then
// ensure it is on your path as symlink if you are only using aliases.
Bin string `mapstructure:"bin" yaml:"bin" json:"bin"`
Args []string `mapstructure:"args" yaml:"args,omitempty" json:"args,omitempty"`
// contains filtered or unexported fields
}
Binary is a structure for storing binary file path and arguments that should be passed on binary's invocation
func (*Binary) BuildArgsWithEnvFile ¶
BuildArgsWithEnvFile returns all args with correctly placed --env-file parameter for context binary
func (*Binary) WithBaseArgs ¶
func (*Binary) WithContainerArgs ¶
func (*Binary) WithShellArgs ¶
type Container ¶
type Container struct {
// Name is the name of the container
//
// can be specified in the following formats
//
// - <image-name> (Same as using <image-name> with the latest tag)
//
// - <image-name>:<tag>
//
// - <image-name>@<digest>
//
// If the known runtime is podman it should include the registry domain
// e.g. `docker.io/alpine:latest`
Name string `mapstructure:"name" yaml:"name" json:"name"`
// Entrypoint Overwrites the default ENTRYPOINT of the image
Entrypoint string `mapstructure:"entrypoint" yaml:"entrypoint,omitempty" json:"entrypoint,omitempty"`
// EnableDinD mounts the docker sock...
//
// >highly discouraged
EnableDinD bool `mapstructure:"enable_dind" yaml:"enable_dind,omitempty" json:"enable_dind,omitempty"`
// ContainerArgs are additional args used for the container supplied by the user
//
// e.g. dcoker run (TASKCTL_ARGS...) (CONTAINER_ARGS...) image (command)
// The internals will strip out any unwanted/forbidden args
//
// Args like the switch --privileged and the --volume|-v flag with the value of /var/run/docker.sock:/var/run/docker.sock
// will be removed.
ContainerArgs []string `mapstructure:"container_args" yaml:"container_args,omitempty" json:"container_args,omitempty"`
// Shell will be used to run the command in a specific shell on the container
//
// Must exist in the container
Shell string `mapstructure:"shell" yaml:"shell,omitempty" json:"shell,omitempty"`
// Args are additional args to pass to the shell if provided
//
// // e.g. dcoker run (TASKCTL_ARGS...) (CONTAINER_ARGS...) image (shell) (SHELL_ARGS...) (command)
ShellArgs []string `mapstructure:"shell_args" yaml:"shell_args,omitempty" json:"shell_args,omitempty"`
}
Container is the specific context for containers only available to docker API compliant implementations
e.g. docker and podman
The aim is to remove some of the boilerplate away from the existing more generic context and introduce a specific context for tasks run in containers.
type Envfile ¶
type Envfile struct {
// Generate will toggle the creation of the envFile
// this "envFile" is only used in executables of type `docker|podman`
Generate bool `mapstructure:"generate" yaml:"generate,omitempty" json:"generate,omitempty"`
// list of variables to be excluded
// from the injection into container runtimes
//
// Currently this is based on a prefix
//
// Example:
// HOME=foo,HOMELAB=bar
//
// Both of these will be skipped
Exclude []string `mapstructure:"exclude" yaml:"exclude,omitempty" json:"exclude,omitempty"`
Include []string `mapstructure:"include" yaml:"include,omitempty" json:"include,omitempty"`
// Path is generated using task name and current timestamp
// TODO: include additional graph info about the execution
// e.g. owning pipeline (if any) execution number
Path string `mapstructure:"path" yaml:"path,omitempty" json:"path,omitempty"`
ReplaceChar string `mapstructure:"replace_char" yaml:"replace_char,omitempty" json:"replace_char,omitempty"`
Quote bool `mapstructure:"quote" yaml:"quote,omitempty" json:"quote,omitempty"`
// Modify specifies the modifications to make to each env var and whether it meets the criteria
// example:
// - pattern: "^(?P<keyword>TF_VAR_)(?P<varname>.*)"
// operation: lower
// the inputs are validated at task/pipeline build time and will fail if the
// <keyword> and <varname> sub expressions are not present in the `pattern`
Modify []ModifyEnv `mapstructure:"modify" yaml:"modify,omitempty" json:"modify,omitempty"`
// defaults to .taskctl in the current directory
// again this should be hidden from the user...
GeneratedDir string `mapstructure:"generated_dir" yaml:"generated_dir,omitempty" json:"generated_dir,omitempty"`
}
Envile is a structure for storing the information required to generate an envfile which can be consumed by the specified binary
func NewEnvFile ¶
func NewEnvFile(opts ...EnvFileOpts) *Envfile
NewEnvFile creates a new instance of the EnvFile initializes it with some defaults