-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New docker-env syntax * now commands without arguments use default git branch (master) * added -b option for branched environments * hooks refactor * added checking aws binary * set go version to 1.22
- Loading branch information
1 parent
74f440f
commit bdf724d
Showing
27 changed files
with
402 additions
and
201 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/marcinhlybin/docker-env/config" | ||
"github.com/marcinhlybin/docker-env/logger" | ||
"github.com/marcinhlybin/docker-env/registry" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
type AppContext struct { | ||
ProjectName string | ||
ServiceName string | ||
IsBranch bool | ||
IsProjectNameSet bool | ||
Config *config.Config | ||
Registry *registry.DockerProjectRegistry | ||
} | ||
|
||
func NewAppContext(c *cli.Context) (*AppContext, error) { | ||
cfg, err := initializeConfig(c) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
reg, err := initializeRegistry(cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Set default project name | ||
projectName := c.String("project") | ||
if projectName == "" { | ||
projectName = cfg.GitDefaultBranch | ||
} | ||
|
||
return &AppContext{ | ||
ProjectName: projectName, | ||
ServiceName: c.String("service"), | ||
IsProjectNameSet: c.IsSet("project"), | ||
IsBranch: c.Bool("branch"), | ||
Config: cfg, | ||
Registry: reg, | ||
}, nil | ||
} | ||
|
||
func initializeConfig(c *cli.Context) (*config.Config, error) { | ||
cfg := config.NewConfig() | ||
if err := cfg.LoadConfig(c.String("config")); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Show executed commands | ||
logger.ShowExecutedCommands(cfg.ShowExecutedCommands) | ||
|
||
return cfg, nil | ||
} | ||
|
||
func initializeRegistry(cfg *config.Config) (*registry.DockerProjectRegistry, error) { | ||
return registry.NewDockerProjectRegistry(cfg), nil | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/marcinhlybin/docker-env/logger" | ||
"github.com/marcinhlybin/docker-env/project" | ||
) | ||
|
||
func (ctx *AppContext) CreateProject() (*project.Project, error) { | ||
p, err := project.NewProject(ctx.ProjectName, ctx.ServiceName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Set project name from git branch | ||
if ctx.IsBranch { | ||
if err := p.SetProjectNameFromGitBranch(); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return p, nil | ||
} | ||
|
||
func (ctx *AppContext) ActiveProject() (*project.Project, error) { | ||
if ctx.IsProjectNameSet { | ||
return ctx.CreateProject() | ||
} | ||
|
||
// Fetch active project | ||
reg := ctx.Registry | ||
p, err := reg.ActiveProject() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if p == nil { | ||
logger.Warning("No active project found") | ||
return nil, nil | ||
} | ||
|
||
p.SetServiceName(ctx.ServiceName) | ||
return p, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.