Skip to content

Commit

Permalink
buildContainerImages opts added
Browse files Browse the repository at this point in the history
  • Loading branch information
Varun359 committed Jul 28, 2023
1 parent 2e74e0d commit ce9928b
Showing 1 changed file with 47 additions and 38 deletions.
85 changes: 47 additions & 38 deletions internal/pkg/cli/local_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,25 @@ type localRunVars struct {
type localRunOpts struct {
localRunVars

sel deploySelector
ecsLocalClient ecsLocalClient
sessProvider sessionProvider
sess *session.Session
targetEnv *config.Environment
targetApp *config.Application
store store
ws wsWlDirReader
cmd execRunner
dockerEngine dockerEngineRunner

configureClients func(o *localRunOpts) (repositoryService, error)
labeledTermPrinter func(fw syncbuffer.FileWriter, bufs []*syncbuffer.LabeledSyncBuffer, opts ...syncbuffer.LabeledTermPrinterOption) clideploy.LabeledTermPrinter
unmarshal func([]byte) (manifest.DynamicWorkload, error)
newInterpolator func(app, env string) interpolator
sel deploySelector
ecsLocalClient ecsLocalClient
sessProvider sessionProvider
sess *session.Session
targetEnv *config.Environment
targetApp *config.Application
store store
ws wsWlDirReader
cmd execRunner
dockerEngine dockerEngineRunner
repository repositoryService
appliedDynamicMft manifest.DynamicWorkload
out clideploy.UploadArtifactsOutput

buildContainerImages func(o *localRunOpts) error
configureClients func(o *localRunOpts) (repositoryService, error)
labeledTermPrinter func(fw syncbuffer.FileWriter, bufs []*syncbuffer.LabeledSyncBuffer, opts ...syncbuffer.LabeledTermPrinterOption) clideploy.LabeledTermPrinter
unmarshal func([]byte) (manifest.DynamicWorkload, error)
newInterpolator func(app, env string) interpolator
}

type imageInfo struct {
Expand Down Expand Up @@ -105,6 +109,7 @@ func newLocalRunOpts(vars localRunVars) (*localRunOpts, error) {
cmd: exec.NewCmd(),
dockerEngine: dockerengine.New(exec.NewCmd()),
labeledTermPrinter: labeledTermPrinter,
out: clideploy.UploadArtifactsOutput{},
}
opts.configureClients = func(o *localRunOpts) (repositoryService, error) {
defaultSessEnvRegion, err := o.sessProvider.DefaultWithRegion(o.targetEnv.Region)
Expand All @@ -120,6 +125,25 @@ func newLocalRunOpts(vars localRunVars) (*localRunOpts, error) {
ecr.New(defaultSessEnvRegion), repoName, resources.RepositoryURLs[o.wkldName])
return repository, nil
}
opts.buildContainerImages = func(o *localRunOpts) error {
gitShortCommit := imageTagFromGit(o.cmd)
image := clideploy.ContainerImageIdentifier{
GitShortCommitTag: gitShortCommit,
}
in := &clideploy.BuildImageArgs{
Name: o.wkldName,
WorkspacePath: o.ws.Path(),
Image: image,
Mft: o.appliedDynamicMft.Manifest(),
Out: &o.out,
GitShortCommitTag: gitShortCommit,
BuildFunc: o.repository.Build,
Login: o.repository.Login,
CheckDockerEngine: o.dockerEngine.CheckDockerEngineRunning,
LabeledTermPrinter: o.labeledTermPrinter,
}
return clideploy.BuildContainerImages(in)
}
return opts, nil
}

Expand Down Expand Up @@ -219,35 +243,19 @@ func (o *localRunOpts) Execute() error {
if err != nil {
return err
}
out := &clideploy.UploadArtifactsOutput{}
gitShortCommit := imageTagFromGit(o.cmd)
image := clideploy.ContainerImageIdentifier{
GitShortCommitTag: gitShortCommit,
}

repository, err := o.configureClients(o)
o.appliedDynamicMft = mft
o.repository, err = o.configureClients(o)
if err != nil {
return err
}
in := &clideploy.BuildImageArgs{
Name: o.wkldName,
WorkspacePath: o.ws.Path(),
Image: image,
Mft: mft.Manifest(),
Out: out,
GitShortCommitTag: gitShortCommit,
BuildFunc: repository.Build,
Login: repository.Login,
CheckDockerEngine: o.dockerEngine.CheckDockerEngineRunning,
LabeledTermPrinter: o.labeledTermPrinter,
}
err = clideploy.BuildContainerImages(in)

err = o.buildContainerImages(o)
if err != nil {
return fmt.Errorf("building container image: %w", err)
}

containerNames := out.ContainerNames
imageNames := out.ImageNames
containerNames := o.out.ContainerNames
imageNames := o.out.ImageNames

secretsList := make(map[string]string)
for _, s := range decrytedSecrets {
Expand All @@ -263,8 +271,8 @@ func (o *localRunOpts) Execute() error {
imageInfoList = append(imageInfoList, imageInfo)
}

manifestContent := mft.Manifest()
var sideCarListInfo []imageInfo
manifestContent := o.appliedDynamicMft.Manifest()
switch t := manifestContent.(type) {
case *manifest.ScheduledJob:
sideCarListInfo = getBuiltSideCarImages(t.Sidecars)
Expand All @@ -286,6 +294,7 @@ func (o *localRunOpts) Execute() error {
if err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit ce9928b

Please sign in to comment.