create

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package create provides the container config for the wrapped client. it is built to be created in a declarative way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDockerFile added in v0.1.4

func NewDockerFile() *dockerFile

NewDockerFile creates a new dockerfile which allows you to create a dockerfile string with step by step instructions via builder pattern

note: Not safe for concurrent use.

Types

type Container

type Container struct {
	Name   string        // the name of the container
	Config *MergedConfig // merged docker sdk configuration for container creation
	Errors []error
}

func NewContainer

func NewContainer(name ...string) *Container

NewContainer creates a new container with the given name. It will return a container with empty configurations ready to be set. a container is a wrapper around the docker sdk container configuration. but it can be used as a service config in a compose project

parameters:

  • name: the name of the container

Note: 'name' is optional when using this container as a Compose service config. It is required when using the Docker SDK directly. If multiple strings are passed as the name, they will be joined with hyphens (e.g., "foo", "bar" -> "foo-bar").

func (*Container) Validate

func (c *Container) Validate() error

Validate validates the container config. It will return an error if the container has errors.

func (*Container) With added in v0.1.4

func (c *Container) With(setters ...any) *Container

With sets the container config via the setter functions. It will return a container with the container config set. If any of the setters return an error, the error will be appended to the container's error slice.

parameters:

  • setters: the setters to set the container config

note: setters can be any type that implements the SetContainerConfig, SetHostConfig, SetNetworkConfig, or SetPlatformConfig function type. If a setter is nil, it will be skipped.

func (*Container) WithContainerConfig

func (c *Container) WithContainerConfig(setters ...SetContainerConfig) *Container

WithContainerConfig sets the container config via the setter functions. It will return a container with the container config set. If any of the setters return an error, the error will be appended to the container's error slice. parameters:

  • setters: the setters to set the container config

func (*Container) WithHostConfig

func (c *Container) WithHostConfig(setters ...SetHostConfig) *Container

WithHostConfig sets the host config via the setter functions. It will return a container with the host config set. If any of the setters return an error, the error will be appended to the container's error slice.

parameters:

  • setters: the setters to set the host config

func (*Container) WithNetworkConfig

func (c *Container) WithNetworkConfig(setters ...SetNetworkConfig) *Container

WithNetworkConfig sets the network config via the setter functions. It will return a container with the network config set. If any of the setters return an error, the error will be appended to the container's error slice.

parameters:

  • setters: the setters to set the network config

func (*Container) WithPlatformConfig

func (c *Container) WithPlatformConfig(setters ...SetPlatformConfig) *Container

WithPlatformConfig sets the platform config via the setter functions. It will return a container with the platform config set. If any of the setters return an error, the error will be appended to the container's error slice. parameters:

  • setters: the setters to set the platform config

type MergedConfig added in v0.1.3

type MergedConfig struct {
	Container *container.Config         // the container configuration
	Host      *container.HostConfig     // the host configuration
	Network   *network.NetworkingConfig // the network configuration
	Platform  *ocispec.Platform         // the platform configuration
}

type Project

type Project struct {
	// contains filtered or unexported fields
}

Project is a wrapper around types.Project It provides methods to create and manage a docker Compose project.

func NewProject

func NewProject(name string) *Project

NewProject creates a new project with the given name. It initializes the project with an empty service list. The name is used as the project name in the compose file.

func (*Project) Export

func (p *Project) Export(file string, perm os.FileMode) error

Export exports the project to a file parameters:

  • file: the file path to export the project to
  • perm: the permission of the file

func (*Project) ForEachService

func (p *Project) ForEachService(fn func(name string, service *types.ServiceConfig) error) error

ForEachService iterates over each service in the project and calls the provided function to provide the ability to mutate a service parameters:

  • fn: the function to call for each service

returns an error if the function returns an error

func (*Project) GetService added in v0.1.3

func (p *Project) GetService(name string) (*types.ServiceConfig, error)

GetService returns a service from the project parameters:

  • name: the name of the service

returns the service and an error if the service is not found or the project has no services

func (*Project) Marshal

func (p *Project) Marshal() ([]byte, error)

Marshal marshals the project to a yaml bytes slice

func (*Project) Unwrap

func (p *Project) Unwrap() *types.Project

Unwrap returns the underlying types.Project

func (*Project) Validate

func (p *Project) Validate() error

Validate validates the project returns an error if the project has errors

func (*Project) WithNetwork

func (p *Project) WithNetwork(name string, setters ...network.SetNetworkProjectConfig) *Project

WithNetwork defines a new network in the project

func (*Project) WithSecret

func (p *Project) WithSecret(key string, setters ...projectsecret.SetProjectSecretConfig) *Project

WithSecret defines a new secret in the project

func (*Project) WithService

func (p *Project) WithService(name string, service *Container, setters ...SetServiceConfig) *Project

WithService defines a new service in the project parameters:

  • name: the name of the service
  • service: the container to create the service from
  • setters: the setters to apply to the service

func (*Project) WithVolume

func (p *Project) WithVolume(name string, setters ...volume.SetVolumeProjectConfig) *Project

WithVolume defines a new volume in the project parameters:

  • name: the name of the volume
  • volume: the volume to create the volume from

type SetContainerConfig

type SetContainerConfig func(config *container.Config) error

SetContainerConfig is a function that sets the container config

type SetHostConfig

type SetHostConfig func(config *container.HostConfig) error

SetHostConfig is a function that sets the host config

type SetNetworkConfig

type SetNetworkConfig func(config *network.NetworkingConfig) error

SetNetworkConfig is a function that sets the network config

type SetPlatformConfig

type SetPlatformConfig func(config *ocispec.Platform) error

SetPlatformConfig is a function that sets the platform config

type SetServiceConfig

type SetServiceConfig func(service *types.ServiceConfig) error

SetServiceConfig is a function that sets the service config

Directories

Path Synopsis
config
cc
Package cc provides the options for the container config.
Package cc provides the options for the container config.
hc
Package hc provides the options for the host config.
Package hc provides the options for the host config.
hc/mount
Package mount provides the options for the mount config in the host config.
Package mount provides the options for the mount config in the host config.
nc
Package nc provides the options for the network config.
Package nc provides the options for the network config.
nc/endpoint
Package endpoint provides the options for the endpoint config in the network config.
Package endpoint provides the options for the endpoint config in the network config.
nc/endpoint/ipam
Package ipam provides the options for the IPAM config in the endpoint config.
Package ipam provides the options for the IPAM config in the endpoint config.
pc
Package pc provides the options for the platform config.
Package pc provides the options for the platform config.
sc
Package sc provides functions to set the service config
Package sc provides functions to set the service config
sc/build
Package build provides functions to set the build config for a service
Package build provides functions to set the build config for a service
sc/build/ulimit
Package ulimit provides a set of functions to configure the ulimits for the build
Package ulimit provides a set of functions to configure the ulimits for the build
sc/deploy
Package deploy provides functions to set the deploy configuration for a service
Package deploy provides functions to set the deploy configuration for a service
sc/deploy/resource
Package resource provides functions to set the resource configuration for a service deploy
Package resource provides functions to set the resource configuration for a service deploy
sc/deploy/resource/device
Package device provides functions to set the device configuration for a service deploys resource
Package device provides functions to set the device configuration for a service deploys resource
sc/deploy/update
Package update provides functions to set the update configuration for a service deploy
Package update provides functions to set the update configuration for a service deploy
sc/network
Package network provides functions to set the network configuration for a project
Package network provides functions to set the network configuration for a project
sc/network/pool
Package pool provides functions to set the ipam pool configuration for a project
Package pool provides functions to set the ipam pool configuration for a project
sc/secrets/projectsecret
Package projectsecret provides a set of functions to configure the secret for the project
Package projectsecret provides a set of functions to configure the secret for the project
sc/secrets/secretservice
Package secretservice provides a set of functions to configure the secrets for the service
Package secretservice provides a set of functions to configure the secrets for the service
sc/volume
Package volume provides functions to set the volume configuration for a project
Package volume provides functions to set the volume configuration for a project

Jump to

Keyboard shortcuts

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