Documentation ¶
Overview ¶
Dbyml is a CLI tool to build a docker image with the arguments loaded from configs in yaml.
Usage ¶
The following command will generate a configuration file.
dbyml --init
The configuration file where the about image build is written.
dbyml
The options on image build can be written in the config. See https://github.com/git-ogawa/dbyml how to edit contents in config file.
Index ¶
- Constants
- func Centering(s string, w int) string
- func ConfigExists(path string) bool
- func ExecBuild(path string)
- func GetAuthBase64(username string, password string) string
- func GetBuildContext(dir string) (buf *bytes.Buffer)
- func GetBuildkitContext(dir string) (buf *bytes.Buffer)
- func IsExclude(file string, exclude []string) (bool, error)
- func MakeBuildkitToml(config *RegistryInfo) (string, error)
- func MakeTemplate(config *Configuration)
- func PrintCenter(s string, w int, padding string)
- func ReadAll(reader io.Reader) ([]string, error)
- func ReadDockerignore(dir string) ([]string, error)
- func SearchDockerignore(dir string) (io.Reader, error)
- func ShowVersion()
- type BuildInfo
- type Builder
- func (builder *Builder) AddCmd(cmd ...string)
- func (builder *Builder) Build(debug bool) error
- func (builder *Builder) CopyFiles(path string, dst string) error
- func (builder *Builder) Create() error
- func (builder *Builder) Exec(cmd []string) error
- func (builder *Builder) Exists() bool
- func (builder *Builder) Inspect() (types.ContainerJSON, error)
- func (builder *Builder) Remove() error
- func (builder *Builder) SetContainerID() error
- func (builder *Builder) Setup(config *RegistryInfo) error
- func (builder *Builder) Start() error
- func (builder *Builder) Stop() error
- type BuildkitImage
- type BuildkitInfo
- type CLIoptions
- type Configuration
- type ImageInfo
- type RegistryInfo
Constants ¶
const BuildkitdTomlTemplate = `` /* 153-byte string literal not displayed */
BuildkitdTomlTemplate is a template of buildkit settings.
const ConfigurationTemplate = `` /* 4511-byte string literal not displayed */
ConfigurationTemplate is a template of dbyml settings.
Variables ¶
This section is empty.
Functions ¶
func ConfigExists ¶
ConfigExists checks if the input config exists.
func GetAuthBase64 ¶
GetAuthBase64 encodes credentials for the registry with base64.
func GetBuildContext ¶ added in v1.2.1
GetBuildContext makes tar archive of files and directories in a given directory, and returns byte.Buffer of the archive. The buffer is used for build context to build an image.
func GetBuildkitContext ¶ added in v1.2.1
GetBuildContext makes tar archive of files and directories in a given directory, and returns byte.Buffer of the archive. The buffer is used for build context to build an image in bubildkitd container.
func IsExclude ¶ added in v1.2.1
IsExclude returns true if file matches any of the patterns and isn't excluded by any of the subsequent patterns.
func MakeBuildkitToml ¶ added in v1.1.0
func MakeBuildkitToml(config *RegistryInfo) (string, error)
MakeBuildkitToml makes buildkitd.toml from a template.
func MakeTemplate ¶
func MakeTemplate(config *Configuration)
MakeTemplate makes a dbyml setting file from a template.
func PrintCenter ¶
PrintCenter shows centered string with padding specified character on each side of the string to stdout.
func ReadAll ¶ added in v1.2.1
ReadAll reads a .dockerignore file and returns the list of file patterns to ignore. Note this will trim whitespace from each line as well as use GO's "clean" func to get the shortest/cleanest path for each.
func ReadDockerignore ¶ added in v1.2.1
ReadDockerignore reads exclude files from .dockerignore. If not exists, return empty list.
func SearchDockerignore ¶ added in v1.2.1
SearchDockerignore searches .dockerignore exists in a given directory. If exists, return the io.Reader of the .dockerignore, otherwise return nil.
Types ¶
type BuildInfo ¶
type BuildInfo struct { Target string `yaml:"target"` NoCache bool `yaml:"no_cache"` Verbose bool `yaml:"verbose"` }
BuildInfo defines some options related to setting or progress on image build.
func NewBuildInfo ¶
func NewBuildInfo() *BuildInfo
NewBuildInfo makes Configuration struct with default values.
type Builder ¶ added in v1.1.0
type Builder struct { Name string // The name of builder container Image BuildkitImage // The image of builder container ID string // The container ID Config *container.Config // Container config HostConfig *container.HostConfig // Container host config Context string // The build context in builder DockerfilePath string // The path to Dockerfile in builder Cmd []string // The command executed in the builder Client *client.Client // Docker client for connecting to builder }
Builder describes a container information on buildkit
func NewBuilder ¶ added in v1.1.0
func NewBuilder() (builder *Builder)
NewBuilder creates a builder object with the default values.
func (*Builder) CopyFiles ¶ added in v1.1.0
CopyFiles copies directory in client to builder container. If the directory contains some other directories, copy them recursively.
func (*Builder) Inspect ¶ added in v1.1.0
func (builder *Builder) Inspect() (types.ContainerJSON, error)
Inspect gets a builder information.
func (*Builder) SetContainerID ¶ added in v1.1.0
SetContainerID sets container ID of a builder.
func (*Builder) Setup ¶ added in v1.1.0
func (builder *Builder) Setup(config *RegistryInfo) error
Setup creates a builder container and copy setting toml into the builder.
type BuildkitImage ¶ added in v1.1.0
type BuildkitImage struct {
Name string
}
BuildkitImage defines a docker image used in a builder container.
func (*BuildkitImage) Exists ¶ added in v1.1.0
func (buildkit *BuildkitImage) Exists() bool
Exists checks if the image exists on host.
func (*BuildkitImage) Pull ¶ added in v1.1.0
func (buildkit *BuildkitImage) Pull() error
Pull pulls a buildkit image from official dockerhub.
type BuildkitInfo ¶ added in v1.1.0
type BuildkitInfo struct { Enabled bool `yaml:"enabled"` Output map[string]interface{} `yaml:"output"` Cache map[string]interface{} `yaml:"cache"` Platform []string `yaml:"platform"` Remove bool `yaml:"remove"` }
BuildkitInfo defines setting on build with buildkit.
func NewBuildkitInfo ¶ added in v1.1.0
func NewBuildkitInfo() *BuildkitInfo
NewBuildkitInfo makes BuildkitInfo object with default values.
func (*BuildkitInfo) ParseOptions ¶ added in v1.1.0
func (buildkit *BuildkitInfo) ParseOptions(imageInfo ImageInfo) []string
ParseOptions parses options related to buildkit and sets buildctl args.
type CLIoptions ¶
type CLIoptions struct { // Path to config file. Config string // Whether to generate config file. Init bool }
CLIoptions defines cli options.
func (*CLIoptions) Parse ¶
func (options *CLIoptions) Parse()
Parse checks the input options, run actions according to the options.
type Configuration ¶
type Configuration struct { ImageInfo ImageInfo `yaml:"image"` BuildInfo BuildInfo `yaml:"build"` RegistryInfo RegistryInfo `yaml:"registry"` BuildkitInfo BuildkitInfo `yaml:"buildkit"` }
Configuration defines the hierarchy of the settings in config file.
func LoadConfig ¶
func LoadConfig(path string) (conf *Configuration)
LoadConfig loads the configuration from the path.
func NewConfiguration ¶
func NewConfiguration() *Configuration
NewConfiguration makes Configuration struct with default values.
func (*Configuration) ShowConfig ¶
func (config *Configuration) ShowConfig()
ShowConfig shows the current Configuration to stdout.
type ImageInfo ¶
type ImageInfo struct { Basename string `yaml:"name"` // Image name Tag string `yaml:"tag"` // Image tag ImageName string `yaml:"image_name"` // Image name such as `go-dbyml:latest` Context string `yaml:"path"` // Path to the directory where Dockerfile exists, is equivalent to build context Dockerfile string `yaml:"dockerfile"` // Dockerfile filename BuildArgs map[string]*string `yaml:"build_args"` // Build-args to be passed to image on build Labels map[string]string `yaml:"label"` // Labels to be passed to image on build DockerHost string `yaml:"docker_host"` // Docker host such as "unix:///var/run/docker.sock" DockerfilePath string Registry RegistryInfo BuildInfo BuildInfo FullName string DockerClient *client.Client }
ImageInfo defines docker image information.
func NewImageInfo ¶
func NewImageInfo() *ImageInfo
NewImageInfo creates a new ImageInfo struct with default values.
func (*ImageInfo) AddTag ¶
func (image *ImageInfo) AddTag()
AddTag adds a tag containing the registry name to a built image.
func (*ImageInfo) SetDockerClient ¶
func (image *ImageInfo) SetDockerClient()
SetDockerClient initializes docker api client for the specified host.
func (*ImageInfo) SetFullImageName ¶
func (image *ImageInfo) SetFullImageName()
SetFullImageName sets image name for pushing to a registry.
func (*ImageInfo) SetProperties ¶
func (image *ImageInfo) SetProperties()
SetProperties sets some properties when build an image.
func (ImageInfo) ShowProperties ¶
func (image ImageInfo) ShowProperties()
ShowProperties shows the current settings related to image build.
type RegistryInfo ¶
type RegistryInfo struct { // Whether to enabled pushing to a registry Enabled bool `yaml:"enabled"` // Registry host such as `myregistry.com:5000` Host string `yaml:"host"` // Project name Project string `yaml:"project"` // credentials settings to a registry Auth map[string]string `yaml:"auth"` Insecure bool `yaml:"insecure"` }
RegistryInfo defines a registry settings where a built image will be pushed.
func NewRegistryInfo ¶
func NewRegistryInfo() *RegistryInfo
NewRegistryInfo creates a new RegistryInfo struct with default values.
func (*RegistryInfo) BasicAuth ¶
func (registry *RegistryInfo) BasicAuth() string
BasicAuth returns base64 the encoded credentials for the registry.
func (RegistryInfo) ShowProperties ¶
func (registry RegistryInfo) ShowProperties()
ShowProperties shows the current registry settings to stdout.