Documentation
¶
Overview ¶
Copyright (C) 2019 MalvaHQ
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Index ¶
- Constants
- Variables
- func CreateDockerfile(buildRoot string, fnOnCreate ciutil.OnWriterFunc, ignoreFiles []string) error
- func DebugDockerfile(buildRoot string) func(log logger.Log) error
- func DoCreateDockerIgnore(buildRoot string, ignoreFiles []string) error
- func GetCmdCombinationOperator() (string, error)
- func GetContainerName(buildID BuildID, suffix string) string
- func GetDockerIgnoreWriterFunc(ignoreFiles []string) ciutil.OnWriterFunc
- func GetImageBuildOptions(buildSettings *BuildSettings) *types.ImageBuildOptions
- func OnClient(ctx context.Context, fnCreateDockerClient CreateDockerClientFunc, ...) error
- type BuildID
- type BuildOptions
- type BuildSettings
- type CreateDockerClientFunc
- type DockerCliExecFunc
- type OnBuildContextFunc
- type OnBuildOptionsFunc
- type OnClientFunc
- func BuildImage(imageBuildOptions *types.ImageBuildOptions, buildOptions *BuildOptions, ...) (OnClientFunc, error)
- func CopyFromImage(imageID string, srcPath string, w io.Writer, containerName string, ...) OnClientFunc
- func OnNewContainer(containerName string, containerConfig *container.Config, ...) OnClientFunc
- func PullImage(image string, options *types.ImagePullOptions) OnClientFunc
- func PushImage(image string, options *types.ImagePushOptions) OnClientFunc
- type OnContainerFunc
- func CopyFromContainer(srcPath string, w io.Writer, copyDuration time.Duration) OnContainerFunc
- func OnContainerExec(config *types.ExecConfig, options *types.ExecStartCheck, ...) OnContainerFunc
- func OnContainerRun(fnExec OnContainerFunc) OnContainerFunc
- func RemoveIfExists(options *types.ContainerRemoveOptions) OnContainerFunc
Constants ¶
const ( // DefaultCPUPeriod represents the default CPU build for options // See: https://docs.docker.com/engine/reference/run/#cpu-period-constraint DefaultCPUPeriod = 100000 // CPUQuotaUnit represents the quota for 1 cpu // See: https://docs.docker.com/engine/reference/run/#cpu-quota-constraint CPUQuotaUnit = 100000 // See: https://docs.docker.com/engine/reference/run/#cpu-share-constraint DefaultCPUShare = 1024 )
const (
// DefaultDockerfile represents the name of the default Dockerfile
DefaultDockerfile = "Dockerfile"
)
const ( // DefaultMaxBuildTime represents the default maximum build time DefaultMaxBuildTime = (1<<63 - 1) * time.Nanosecond // Almost infinite duration )
const (
// DockerIgnorefile represents the default .dockerignore file
DockerIgnorefile = ".dockerignore"
)
const (
// LinuxCombinationOperator represents the AND operator
LinuxCombinationOperator = " && "
)
Variables ¶
var ( // DefaultIgnoreFiles lists the default list of files to be ignored DefaultIgnoreFiles = []string{ DefaultDockerfile, DockerIgnorefile, } )
var ( // ErrNonZeroExitCode is an exception / error when the exit code is not zero ErrNonZeroExitCode = errors.New("Exit Code returned is not zero") )
var ( // ErrOSNotSupported does not support OS ErrOSNotSupported = errors.New("OS Not Supported for combination operator for commands on Shell") )
Functions ¶
func CreateDockerfile ¶
func CreateDockerfile(buildRoot string, fnOnCreate ciutil.OnWriterFunc, ignoreFiles []string) error
CreateDockerfile creates a dockerfile in the buildRoot
func DebugDockerfile ¶
DebugDockerfile debugs the given dockerfile
func DoCreateDockerIgnore ¶
DoCreateDockerIgnore creates a dockerignore file in the buildRoot
func GetCmdCombinationOperator ¶
GetCmdCombinationOperator represents the operator to combine commands in the OS Shell. In Linux, that would be '&&'
func GetContainerName ¶
GetContainerName returns the name of the container with the suffix
func GetDockerIgnoreWriterFunc ¶
func GetDockerIgnoreWriterFunc(ignoreFiles []string) ciutil.OnWriterFunc
GetDockerIgnoreWriterFunc returns a WriteFunc that writes the .dockerignore file
func GetImageBuildOptions ¶
func GetImageBuildOptions(buildSettings *BuildSettings) *types.ImageBuildOptions
GetImageBuildOptions retrieves the image build options given the build settings
func OnClient ¶
func OnClient(ctx context.Context, fnCreateDockerClient CreateDockerClientFunc, fnOnClient OnClientFunc, log logger.Log) error
OnClient releases client resources after execution
Types ¶
type BuildID ¶
type BuildID string
BuildID represents the identification of a given build.
func GetTargetBuildID ¶
GetTargetBuildID returns the buildID with the suffix appended
type BuildOptions ¶
type BuildOptions struct { // BuildRoot represents the root of the directory used as buildRoot BuildRoot string // MaxBuildTime represents the maximum time it takes to build MaxBuildTime time.Duration }
BuildOptions represents the options to build
func GetBuildOptionsFunc ¶
func GetBuildOptionsFunc(buildRoot string) *BuildOptions
GetBuildOptionsFunc returns the default build options for the given buildRoot
func NewBuildOptions ¶
func NewBuildOptions(buildRoot string, maxBuildTime time.Duration) *BuildOptions
NewBuildOptions creates a new set of build options
func NewDefaultBuildOptions ¶
func NewDefaultBuildOptions(buildRoot string) *BuildOptions
NewDefaultBuildOptions creates a new set of build options
type BuildSettings ¶
type BuildSettings struct { // BuildDirectory represents the base directory in which the build happens BuildDirectory string // CPUSetCPUs represents the CPUs in which this execution must happen. Eg: 0-3,0,1. // More Example: https://docs.docker.com/engine/reference/run/#cpuset-constraint CPUSetCPUs string // CPUSetMems represents the memory in which this execution must happen. Eg: 1,3. // Only effecitve on NUMA systems CPUSetMems string // https://docs.docker.com/engine/reference/run/#cpu-share-constraint CPUShares int64 }
BuildSettings represents the settings necessary for build environment
func NewBuildSettings ¶
func NewBuildSettings() *BuildSettings
NewBuildSettings creates a new environment
type CreateDockerClientFunc ¶
CreateDockerClientFunc creates a new docker client
type DockerCliExecFunc ¶
DockerCliExecFunc represents the functor to return after a pipeline run
func BuildDockerImage ¶
func BuildDockerImage(buildDirectory string, prefix string, fnCreateBuildContext ciutil.OnDirFunc, fnOnBuildOptions OnBuildOptionsFunc, fnOnBuildContext OnBuildContextFunc, fnPostProcess ciutil.OnDirFunc) DockerCliExecFunc
BuildDockerImage creates the temporary directory for buildContext, and builds a docker image from the same directory as a build context
func RunOnClientFunc ¶
func RunOnClientFunc(createDockerClientFunc CreateDockerClientFunc, fnOnClient OnClientFunc) DockerCliExecFunc
RunOnClientFunc runs the given OnClientFunc on the system
type OnBuildContextFunc ¶
type OnBuildContextFunc func(buildOptions *BuildOptions) (DockerCliExecFunc, error)
OnBuildContextFunc represents a function to act on the given build context
func GetBuildContextFunc ¶
func GetBuildContextFunc(createDockerClientFunc CreateDockerClientFunc, imageBuildOptions *types.ImageBuildOptions, result *types.BuildResult) OnBuildContextFunc
GetBuildContextFunc represents the function to return the build context
type OnBuildOptionsFunc ¶
type OnBuildOptionsFunc func(buildRoot string) *BuildOptions
OnBuildOptionsFunc represents a function to build options
type OnClientFunc ¶
OnClientFunc represents a function to act on a client
func BuildImage ¶
func BuildImage(imageBuildOptions *types.ImageBuildOptions, buildOptions *BuildOptions, result *types.BuildResult) (OnClientFunc, error)
BuildImage returns a OnClientFunc to create a new build image
func CopyFromImage ¶
func CopyFromImage(imageID string, srcPath string, w io.Writer, containerName string, copyDuration time.Duration) OnClientFunc
CopyFromImage copies a file from the source to the target
func OnNewContainer ¶
func OnNewContainer(containerName string, containerConfig *container.Config, fnOnContainer OnContainerFunc) OnClientFunc
OnNewContainer creates and removes a container from a given Image
func PullImage ¶
func PullImage(image string, options *types.ImagePullOptions) OnClientFunc
PullImage pulls a given image from a docker registry
func PushImage ¶
func PushImage(image string, options *types.ImagePushOptions) OnClientFunc
PushImage pushes a given image to a docker registry
type OnContainerFunc ¶
type OnContainerFunc func(ctx context.Context, cli *client.Client, containerID string, log logger.Log) error
OnContainerFunc represents a function to act on a given containerID
func CopyFromContainer ¶
CopyFromContainer copies files from the container to the local directory
func OnContainerExec ¶
func OnContainerExec(config *types.ExecConfig, options *types.ExecStartCheck, execTimeout time.Duration) OnContainerFunc
OnContainerExec executes commands inside a given container
func OnContainerRun ¶
func OnContainerRun(fnExec OnContainerFunc) OnContainerFunc
OnContainerRun starts and stops a given container
func RemoveIfExists ¶
func RemoveIfExists(options *types.ContainerRemoveOptions) OnContainerFunc
RemoveIfExists removes a container if it already exists