Skip to content

Commit

Permalink
Separate starting container action to container go
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammedikinci committed May 6, 2022
1 parent 4ba26fa commit e4c0ce4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
20 changes: 20 additions & 0 deletions pkg/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,29 @@ import (
"strings"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/fatih/color"
)

func (r *runner) startContainer() error {
color.Set(color.FgGreen)
r.infoLog.Println("Start creating container")
color.Unset()

resp, err := r.cli.ContainerCreate(r.ctx, &container.Config{
Image: r.currentJob.Image,
Tty: true,
}, nil, nil, nil, r.currentJob.Name)

if err != nil {
return err
}

r.containerResponse = resp

return nil
}

func (r runner) stopCurrentContainer() error {
color.Set(color.FgBlue)
r.infoLog.Println("Container stopping")
Expand Down
13 changes: 1 addition & 12 deletions pkg/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,10 @@ func (r *runner) jobRunner() error {
}
}

color.Set(color.FgGreen)
r.infoLog.Println("Start creating container")
color.Unset()

resp, err := r.cli.ContainerCreate(r.ctx, &container.Config{
Image: r.currentJob.Image,
Tty: true,
}, nil, nil, nil, r.currentJob.Name)

if err != nil {
if err := r.startContainer(); err != nil {
return err
}

r.containerResponse = resp

if err := r.copyToContainer(); err != nil {
return err
}
Expand Down

0 comments on commit e4c0ce4

Please sign in to comment.