Skip to content

Commit

Permalink
Implement deployment repo context
Browse files Browse the repository at this point in the history
  • Loading branch information
clarsonneur committed Jun 1, 2018
1 parent fe704ea commit 2465f63
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ type Forj struct {
flows flow.Flows

i repository.GitRepoStruct // Infra Repository management.

deployContext forjDeployContext
}

/*const (
Expand Down
11 changes: 7 additions & 4 deletions create.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,23 @@ func (a *Forj) Create() error {
log.Print("CREATE: Automatic git push and forjj maintain enabled.")
}

if err := a.ValidateForjfile(); err != nil {
return fmt.Errorf("Your Forjfile is having issues. %s Try to fix and retry.", err)
}

// Identify deployment repositories from main Forjfile
if err := a.DefineDeployRepositories(a.f.DeployForjfile(), false); err != nil {
return fmt.Errorf("Issues to automatically add your deployment repositories. %s", err)
}

// Defining information about current deployment repository
a.defineDeployContext()

// Load flow identified by Forjfile with missing repos.
if err := a.FlowInit(); err != nil {
return err
}

if err := a.ValidateForjfile(); err != nil {
return fmt.Errorf("Your Forjfile is having issues. %s Try to fix and retry.", err)
}

if err := a.define_infra_upstream(); err != nil {
return fmt.Errorf("Unable to identify a valid infra repository upstream. %s", err)
}
Expand Down
21 changes: 20 additions & 1 deletion drivers_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,24 @@ func (a *Forj) RepoManagedBy(object_name, instance_name string) (_ string) {
return
}

// defineDeployContext initialize the deployment context for GetObjectData
func (a *Forj) defineDeployContext() {
// Getting information about deployment repository
a.deployContext.to = a.f.GetDeployment()
if deploy, found := a.f.GetADeployment(a.deployContext.to) ; found {
a.deployContext.obj = deploy
a.deployContext.repoAttached = deploy.AttachedRepo()
a.deployContext.repoAttached.SetCurrentDeploy()
}
}

// GetObjectsData build the list of Object required by the plugin provided from the cli flags.
// Information retrieved from InMemForjfile
//
func (a *Forj) GetObjectsData(r *goforjj.PluginReqData, d *drivers.Driver, action string) error {
// Loop on each plugin object
ffd := a.f.InMemForjfile()

for object_name, Obj := range d.Plugin.Yaml.Objects {
Obj_instances := ffd.GetInstances(object_name)
for _, instance_name := range Obj_instances {
Expand All @@ -553,11 +565,18 @@ func (a *Forj) GetObjectsData(r *goforjj.PluginReqData, d *drivers.Driver, actio
continue
}

// Filter on repo to be supported by the driver instance.
if object_name == "repo" {
// Filter on repo to be supported by the driver instance.
if _, is_owner := a.IsRepoManaged(d, object_name, instance_name); !is_owner {
continue
}
// Filter on deploy repos. Working only with the deployment repository of the current deployment.
if repo, found := ffd.GetRepo(instance_name) ; found {
if repo.Role() == "deploy" && a.deployContext.repoName() != instance_name {
gotrace.Trace("Deploy repository '%s' out of deployment '%s' scope", instance_name, a.deployContext.to)
continue
}
}
}

keys := make(goforjj.InstanceKeys)
Expand Down
18 changes: 18 additions & 0 deletions forj_deploy_context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"forjj/forjfile"
)

type forjDeployContext struct {
to string
obj *forjfile.DeploymentStruct
repoAttached *forjfile.RepoStruct
}

func (c *forjDeployContext) repoName() (ret string) {
if c.repoAttached != nil {
ret = c.repoAttached.Name()
}
return
}
3 changes: 3 additions & 0 deletions maintain.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func (a *Forj) Maintain() error {
return fmt.Errorf("Issues to automatically add your deployment repositories. %s", err)
}

// Defining information about current deployment repository
a.defineDeployContext()

// Load flow identified by Forjfile with missing repos.
if err := a.FlowInit(); err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func (a *Forj) Update() error {
if err := a.DefineDeployRepositories(ffd, true); err != nil {
return fmt.Errorf("Issues to automatically add your deployment repositories. %s", err)
}

// Defining information about current deployment repository
a.defineDeployContext()

// Load flow identified by Forjfile source with missing repos.
if err := a.FlowInit(); err != nil {
Expand Down

0 comments on commit 2465f63

Please sign in to comment.