Skip to content

Commit

Permalink
Add installation of packages on environment creation
Browse files Browse the repository at this point in the history
Signed-off-by: Lou Marvin Caraig <[email protected]>
  • Loading branch information
se7entyse7en committed Jun 27, 2020
1 parent 01b5629 commit 1ceee8d
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion internal/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/term"
"github.com/se7entyse7en/pydockenv/internal/dependency"
"github.com/se7entyse7en/pydockenv/internal/utils"
"github.com/se7entyse7en/pydockenv/log"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -107,7 +108,7 @@ func Create(conf *Config) error {
return err
}

_, err = cli.ContainerCreate(
c, err := cli.ContainerCreate(
context.Background(),
&container.Config{
Image: contImg,
Expand Down Expand Up @@ -138,6 +139,36 @@ func Create(conf *Config) error {

ctxLogger.Debug("Container created!")

contInfo, err := cli.ContainerInspect(context.Background(), c.ID)
if err != nil {
return fmt.Errorf("cannot inspect container: %w", err)
}

if len(conf.Dependencies) == 0 {
return nil
}

ctxLogger.Debugf("Installing %d dependencies...", len(conf.Dependencies))
err = cli.ContainerStart(context.Background(), contName,
types.ContainerStartOptions{})
if err != nil {
return fmt.Errorf("cannot start container: %w", err)
}

err = dependency.InstallForContainer(contInfo, &dependency.Requirements{
Packages: dependency.Packages{Dependencies: conf.Dependencies},
})
if err != nil {
return fmt.Errorf("cannot execute command in container: %w", err)
}

err = cli.ContainerStop(context.Background(), contName, nil)
if err != nil {
return fmt.Errorf("cannot stop container: %w", err)
}

ctxLogger.Debug("Dependencies installed!")

return nil
}

Expand Down

0 comments on commit 1ceee8d

Please sign in to comment.