Created
August 26, 2016 05:11
-
-
Save mweagle/a365ebce0cefec79eba820ad5c017efb to your computer and use it in GitHub Desktop.
Spartav0.8.0_buildDockerImage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SpartaPostBuildDockerImageHook workflow hook to build the Docker image | |
func SpartaPostBuildDockerImageHook(context map[string]interface{}, | |
serviceName string, | |
S3Bucket string, | |
buildID string, | |
awsSession *session.Session, | |
noop bool, | |
logger *logrus.Logger) error { | |
dockerServiceName := strings.ToLower(serviceName) | |
dockerTags := make(map[string]string, 0) | |
dockerTags[dockerServiceName] = buildID | |
// Always build the image | |
buildErr := spartaDocker.BuildDockerImage(serviceName, | |
"", | |
&dockerTags, | |
logger) | |
if nil != buildErr { | |
return buildErr | |
} | |
var ecrURL string | |
if !noop { | |
// Push the image to ECR & store the URL s.t. we can properly annotate | |
// the CloudFormation template | |
localTag := fmt.Sprintf("%s:%s", dockerServiceName, buildID) | |
ecrURLPush, pushImageErr := spartaDocker.PushDockerImageToECR(localTag, | |
ecrRepositoryName, | |
awsSession, | |
logger) | |
if nil != pushImageErr { | |
return pushImageErr | |
} | |
ecrURL = ecrURLPush | |
logger.WithFields(logrus.Fields{ | |
"ECRUrl": ecrURL, | |
"PushError": pushImageErr, | |
}).Info("Docker image pushed") | |
} else { | |
ecrURL = fmt.Sprintf("https://123412341234.dkr.ecr.aws-region.amazonaws.com/%s", serviceName) | |
} | |
// Save the URL | |
context["URL"] = ecrURL | |
return nil | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment