Documentation ¶
Overview ¶
Package service holds all docker-bakery business logic and splits them into services
Index ¶
- func BuildDockerfile(dockerfile, scope string, shouldTriggerDependantBuilds bool) error
- func DumpLatestVersions(fileName, excludeDirsPattern string) error
- func ExecuteDockerCommand(command, dockerfile, scope string, postCmdListener PostCommandListener, ...) error
- func FillTemplate(inputFile, outputFile string) error
- func GenerateImagesTree(previousImageName string, recursive, skipExistingDirectories bool, ...) error
- func GetGitUserEmail() (string, error)
- func GetGitUserName() (string, error)
- func GetLatestVersions() (map[string]*semver.Version, error)
- func InitConfiguration(configFile, rootDir string, additionalProperties []string) error
- func PrintReport()
- func PushDockerImages(dockerfile, scope string, shouldTriggerDependantBuilds bool) error
- func PushTags() error
- func TagVersion(imageName, version string) error
- type CommandResult
- type Commands
- type Config
- type DockerHierarchy
- type DockerImage
- type DockerImageParser
- type DockerTreeItem
- type PostCommandListener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDockerfile ¶
BuildDockerfile uses build command defined in the config to build provided dockerfile and potentially its dependants. Prints the build report at the end of processing.
func DumpLatestVersions ¶ added in v1.1.0
DumpLatestVersions saves images with their latest version in json format to file. Optionally it can exclude images from provided directories.
func ExecuteDockerCommand ¶
func ExecuteDockerCommand(command, dockerfile, scope string, postCmdListener PostCommandListener, shouldTriggerDependantBuilds bool) error
ExecuteDockerCommand build/push docker file in the following steps: - obtain current image info (name, version, dependants) - get next version based on git tags according to the change scope - updates dynamic config properties based on gathered info - templates docker command - execute already filled template of the build/push command - depending on the shouldTriggerDependantBuilds flag executes child builds if there are any
func FillTemplate ¶
FillTemplate takes the input Dockerfile.template and fills it to deliver Dockerfile that will be used to build the image. Uses properties defined in the config file + dynamic properties for filling the template. Dynamic properties are prepared automatically after analysing entire image hierarchy.
func GenerateImagesTree ¶ added in v1.4.0
func GenerateImagesTree(previousImageName string, recursive, skipExistingDirectories bool, nameReplacements []string) error
GenerateImagesTree generate ancestors for a given image with a new parent image
func GetGitUserEmail ¶ added in v1.0.7
GetGitUserEmail returns git user email obtained from configuration or error if it could not be obtained
func GetGitUserName ¶ added in v1.0.7
GetGitUserName returns git user name obtained from configuration or error if it could not be obtained
func GetLatestVersions ¶
GetLatestVersions returns map with latest versions of the images based on git remote tags. Image name is the key and latest version is the value.
func InitConfiguration ¶
InitConfiguration is called before execution of other commands, parses config and gathers docker image dependencies/hierarchy
func PrintReport ¶
func PrintReport()
PrintReport prints the report with processed images and its versions.
func PushDockerImages ¶
PushDockerImages uses push command defined in the config to build provided dockerfile and potentially its dependants. Prints the build report at the end of processing.
func TagVersion ¶
TagVersion creates new tag for the image with the given version.
Types ¶
type CommandResult ¶
type CommandResult struct { Name string DockerfileDir string NextVersion string CurrentVersion string }
CommandResult is an outcome of the docker command
type Commands ¶
type Commands struct { DefaultBuildCommand string `json:"defaultBuildCommand"` DefaultPushCommand string `json:"defaultPushCommand"` }
Commands is used as part of the config to contain template of build and push commands
type Config ¶
type Config struct { Properties map[string]string `json:"properties"` Commands Commands `json:"commands"` RootDir string `json:"rootDir"` Verbose bool `json:"verbose"` AutoBuildExcludes []string `json:"autoBuildExcludes"` ReportFileName string `json:"reportFileName"` }
Config corresponds to the config structure in json file
func ReadConfig ¶
ReadConfig reads configuration file from provided path and returns it as an object.
func (*Config) PrintProperties ¶
func (cfg *Config) PrintProperties()
PrintProperties prints all properties available in the config (along with the dynamic ones).
func (*Config) UpdateDynamicProperties ¶
func (cfg *Config) UpdateDynamicProperties(dockerImg *DockerImage)
UpdateDynamicProperties updates config object state with the corresponding values of all dynamic properties. Called in every cycle of executing docker command.
type DockerHierarchy ¶
type DockerHierarchy interface { // Analyzes docker files structure under given directory and constructs entire hierarchy AnalyzeStructure(string, map[string]*semver.Version) error // Adds docker image to the hierarchy based on the docker image parent AddImage(dockerImg *DockerImage) // GetImageByName returns docker image by its name. Image can be obtained after entire hierarchy has been analyzed GetImageByName(imageName string) *DockerImage // Returns map with docker images where key is the short docker image name and // the value is a slice of dependent images GetImagesWithDependants() map[string][]*DockerImage // Returns map with docker images where key is the short docker image name and // the value is docker image object GetImages() map[string]*DockerImage // Prints gathered hierarchy under a given root name PrintImageHierarchy(string) }
DockerHierarchy represents hierarchy of docker images
func NewDockerHierarchy ¶
func NewDockerHierarchy() DockerHierarchy
NewDockerHierarchy initializes new docker hierarchy.
type DockerImage ¶
type DockerImage struct { Name string DockerfileDir string DockerfilePath string DependsOnLong string DependsOnShort string DependsOnVersion string // contains filtered or unexported fields }
DockerImage represents docker image with its parent
func (*DockerImage) CalculateNextVersion ¶ added in v1.0.7
func (di *DockerImage) CalculateNextVersion(scope string)
CalculateNextVersion returns next version of the docker image based on the provided scope (major/minor/patch). If image had no previous version the the 0.0.0 is used as a base line and appropriately updated with regards to the provided scope.
func (*DockerImage) GetLatestVersion ¶ added in v1.0.7
func (di *DockerImage) GetLatestVersion() *semver.Version
GetLatestVersion returns latest version of the docker image or "0.0.0" if there was no version defined
func (*DockerImage) GetLatestVersionString ¶ added in v1.0.7
func (di *DockerImage) GetLatestVersionString() string
GetLatestVersionString returns the latest version (as a string) of the docker image or "0.0.0" if there was no version defined
func (*DockerImage) GetNextVersion ¶ added in v1.0.7
func (di *DockerImage) GetNextVersion() semver.Version
GetNextVersion returns already calculated next version of the docker image.
func (*DockerImage) GetNextVersionString ¶ added in v1.0.7
func (di *DockerImage) GetNextVersionString() string
GetNextVersionString returns already calculated next version (as a string) of the docker image.
type DockerImageParser ¶
type DockerImageParser interface { ParseDockerfile(string) (*DockerImage, error) ExtractDockerFileDir(string) (string, error) ExtractImageName(string) (string, error) }
DockerImageParser provides functionality related to parsing docker files
func NewDockerImageParser ¶
func NewDockerImageParser() DockerImageParser
NewDockerImageParser initializes new docker image parser.
type DockerTreeItem ¶
type DockerTreeItem struct { ID string ParentID string TreeItem *gotree.GTStructure }
DockerTreeItem used in graphical representation of the image hierarchy
type PostCommandListener ¶
type PostCommandListener interface {
OnPostCommand(result *CommandResult)
}
PostCommandListener is an interface that allows to plugin just after docker command is executed and before any commands on children are executed
func NewPostPushListener ¶
func NewPostPushListener() PostCommandListener
NewPostPushListener initializes new PostPushListener.