Documentation ¶
Index ¶
- func Build(context *G3opsContext, container *Container) error
- func BuildExists(version string, context *G3opsContext) bool
- func CommitChanges(repoDir string, files []string, message string, branchName string, ...)
- func CreateMemFs() *afero.Afero
- func CreateOsFs() *afero.Afero
- func CurrentBranch(repoDir string) string
- func CurrentSha(repoDir string) string
- func Deploy(context *G3opsContext, container *Container, version string, env string) error
- func InitWorkflows(fs *afero.Afero, context *G3opsContext)
- func PrintYaml(code string)
- func UpdateWorkflows(fs *afero.Afero, context *G3opsContext)
- func ValidateArgs(argValidators []ArgValidator) cobra.PositionalArgs
- func ValidateWorkflows(fs *afero.Afero, context *G3opsContext) error
- type ArgValidator
- type Clock
- type CommandExecutor
- type Container
- type ExecOptions
- type Executor
- type G3opsBuild
- type G3opsBuildCatalog
- type G3opsConfig
- type G3opsContext
- type G3opsDeployment
- type G3opsDeploymentCatalog
- type G3opsManifest
- type G3opsService
- type SystemClock
- type ValidationResult
- type WorkflowDefinition
- type WorkflowValidator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
func Build(context *G3opsContext, container *Container) error
Build - creates a build for the service and updates the catalog
func BuildExists ¶
func BuildExists(version string, context *G3opsContext) bool
BuildExists - returns whether a build already exists for the given version name and service
func CommitChanges ¶
func CommitChanges(repoDir string, files []string, message string, branchName string, g3ops *G3opsContext, executor Executor)
CommitChanges - commits and pushes changes to the filesystem
func CreateMemFs ¶
CreateMemFs - creates an in-memory Afero instance for testing
func CurrentBranch ¶
CurrentBranch - returns the current git branch
func CurrentSha ¶
CurrentSha - returns the short form version of git rev-parse HEAD
func Deploy ¶
func Deploy(context *G3opsContext, container *Container, version string, env string) error
func InitWorkflows ¶
func InitWorkflows(fs *afero.Afero, context *G3opsContext)
InitWorkflows - copies g3ops workflow sources to context directory
Example ¶
fs, context := newTestContext() fs.WriteFile(".g3ops/workflows/common/git.libsonnet", []byte(""), 0644) InitWorkflows(fs, context)
Output: update .g3ops/workflows/common/git.libsonnet create .g3ops/workflows/g3ops/config.libsonnet create .g3ops/workflows/g3ops/template.jsonnet
func PrintYaml ¶
func PrintYaml(code string)
PrintYaml - highlights the given code if pygmentize is available Inspired by https://github.com/pksunkara/pygments
func UpdateWorkflows ¶
func UpdateWorkflows(fs *afero.Afero, context *G3opsContext)
UpdateWorkflows - update workflow files for the given context
func ValidateArgs ¶
func ValidateArgs(argValidators []ArgValidator) cobra.PositionalArgs
ValidateArgs - Returns a function which validates all the given arguments
func ValidateWorkflows ¶
func ValidateWorkflows(fs *afero.Afero, context *G3opsContext) error
ValidateWorkflows - returns an error if the workflows are out of date
Example ¶
fs, context := newTestContext() // invalid template fs.WriteFile(".g3ops/workflows/test.jsonnet", []byte(invalidTemplate), 0644) ValidateWorkflows(fs, context) // valid template, missing workflow fs.WriteFile(".g3ops/workflows/test.jsonnet", []byte(exampleTemplate), 0644) ValidateWorkflows(fs, context) // valid template, out of date workflow fs.WriteFile(".github/workflows/test.yml", []byte("incorrect content"), 0644) ValidateWorkflows(fs, context) // valid template, up to date workflow fs.WriteFile(".github/workflows/test.yml", []byte(exampleWorkflow), 0644) ValidateWorkflows(fs, context)
Output: Checking �[1mtest�[0m ... �[1;31mFAILED�[0m Workflow failed schema validation: ► (root): jobs is required Checking �[1mtest�[0m ... �[1;31mFAILED�[0m Workflow missing for "test" (expected workflow at .github/workflows/test.yml) ► Run "g3ops workflow generate" to update Checking �[1mtest�[0m ... �[1;31mFAILED�[0m Content is out of date for "test" (.github/workflows/test.yml) ► Run "g3ops workflow generate" to update Checking �[1mtest�[0m ... �[1;32mOK�[0m
Types ¶
type ArgValidator ¶
ArgValidator - function which returns an error if the argument is invalid
type CommandExecutor ¶
type CommandExecutor struct{}
CommandExecutor - executes commands
func NewCommandExecutor ¶
func NewCommandExecutor() *CommandExecutor
NewCommandExecutor - returns a concrete CommandExecutor
func (*CommandExecutor) ExecCommand ¶
func (executor *CommandExecutor) ExecCommand(command string, opts ExecOptions)
ExecCommand - executes a command
type Container ¶
type Container struct { FileSystem *afero.Afero Executor Executor GitHubService services.GitHubService Clock Clock Logger *io.Logger }
Container - DI container
func NewContainer ¶
func NewContainer() *Container
NewContainer - creates a new production container instance. Use NewTestContainer for testing.
type ExecOptions ¶
ExecOptions - options for executing a command
type Executor ¶
type Executor interface {
ExecCommand(command string, opts ExecOptions)
}
Executor - adapter for executing commands
type G3opsBuild ¶
type G3opsBuild struct { ID string // e.g. 0c8bf7ef-2291-4dba-9e8e-f3d01093fd86 Version string // e.g. 0.2.22 PackageImage string `yaml:"packageImage"` // image digest of the config image //BuildSha string `yaml:"buildSha"` // git build sha, e.g. cc87c1c //ImageTag string `yaml:"imageTag"` // specified by user, but could be based on version + id, e.g. 0.2.22-0c8bf7ef-2291-4dba-9e8e-f3d01093fd86 Timestamp time.Time // e.g. '2020-06-21T13:43:29.694Z' }
G3opsBuild - represents information about a build
func FindBuild ¶
func FindBuild(version string, context *G3opsContext) *G3opsBuild
FindBuild - finds and returns the build (if it exists)
func (G3opsBuild) FormatTimestamp ¶
func (b G3opsBuild) FormatTimestamp() string
FormatTimestamp - human readable string
type G3opsBuildCatalog ¶
type G3opsBuildCatalog struct {
Builds []G3opsBuild
}
G3opsBuildCatalog - represents a build catalog for a service
func LoadBuildCatalog ¶
func LoadBuildCatalog(context *G3opsContext) G3opsBuildCatalog
LoadBuildCatalog - loads a build catalog
type G3opsConfig ¶
type G3opsConfig struct { Name string GitHubDir string `yaml:"githubDir"` //Environments map[string]g3opsEnvironmentConfig //Services map[string]g3opsServiceConfig //Ci g3opsCiConfig Repo string Build g3opsBuildConfig Deploy struct { Command string } }
G3opsConfig - type of current g3ops context
func GetContextConfig ¶
func GetContextConfig(fs *afero.Afero, path string) (*G3opsConfig, error)
GetContextConfig - finds and returns the G3opsConfig
type G3opsContext ¶
type G3opsContext struct { Dir string ProjectDir string ConfigPath string GitHubDir string Config *G3opsConfig DryRun bool RepoID services.GitHubRepoID Manifest *G3opsManifest }
G3opsContext - current command context
func CloneTempRepo ¶
func CloneTempRepo(fs *afero.Afero, executor Executor, g3ops *G3opsContext) (string, *G3opsContext)
CloneTempRepo - clones a shallow copy into a temp directory. Returns the directory path and the context for the new repo.
func GetContext ¶
GetContext - returns the current command context
func NewContext ¶
NewContext - returns a context for the given config
func (*G3opsContext) GetManifest ¶
func (context *G3opsContext) GetManifest(fs *afero.Afero) (G3opsManifest, error)
GetManifest - returns the manifest (if it exists)
type G3opsDeployment ¶
func GetLatestDeployment ¶
func GetLatestDeployment(environment string, context *G3opsContext) *G3opsDeployment
GetLatestDeployment - returns the latest deployment (if there is one)
type G3opsDeploymentCatalog ¶
type G3opsDeploymentCatalog struct {
Deployments []G3opsDeployment
}
func LoadDeploymentsCatalog ¶
func LoadDeploymentsCatalog(context *G3opsContext, environment string) G3opsDeploymentCatalog
LoadDeploymentsCatalog - loads deployment catalog for the given environment
type G3opsManifest ¶
type G3opsManifest struct { Version string Environments map[string]struct { Host string Version string } }
G3opsManifest - manifest with build information for github releases
type G3opsService ¶
G3opsService - type of current g3ops context
type SystemClock ¶
type SystemClock struct{}
SystemClock - a Clock instance using the system time
func NewSystemClock ¶
func NewSystemClock() *SystemClock
NewSystemClock - returns a new concrete clock instance
type ValidationResult ¶
ValidationResult - validate result
type WorkflowDefinition ¶
WorkflowDefinition - definitoin for a workflow defined by a G3ops template
func GetWorkflowDefinitions ¶
func GetWorkflowDefinitions(fs *afero.Afero, context *G3opsContext) []*WorkflowDefinition
GetWorkflowDefinitions - get workflow definitions for the given context
type WorkflowValidator ¶
type WorkflowValidator struct {
// contains filtered or unexported fields
}
WorkflowValidator - validates a workflow definition
func NewWorkflowValidator ¶
func NewWorkflowValidator(fs *afero.Afero) *WorkflowValidator
NewWorkflowValidator - creates a new validator for the given filesystem
func (*WorkflowValidator) ValidateContent ¶
func (validator *WorkflowValidator) ValidateContent(definition *WorkflowDefinition) ValidationResult
ValidateContent - validates the content at the destination in the definition is up to date
func (*WorkflowValidator) ValidateSchema ¶
func (validator *WorkflowValidator) ValidateSchema(definition *WorkflowDefinition) ValidationResult
ValidateSchema - validates the template for the definition generates a valid workflow