Skip to content

Commit

Permalink
feat(docker): expose the image name and tag separately (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrynhard authored Mar 7, 2018
1 parent 5a73ea6 commit 42c5d09
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 35 deletions.
24 changes: 18 additions & 6 deletions pkg/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/Masterminds/semver"
"github.com/autonomy/conform/pkg/git"
"github.com/autonomy/conform/pkg/utilities"
)

// Metadata contains metadata.
Expand All @@ -20,12 +19,18 @@ type Metadata struct {

// Docker contains docker specific metadata.
type Docker struct {
Image string
Image *Image
PreviousStage string
CurrentStage string
NextStage string
}

// Image contains information used to identity an image.
type Image struct {
Name string
Tag string
}

// Git contains git specific metadata.
type Git struct {
Branch string
Expand Down Expand Up @@ -97,12 +102,19 @@ func addMetadataForVersion(m *Metadata) error {
}

func addMetadataForDocker(m *Metadata) error {
image, err := utilities.ImageName(m.Repository, m.Git.SHA, m.Git.IsClean)
if err != nil {
return err
var name, tag string
if !m.Git.IsClean {
tag = "dirty"
} else {
tag = m.Git.SHA
}
name = m.Repository

dockerMetadata := &Docker{
Image: image,
Image: &Image{
Name: name,
Tag: tag,
},
}
m.Docker = dockerMetadata

Expand Down
4 changes: 2 additions & 2 deletions pkg/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func (p *Pipeline) Build(metadata *metadata.Metadata, stages map[string]*stage.S

var image string
if i+1 == len(p.Stages) {
image = metadata.Docker.Image
image = metadata.Docker.Image.Name + ":" + metadata.Docker.Image.Tag
} else {
image = metadata.Repository + ":" + stageName
image = metadata.Docker.Image.Name + ":" + stageName
}

_err = build(image, s)
Expand Down
27 changes: 0 additions & 27 deletions pkg/utilities/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,6 @@ import (
"github.com/docker/docker/client"
)

// ImageName formats the image name based on the status of a git repository.
func ImageName(repository, sha string, isClean bool) (image string, err error) {
if !isClean {
image = formatImageNameWIP(repository)
} else {
image = formatImageNameSHA(repository, sha)
}

return image, err
}

func formatImageNameWIP(repository string) string {
return fmt.Sprintf("%s:wip", repository)
}

func formatImageNameSHA(repository, sha string) string {
return fmt.Sprintf("%s:%s", repository, sha)
}

// func formatImageNameTag(repository, tag string) string {
// return fmt.Sprintf("%s:%s", repository, tag)
// }
//
// func formatImageNameLatest(repository string) string {
// return fmt.Sprintf("%s:latest", repository)
// }

// CheckDockerVersion checks the Docker server version and returns an error if
// it is an incompatible version.
func CheckDockerVersion() error {
Expand Down

0 comments on commit 42c5d09

Please sign in to comment.