Skip to content

Commit

Permalink
cfg: remove [Build.command] from repository config
Browse files Browse the repository at this point in the history
Setting a default build command in the repository configuration can be
handy but has the issue, that all applications need to add the
.baur.toml file as buildinput.
Otherwise they are not able to detect that the build command changed in
the repository wide configuration.
Adding the .baur.toml file as buildinput isn't feasible, it means that
all applications are rebuild when e.g. the postgres url changes.

- Remove the Build.Command parameter from the repository config
- Setting a build.command in the .app.toml file is now mandatory
- Change the build.command to "make" and uncomment the parameter in the
  example configuration file
  • Loading branch information
fho committed Oct 18, 2018
1 parent 09fa151 commit 652c0b6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 39 deletions.
4 changes: 0 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ func NewApp(repository *Repository, cfgPath string) (*App, error) {
BuildCmd: cfg.Build.Command,
}

if len(app.BuildCmd) == 0 {
app.BuildCmd = repository.DefaultBuildCmd
}

if err := app.setDockerOutputsFromCfg(cfg); err != nil {
return nil, errors.Wrap(err, "processing docker output declarations failed")
}
Expand Down
7 changes: 5 additions & 2 deletions cfg/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type App struct {

// Build the build section
type Build struct {
Command string `toml:"command" commented:"true" comment:"command to build the application, overwrites the parameter in the repository config"`
Command string `toml:"command" commented:"false" comment:"command to build the application"`
Input BuildInput `comment:"specifies the inputs for an build, an input is everything that affects the build output"`
Output BuildOutput `comment:"specifies the outputs that the application build produces"`
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func ExampleApp(name string) *App {
Name: name,

Build: Build{
Command: "make docker_dist",
Command: "make dist",
Input: BuildInput{
Files: FileInputs{
Paths: []string{".app.toml"},
Expand Down Expand Up @@ -238,6 +238,9 @@ func (a *App) Validate() error {

// Validate validates the build section
func (b *Build) Validate() error {
if len(b.Command) == 0 {
return errors.New("[Build] section contains errors: command can not be empty")
}
if err := b.Input.Validate(); err != nil {
return err
}
Expand Down
29 changes: 3 additions & 26 deletions cfg/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ const (

// Repository contains the repository configuration.
type Repository struct {
Discover Discover `comment:"application discovery settings"`
Build RepositoryBuild `comment:"build configuration"`
BaurVersion string `toml:"baur_version" comment:"version of baur"`
Database Database `toml:"Database" comment:"configures the database in which build informations are stored"`
Discover Discover `comment:"application discovery settings"`
BaurVersion string `toml:"baur_version" comment:"version of baur"`
Database Database `toml:"Database" comment:"configures the database in which build informations are stored"`
}

// Database contains database configuration
Expand All @@ -35,11 +34,6 @@ type Discover struct {
SearchDepth int `toml:"search_depth" comment:"specifies the max. directory the application search recurses into subdirectories"`
}

// RepositoryBuild contains the build section of the repository
type RepositoryBuild struct {
BuildCmd string `toml:"build_command" comment:"command to build the application, can be overwritten in the application config files"`
}

// RepositoryFromFile reads the repository config from a file and returns it.
func RepositoryFromFile(cfgPath string) (*Repository, error) {
config := Repository{}
Expand All @@ -65,9 +59,6 @@ func ExampleRepository() *Repository {
Dirs: []string{"."},
SearchDepth: 1,
},
Build: RepositoryBuild{
BuildCmd: "make docker_dist",
},

Database: Database{
PGSQLURL: "postgresql://guest:guest@jenkins.sisu.sh:5432/baur",
Expand Down Expand Up @@ -117,11 +108,6 @@ func (r *Repository) Validate() error {
return errors.Wrap(err, "[Discover] section contains errors")
}

err = r.Build.Validate()
if err != nil {
return errors.Wrap(err, "[Build] section contains errors")
}

err = r.Database.Validate()
if err != nil {
return errors.Wrap(err, "[Database] section contains errors")
Expand All @@ -144,15 +130,6 @@ func (d *Discover) Validate() error {
return nil
}

// Validate validates the [Build] section of a repository config file
func (b *RepositoryBuild) Validate() error {
if len(b.BuildCmd) == 0 {
return errors.New("build_command can not be empty")
}

return nil
}

// Validate validates the [Database] section of a repository config file
func (d *Database) Validate() error {
if len(d.PGSQLURL) == 0 {
Expand Down
12 changes: 5 additions & 7 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type Repository struct {
CfgPath string
AppSearchDirs []string
SearchDepth int
DefaultBuildCmd string
gitCommitID string
gitWorktreeIsDirty *bool
PSQLURL string
Expand Down Expand Up @@ -96,12 +95,11 @@ func NewRepository(cfgPath string) (*Repository, error) {
}

r := Repository{
CfgPath: cfgPath,
DefaultBuildCmd: cfg.Build.BuildCmd,
Path: path.Dir(cfgPath),
AppSearchDirs: fs.PathsJoin(path.Dir(cfgPath), cfg.Discover.Dirs),
SearchDepth: cfg.Discover.SearchDepth,
PSQLURL: cfg.Database.PGSQLURL,
CfgPath: cfgPath,
Path: path.Dir(cfgPath),
AppSearchDirs: fs.PathsJoin(path.Dir(cfgPath), cfg.Discover.Dirs),
SearchDepth: cfg.Discover.SearchDepth,
PSQLURL: cfg.Database.PGSQLURL,
}

err = fs.DirsExist(r.AppSearchDirs)
Expand Down

0 comments on commit 652c0b6

Please sign in to comment.