Skip to content

Commit

Permalink
Append has to docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaLanziani committed Jul 13, 2023
1 parent dda46e8 commit 1a02f5d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import (
)

func (c *CLI) Build(cCtx *cli.Context) error {
project := c.getProject(cCtx)
project, err := c.getProject(cCtx)
if err != nil {
return err
}

logger.PrintInfo("Dockerfile Location: " + path.Join(project.Directory, c.DockerService.DockerFileName))
return c.DockerService.Build()
}
Expand Down
23 changes: 18 additions & 5 deletions src/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package cli

import (
"embed"
"fmt"
"io"
"os"
"path"
"path/filepath"
"sort"

"github.com/nearform/k8s-kurated-addons-cli/src/services/git"
"github.com/nearform/k8s-kurated-addons-cli/src/services/project"
"k8s.io/utils/strings/slices"

Expand Down Expand Up @@ -38,7 +40,7 @@ func (c CLI) baseBeforeFunc(ctx *cli.Context) error {
return nil
}

func (c *CLI) init(cCtx *cli.Context) {
func (c *CLI) init(cCtx *cli.Context) error {
appName := cCtx.String(appNameFlag)
version := cCtx.String(appVersionFlag)
projectDirectory := cCtx.String(projectDirectoryFlag)
Expand All @@ -64,11 +66,18 @@ func (c *CLI) init(cCtx *cli.Context) {
dockerImageName = appName + "/" + base
}

hash, err := git.GetHash()
if err != nil {
return err
}

tag := fmt.Sprintf("%s-%s", version, hash)

dockerImage := docker.DockerImage{
Registry: cCtx.String(repoNameFlag),
Name: dockerImageName,
Directory: absProjectDirectory,
Tag: version,
Tag: tag,
}

dockerService, err := docker.New(project, dockerImage, cCtx.String(dockerFileNameFlag))
Expand All @@ -79,13 +88,17 @@ func (c *CLI) init(cCtx *cli.Context) {
c.DockerService = dockerService
c.dockerImage = dockerImage
c.project = project
return nil
}

func (c *CLI) getProject(cCtx *cli.Context) *project.Project {
func (c *CLI) getProject(cCtx *cli.Context) (*project.Project, error) {
if (c.project == project.Project{}) {
c.init(cCtx)
err := c.init(cCtx)
if err != nil {
return nil, err
}
}
return &c.project
return &c.project, nil
}

func (c CLI) Run(args []string) error {
Expand Down
5 changes: 4 additions & 1 deletion src/cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ func (c *CLI) Delete(cCtx *cli.Context) error {
if err != nil {
return err
}
project := c.getProject(cCtx)
project, err := c.getProject(cCtx)
if err != nil {
return err
}
return knative.Clean(cCtx.String(namespaceFlag), config, project)
}

Expand Down
5 changes: 4 additions & 1 deletion src/cli/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ func (c *CLI) Deploy(cCtx *cli.Context) error {
if err != nil {
return err
}
project := c.getProject(cCtx)
project, err := c.getProject(cCtx)
if err != nil {
return err
}

return knative.Apply(cCtx.String(namespaceFlag), config, project, c.dockerImage)
}
Expand Down
1 change: 0 additions & 1 deletion src/cli/onbranch.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func (c CLI) OnBranchCMD() *cli.Command {
}

branchName := head.Name().Short()
c.Logger.Infof("Using branch %v as version and namespace", branchName)

ctx.Set(appVersionFlag, utils.EncodeRFC1123(branchName))
ctx.Set(namespaceFlag, utils.EncodeRFC1123(branchName))
Expand Down
5 changes: 4 additions & 1 deletion src/cli/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
)

func (c *CLI) template(cCtx *cli.Context) error {
project := c.getProject(cCtx)
project, err := c.getProject(cCtx)
if err != nil {
return err
}
content, err := project.Dockerfile()
if err != nil {
return fmt.Errorf("Getting docker file %v", err)
Expand Down

0 comments on commit 1a02f5d

Please sign in to comment.