dbyml

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: MIT Imports: 32 Imported by: 0

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

View Source
const BuildkitdTomlTemplate = `` /* 153-byte string literal not displayed */

BuildkitdTomlTemplate is a template of buildkit settings.

View Source
const ConfigurationTemplate = `` /* 4511-byte string literal not displayed */

ConfigurationTemplate is a template of dbyml settings.

Variables

This section is empty.

Functions

func Centering

func Centering(s string, w int) string

Centering returns the string centered within the specified length.

func ConfigExists

func ConfigExists(path string) bool

ConfigExists checks if the input config exists.

func ExecBuild

func ExecBuild(path string)

ExecBuild run the build sequence.

func GetAuthBase64

func GetAuthBase64(username string, password string) string

GetAuthBase64 encodes credentials for the registry with base64.

func GetBuildContext added in v1.2.1

func GetBuildContext(dir string) (buf *bytes.Buffer)

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

func GetBuildkitContext(dir string) (buf *bytes.Buffer)

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

func IsExclude(file string, exclude []string) (bool, error)

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

func PrintCenter(s string, w int, padding string)

PrintCenter shows centered string with padding specified character on each side of the string to stdout.

func ReadAll added in v1.2.1

func ReadAll(reader io.Reader) ([]string, error)

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

func ReadDockerignore(dir string) ([]string, error)

ReadDockerignore reads exclude files from .dockerignore. If not exists, return empty list.

func SearchDockerignore added in v1.2.1

func SearchDockerignore(dir string) (io.Reader, error)

SearchDockerignore searches .dockerignore exists in a given directory. If exists, return the io.Reader of the .dockerignore, otherwise return nil.

func ShowVersion

func ShowVersion()

ShowVersion shows module version.

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) AddCmd added in v1.1.0

func (builder *Builder) AddCmd(cmd ...string)

AddCmd adds arguments passed to buildctl.

func (*Builder) Build added in v1.1.0

func (builder *Builder) Build(debug bool) error

Build builds a image in a builder.

func (*Builder) CopyFiles added in v1.1.0

func (builder *Builder) CopyFiles(path string, dst string) error

CopyFiles copies directory in client to builder container. If the directory contains some other directories, copy them recursively.

func (*Builder) Create added in v1.1.0

func (builder *Builder) Create() error

Create creates a builder container.

func (*Builder) Exec added in v1.2.1

func (builder *Builder) Exec(cmd []string) error

Exec runs a command in buildkit container.

func (*Builder) Exists added in v1.1.0

func (builder *Builder) Exists() bool

Exists checks if a builder container exists.

func (*Builder) Inspect added in v1.1.0

func (builder *Builder) Inspect() (types.ContainerJSON, error)

Inspect gets a builder information.

func (*Builder) Remove added in v1.1.0

func (builder *Builder) Remove() error

Remove removes a builder container.

func (*Builder) SetContainerID added in v1.1.0

func (builder *Builder) SetContainerID() error

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.

func (*Builder) Start added in v1.1.0

func (builder *Builder) Start() error

Start starts a builder container.

func (*Builder) Stop added in v1.1.0

func (builder *Builder) Stop() error

Stop stops a builder container.

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 GetArgs

func GetArgs() (CLIoptions, bool)

GetArgs gets cli options from user inputs.

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) Build

func (image *ImageInfo) Build() error

Build runs image build.

func (*ImageInfo) Push

func (image *ImageInfo) Push() error

Push runs image push to a registry.

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.

Jump to

Keyboard shortcuts

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