Skip to content

Commit

Permalink
Merge branch 'release/v0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rojack96 committed Dec 28, 2024
2 parents 79cd833 + a27095f commit 93054a2
Show file tree
Hide file tree
Showing 38 changed files with 458 additions and 366 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Gocker supports Docker commands for version 26.1.3.

Currently, all `compose` commands are implemented, and support for other Docker commands is coming soon.

### Create a Command
### Create a command

```go
// Create compose instance
Expand All @@ -55,7 +55,7 @@ fmt.Println(result.GetCommand())
// output: "docker compose --file compose.yml up --build hello-world"
```

### Execute a Command
### Execute a command

```go
// Create compose instance
Expand Down
14 changes: 8 additions & 6 deletions commands/compose/common/common.go → commands/common/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,25 @@ type Services interface {
}

type CommandExecutor struct {
Command string
command string
}

func SetCommand(cmd string) *CommandExecutor {
return &CommandExecutor{command: cmd}
}

func (ce *CommandExecutor) GetCommand() string {
return ce.Command
return ce.command
}

/*
func (ce *CommandExecutor) GetCommandWithPrivileges() string {
return ce.Command
return ce.command
}
*/

func (ce *CommandExecutor) Exec(withPrivileges bool) {
helpers.GeneralExec(ce.Command, withPrivileges)
helpers.GeneralExec(ce.command, withPrivileges)
}

func Index(indexOfContainer int) string {
Expand Down Expand Up @@ -80,12 +84,10 @@ func Env(envs ...helpers.KeyValueParameters) string {
return helpers.StringArray(env, arguments...)
}

// User - Run the command as this user
func User(usr string) string {
return helpers.String(user, usr)
}

// Workdir - ath to workdir directory for this command
func Workdir(path string) string {
return helpers.String(workdir, path)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package option
package common

import (
"github.com/rojack96/gocker/helpers"
Expand Down Expand Up @@ -82,7 +82,7 @@ func Detach() string {
return helpers.Option(detach)
}

func Services() string {
func ServicesOption() string {
return helpers.Option(services)
}

Expand Down
21 changes: 12 additions & 9 deletions commands/compose/command/attach.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package command

import (
"github.com/rojack96/gocker/commands/compose/common"
"github.com/rojack96/gocker/commands/compose/option"
"github.com/rojack96/gocker/commands/common"
"github.com/rojack96/gocker/helpers"
)

Expand All @@ -13,34 +12,38 @@ const (
)

type Attach struct {
Command string
command string
}

func NewAttach(cmd string) *Attach {
return &Attach{command: cmd}
}

// DetachKeys - Override the key sequence for detaching from a container.
func (a *Attach) DetachKeys(value string) *Attach {
return &Attach{Command: a.Command + helpers.String(detachKeys, value)}
return &Attach{command: a.command + helpers.String(detachKeys, value)}
}

// DryRun - Execute command in dry run mode
func (a *Attach) DryRun() *Attach {
return &Attach{Command: a.Command + option.DryRun()}
return &Attach{command: a.command + common.DryRun()}
}

// Index - index of the container if service has multiple replicas
func (a *Attach) Index(indexOfContainer int) *Attach {
return &Attach{a.Command + common.Index(indexOfContainer)}
return &Attach{a.command + common.Index(indexOfContainer)}
}

// NoStdin - Do not attach STDIN
func (a *Attach) NoStdin() *Attach {
return &Attach{Command: a.Command + helpers.Option(noStdin)}
return &Attach{command: a.command + helpers.Option(noStdin)}
}

// SigProxy - Proxy all received signals to the process (default true)
func (a *Attach) SigProxy() *Attach {
return &Attach{Command: a.Command + helpers.Option(sigProxy)}
return &Attach{command: a.command + helpers.Option(sigProxy)}
}

func (a *Attach) ServiceName(serviceName string) *common.CommandExecutor {
return &common.CommandExecutor{Command: a.Command + helpers.ServiceName(serviceName)}
return common.SetCommand(a.command + helpers.ServiceName(serviceName))
}
40 changes: 25 additions & 15 deletions commands/compose/command/build.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package command

import (
"github.com/rojack96/gocker/commands/compose/common"
"github.com/rojack96/gocker/commands/compose/option"
"github.com/rojack96/gocker/commands/common"
"github.com/rojack96/gocker/helpers"
)

Expand All @@ -18,7 +17,11 @@ const (
)

type Build struct {
Command string
command string
}

func NewBuild(cmd string) *Build {
return &Build{command: cmd}
}

type UnitByte string
Expand All @@ -41,56 +44,63 @@ func (b *Build) BuildArg(args ...helpers.KeyValueParameters) *Build {
}
}

return &Build{Command: b.Command + helpers.StringArray(buildArg, arguments...)}
return &Build{command: b.command + helpers.StringArray(buildArg, arguments...)}
}

// Builder - Set builder to use
func (b *Build) Builder(builderName string) *Build {
return &Build{Command: b.Command + helpers.String(builder, builderName)}
return &Build{command: b.command + helpers.String(builder, builderName)}
}

// DryRun - Execute command in dry run mode
func (b *Build) DryRun() *Build {
return &Build{Command: b.Command + option.DryRun()}
return &Build{command: b.command + common.DryRun()}
}

// Memory - Set memory limit for the command container. Not supported by BuildKit.
// If unitByte is empty use Kilobytes by default
func (b *Build) Memory(bytes string, unitByte UnitByte) *Build {
bytes += string(unitByte)
return &Build{Command: b.Command + helpers.String(memory, bytes)}
switch unitByte {
case Kilobytes, Megabytes, Gigabytes:
bytes += string(unitByte)
default:
bytes += string(Kilobytes)
}

return &Build{command: b.command + helpers.String(memory, bytes)}
}

// NoCache - Do not use cache when building the image
func (b *Build) NoCache() *Build {
return &Build{Command: b.Command + helpers.Option(noCache)}
return &Build{command: b.command + helpers.Option(noCache)}
}

// Pull - Always attempt to pull a newer version of the image
func (b *Build) Pull() *Build {
return &Build{Command: b.Command + helpers.Option(pull)}
return &Build{command: b.command + helpers.Option(pull)}
}

// Push - Push service images
func (b *Build) Push() *Build {
return &Build{Command: b.Command + helpers.Option(push)}
return &Build{command: b.command + helpers.Option(push)}
}

// Quiet - Don't print anything to STDOUT
func (b *Build) Quiet() *Build {
return &Build{Command: b.Command + option.Quiet()}
return &Build{command: b.command + common.Quiet()}
}

// Ssh - Set SSH authentications used when building service images.
// (use 'default' for using your default SSH Agent)
func (b *Build) Ssh(agent string) *Build {
return &Build{Command: b.Command + helpers.String(ssh, agent)}
return &Build{command: b.command + helpers.String(ssh, agent)}
}

// WithDependencies - Also command dependencies (transitively)
func (b *Build) WithDependencies() *Build {
return &Build{Command: b.Command + helpers.Option(withDependencies)}
return &Build{command: b.command + helpers.Option(withDependencies)}
}

func (b *Build) ServiceNames(serviceNames ...string) *common.CommandExecutor {
return &common.CommandExecutor{Command: b.Command + helpers.ServiceName(serviceNames...)}
return common.SetCommand(b.command + helpers.ServiceName(serviceNames...))
}
41 changes: 22 additions & 19 deletions commands/compose/command/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package command

import (
"github.com/rojack96/gocker/commands/compose/common"
"github.com/rojack96/gocker/commands/compose/option"
"github.com/rojack96/gocker/commands/common"
"github.com/rojack96/gocker/helpers"
)

Expand All @@ -21,84 +20,88 @@ const (
)

type Config struct {
Command string
command string
}

func NewConfig(cmd string) *Config {
return &Config{command: cmd}
}

// DryRun - Execute command in dry run mode
func (c *Config) DryRun() *Config {
return &Config{Command: c.Command + option.DryRun()}
return &Config{command: c.command + common.DryRun()}
}

// Format - Format the output. Values: [yaml | json] (default "yaml")
func (c *Config) Format(value string) *Config {
return &Config{Command: c.Command + common.Format(value)}
return &Config{command: c.command + common.Format(value)}
}

// Hash - Print the service config hash, one per line
func (c *Config) Hash(value string) *Config {
return &Config{Command: c.Command + helpers.String(hash, value)}
return &Config{command: c.command + helpers.String(hash, value)}
}

// Images - Print the image names, one per line
func (c *Config) Images() *Config {
return &Config{Command: c.Command + helpers.Option(images)}
return &Config{command: c.command + helpers.Option(images)}
}

// NoConsistency - Don't check model consistency
func (c *Config) NoConsistency() *Config {
return &Config{Command: c.Command + helpers.Option(noConsistency)}
return &Config{command: c.command + helpers.Option(noConsistency)}
}

// NoInterpolate - Don't interpolate environment variables
func (c *Config) NoInterpolate() *Config {
return &Config{Command: c.Command + helpers.Option(noInterpolate)}
return &Config{command: c.command + helpers.Option(noInterpolate)}
}

// NoNormalize - Don't normalize compose model
func (c *Config) NoNormalize() *Config {
return &Config{Command: c.Command + helpers.Option(noNormalize)}
return &Config{command: c.command + helpers.Option(noNormalize)}
}

// NoPathResolution - Don't resolve file paths
func (c *Config) NoPathResolution() *Config {
return &Config{Command: c.Command + helpers.Option(noPathResolution)}
return &Config{command: c.command + helpers.Option(noPathResolution)}
}

// Output - Save to file (default to stdout)
func (c *Config) Output(value string) *Config {
return &Config{Command: c.Command + helpers.String(output, value)}
return &Config{command: c.command + helpers.String(output, value)}
}

// Profiles - Print the profile names, one per line
func (c *Config) Profiles() *Config {
return &Config{Command: c.Command + helpers.Option(profiles)}
return &Config{command: c.command + helpers.Option(profiles)}
}

// Quiet - Only validate the configuration, don't print anything
func (c *Config) Quiet() *Config {
return &Config{Command: c.Command + helpers.Option(quiet)}
return &Config{command: c.command + helpers.Option(quiet)}
}

// ResolveImageDigests - Pin image tags to digests
func (c *Config) ResolveImageDigests() *Config {
return &Config{Command: c.Command + helpers.Option(resolveImageDigests)}
return &Config{command: c.command + helpers.Option(resolveImageDigests)}
}

// Services - Print the service names, one per line
func (c *Config) Services() *Config {
return &Config{Command: c.Command + option.Services()}
return &Config{command: c.command + common.ServicesOption()}
}

// Variables - Print model variables and default values
func (c *Config) Variables() *Config {
return &Config{Command: c.Command + helpers.Option(variables)}
return &Config{command: c.command + helpers.Option(variables)}
}

// Volumes - Print the volume names, one per line
func (c *Config) Volumes() *Config {
return &Config{Command: c.Command + option.Volumes()}
return &Config{command: c.command + common.Volumes()}
}

func (c *Config) ServiceNames(serviceNames ...string) *common.CommandExecutor {
return &common.CommandExecutor{Command: c.Command + helpers.ServiceName(serviceNames...)}
return common.SetCommand(c.command + helpers.ServiceName(serviceNames...))
}
Loading

0 comments on commit 93054a2

Please sign in to comment.