diff --git a/pkg/metadata/metadata.go b/pkg/metadata/metadata.go index 6ff6b0ca..3537507d 100644 --- a/pkg/metadata/metadata.go +++ b/pkg/metadata/metadata.go @@ -5,7 +5,6 @@ import ( "github.com/Masterminds/semver" "github.com/autonomy/conform/pkg/git" - "github.com/autonomy/conform/pkg/utilities" ) // Metadata contains metadata. @@ -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 @@ -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 diff --git a/pkg/pipeline/pipeline.go b/pkg/pipeline/pipeline.go index 7e23cf72..8b5e1ff4 100644 --- a/pkg/pipeline/pipeline.go +++ b/pkg/pipeline/pipeline.go @@ -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) diff --git a/pkg/utilities/utilities.go b/pkg/utilities/utilities.go index e801269e..8c5c914b 100644 --- a/pkg/utilities/utilities.go +++ b/pkg/utilities/utilities.go @@ -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 {