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 ¶ added in v0.7.8
func CreateDockerfile(buildRoot string, fnOnCreate ciutil.OnWriterFunc, ignoreFiles []string) error
CreateDockerfile creates a dockerfile in the buildRoot
func DebugDockerfile ¶ added in v0.7.8
DebugDockerfile debugs the given dockerfile
func DoCreateDockerIgnore ¶ added in v0.9.1
DoCreateDockerIgnore creates a dockerignore file in the buildRoot
func GetCmdCombinationOperator ¶ added in v0.1.2
GetCmdCombinationOperator represents the operator to combine commands in the OS Shell. In Linux, that would be '&&'
func GetContainerName ¶ added in v0.9.0
GetContainerName returns the name of the container with the suffix
func GetDockerIgnoreWriterFunc ¶ added in v0.7.7
func GetDockerIgnoreWriterFunc(ignoreFiles []string) ciutil.OnWriterFunc
GetDockerIgnoreWriterFunc returns a WriteFunc that writes the .dockerignore file
func GetImageBuildOptions ¶ added in v0.1.2
func GetImageBuildOptions(buildSettings *BuildSettings) *types.ImageBuildOptions
GetImageBuildOptions retrieves the image build options given the build settings
func OnClient ¶ added in v0.4.1
func OnClient(ctx context.Context, fnCreateDockerClient CreateDockerClientFunc, fnOnClient OnClientFunc, log logger.Log) error
OnClient releases client resources after execution
Types ¶
type BuildID ¶ added in v0.9.0
type BuildID string
BuildID represents the identification of a given build.
func GetTargetBuildID ¶ added in v0.9.0
GetTargetBuildID returns the buildID with the suffix appended
type BuildOptions ¶ added in v0.3.4
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 ¶ added in v0.9.0
func GetBuildOptionsFunc(buildRoot string) *BuildOptions
GetBuildOptionsFunc returns the default build options for the given buildRoot
func NewBuildOptions ¶ added in v0.3.4
func NewBuildOptions(buildRoot string, maxBuildTime time.Duration) *BuildOptions
NewBuildOptions creates a new set of build options
func NewDefaultBuildOptions ¶ added in v0.8.1
func NewDefaultBuildOptions(buildRoot string) *BuildOptions
NewDefaultBuildOptions creates a new set of build options
type BuildSettings ¶ added in v0.9.5
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 ¶ added in v0.9.5
func NewBuildSettings() *BuildSettings
NewBuildSettings creates a new environment
type CreateDockerClientFunc ¶ added in v0.4.1
CreateDockerClientFunc creates a new docker client
type DockerCliExecFunc ¶ added in v0.9.0
DockerCliExecFunc represents the functor to return after a pipeline run
func BuildDockerImage ¶ added in v0.9.0
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 ¶ added in v0.9.0
func RunOnClientFunc(createDockerClientFunc CreateDockerClientFunc, fnOnClient OnClientFunc) DockerCliExecFunc
RunOnClientFunc runs the given OnClientFunc on the system
type OnBuildContextFunc ¶ added in v0.9.0
type OnBuildContextFunc func(buildOptions *BuildOptions) (DockerCliExecFunc, error)
OnBuildContextFunc represents a function to act on the given build context
func GetBuildContextFunc ¶ added in v0.9.0
func GetBuildContextFunc(createDockerClientFunc CreateDockerClientFunc, imageBuildOptions *types.ImageBuildOptions, result *types.BuildResult) OnBuildContextFunc
GetBuildContextFunc represents the function to return the build context
type OnBuildOptionsFunc ¶ added in v0.9.0
type OnBuildOptionsFunc func(buildRoot string) *BuildOptions
OnBuildOptionsFunc represents a function to build options
type OnClientFunc ¶ added in v0.4.1
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 ¶ added in v0.4.1
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 ¶ added in v0.8.0
func OnNewContainer(containerName string, containerConfig *container.Config, fnOnContainer OnContainerFunc) OnClientFunc
OnNewContainer creates and removes a container from a given Image
func PullImage ¶ added in v0.7.0
func PullImage(image string, options *types.ImagePullOptions) OnClientFunc
PullImage pulls a given image from a docker registry
func PushImage ¶ added in v0.7.0
func PushImage(image string, options *types.ImagePushOptions) OnClientFunc
PushImage pushes a given image to a docker registry
type OnContainerFunc ¶ added in v0.4.1
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 ¶ added in v0.4.1
CopyFromContainer copies files from the container to the local directory
func OnContainerExec ¶ added in v0.8.0
func OnContainerExec(config *types.ExecConfig, options *types.ExecStartCheck, execTimeout time.Duration) OnContainerFunc
OnContainerExec executes commands inside a given container
func OnContainerRun ¶ added in v0.8.0
func OnContainerRun(fnExec OnContainerFunc) OnContainerFunc
OnContainerRun starts and stops a given container
func RemoveIfExists ¶ added in v0.4.2
func RemoveIfExists(options *types.ContainerRemoveOptions) OnContainerFunc
RemoveIfExists removes a container if it already exists