Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docker): expose the image name and tag separately #58

Merged
merged 1 commit into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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