Skip to content

Commit

Permalink
internal/cmd/gocdk: implement build command (#2047)
Browse files Browse the repository at this point in the history
Fixes #1807
  • Loading branch information
zombiezen authored May 10, 2019
1 parent 0d40f82 commit b73b89e
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions internal/cmd/gocdk/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,37 @@ import (
func build(ctx context.Context, pctx *processContext, args []string) error {
f := newFlagSet(pctx, "build")
list := f.Bool("list", false, "display Docker images of this project")
ref := f.String("t", ":latest", "name and/or tag in the form `name[:tag] OR :tag`")
if err := f.Parse(args); xerrors.Is(err, flag.ErrHelp) {
return nil
} else if err != nil {
return usagef("gocdk build: %w", err)
}
if *list {
return listBuilds(ctx, pctx, f.Args())
if err := listBuilds(ctx, pctx, f.Args()); err != nil {
return xerrors.Errorf("gocdk build: %w", err)
}
return nil
}
moduleRoot, err := findModuleRoot(ctx, pctx.workdir)
if err != nil {
return xerrors.Errorf("gocdk build: %w", err)
}
if strings.HasPrefix(*ref, ":") {
imageName, err := moduleDockerImageName(moduleRoot)
if err != nil {
return xerrors.Errorf("gocdk build: %w", err)
}
*ref = imageName + *ref
}
return xerrors.New("not implemented")
c := exec.CommandContext(ctx, "docker", "build", "--tag", *ref, ".")
c.Dir = moduleRoot
c.Stdout = pctx.stdout
c.Stderr = pctx.stderr
if err := c.Run(); err != nil {
return xerrors.Errorf("gocdk build: %w", err)
}
return nil
}

func listBuilds(ctx context.Context, pctx *processContext, args []string) error {
Expand Down

0 comments on commit b73b89e

Please sign in to comment.