cidocker

package module
v0.9.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2020 License: AGPL-3.0 Imports: 18 Imported by: 9

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

View Source
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

	// DefaultCPUShare represents the default value of CPU share
	// See: https://docs.docker.com/engine/reference/run/#cpu-share-constraint
	DefaultCPUShare = 1024
)
View Source
const (
	// DefaultDockerfile represents the name of the default Dockerfile
	DefaultDockerfile = "Dockerfile"
)
View Source
const (
	// DefaultMaxBuildTime represents the default maximum build time
	DefaultMaxBuildTime = (1<<63 - 1) * time.Nanosecond // Almost infinite duration
)
View Source
const (
	// DockerIgnorefile represents the default .dockerignore file
	DockerIgnorefile = ".dockerignore"
)
View Source
const (
	// LinuxCombinationOperator represents the AND operator
	LinuxCombinationOperator = " && "
)

Variables

View Source
var (
	// DefaultIgnoreFiles lists the default list of files to be ignored
	DefaultIgnoreFiles = []string{
		DefaultDockerfile,
		DockerIgnorefile,
	}
)
View Source
var (
	// ErrNonZeroExitCode is an exception / error when the exit code is not zero
	ErrNonZeroExitCode = errors.New("Exit Code returned is not zero")
)
View Source
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

func DebugDockerfile(buildRoot string) func(log logger.Log) error

DebugDockerfile debugs the given dockerfile

func DoCreateDockerIgnore added in v0.9.1

func DoCreateDockerIgnore(buildRoot string, ignoreFiles []string) error

DoCreateDockerIgnore creates a dockerignore file in the buildRoot

func GetCmdCombinationOperator added in v0.1.2

func GetCmdCombinationOperator() (string, error)

GetCmdCombinationOperator represents the operator to combine commands in the OS Shell. In Linux, that would be '&&'

func GetContainerName added in v0.9.0

func GetContainerName(buildID BuildID, suffix string) string

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

func GetTargetBuildID(buildID BuildID, suffix string) BuildID

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

	// CPUShares represent the weight of CPU Share.
	// 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

type CreateDockerClientFunc func() (*client.Client, error)

CreateDockerClientFunc creates a new docker client

type DockerCliExecFunc added in v0.9.0

type DockerCliExecFunc func(ctx context.Context, log logger.Log) error

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

type OnClientFunc func(ctx context.Context, cli *client.Client, log logger.Log) error

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

func CopyFromContainer(srcPath string, w io.Writer, copyDuration time.Duration) OnContainerFunc

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

Directories

Path Synopsis
tar

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL