Skip to content

Commit bbb6380

Browse files
authored
refactor: refactor project structure
* refactor: move entropy main package to cmd/entropy * chore: reformat readme file * refactor: merge app package into cmd * refactor: rename api into server * refactor: restructure to follow domain-driven layout * refactor: move mocks into internal/ * test: unit tests for provider service * feat: use entropy.yaml as default config file * doc: update configuration doc * refactor: nest core packages inside core/ * refactor: split main package * refactor: move mocks alongside interfaces
1 parent b8862da commit bbb6380

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1566
-1406
lines changed

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
[![Version](https://img.shields.io/github/v/release/odpf/entropy?logo=semantic-release)](Version)
66
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?logo=apache)](LICENSE)
77

8-
Entropy is an extensible infrastructure orchestration and application deployment tool. Entropy provides features required for deploying and managing complex applications like resource versioning, config schema versioning, rollbacks dry runs etc.
8+
Entropy is an extensible infrastructure orchestration and application deployment tool. Entropy provides features
9+
required for deploying and managing complex applications like resource versioning, config schema versioning, rollbacks
10+
dry runs etc.
911

1012
## Key Features
1113

@@ -25,9 +27,10 @@ Install Entropy on macOS, Windows, Linux, OpenBSD, FreeBSD, and on any machine.
2527

2628
#### Binary (Cross-platform)
2729

28-
Download the appropriate version for your platform from [releases](https://github.com/odpf/entropy/releases) page. Once downloaded, the binary can be run from anywhere.
29-
You don’t need to install it into a global location. This works well for shared hosts and other systems where you don’t have a privileged account.
30-
Ideally, you should install it somewhere in your PATH for easy use. `/usr/local/bin` is the most probable location.
30+
Download the appropriate version for your platform from [releases](https://github.com/odpf/entropy/releases) page. Once
31+
downloaded, the binary can be run from anywhere. You don’t need to install it into a global location. This works well
32+
for shared hosts and other systems where you don’t have a privileged account. Ideally, you should install it somewhere
33+
in your PATH for easy use. `/usr/local/bin` is the most probable location.
3134

3235
#### Homebrew
3336

@@ -72,11 +75,15 @@ $ make test
7275

7376
## Contribute
7477

75-
Development of Entropy happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving Entropy.
78+
Development of Entropy happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and
79+
improvements. Read below to learn how you can take part in improving Entropy.
7680

77-
Read our [contributing guide](https://odpf.github.io/entropy/docs/contribute/contributing) to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to Entropy.
81+
Read our [contributing guide](https://odpf.github.io/entropy/docs/contribute/contributing) to learn about our
82+
development process, how to propose bugfixes and improvements, and how to build and test your changes to Entropy.
7883

79-
To help you get your feet wet and get you familiar with our contribution process, we have a list of [good first issues](https://github.com/odpf/entropy/labels/good%20first%20issue) that contain bugs which have a relatively limited scope. This is a great place to get started.
84+
To help you get your feet wet and get you familiar with our contribution process, we have a list
85+
of [good first issues](https://github.com/odpf/entropy/labels/good%20first%20issue) that contain bugs which have a
86+
relatively limited scope. This is a great place to get started.
8087

8188
This project exists thanks to all the [contributors](https://github.com/odpf/entropy/graphs/contributors).
8289

app/app.go

Lines changed: 0 additions & 195 deletions
This file was deleted.

cli/cli.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cli
2+
3+
import (
4+
"github.com/odpf/salt/cmdx"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
var rootCmd = &cobra.Command{
9+
Use: "entropy",
10+
Long: `Entropy is a framework to safely and predictably create, change,
11+
and improve modern cloud applications and infrastructure using
12+
familiar languages, tools, and engineering practices.`,
13+
}
14+
15+
func Execute() {
16+
rootCmd.PersistentFlags().StringP(configFlag, "c", "", "Override config file")
17+
rootCmd.AddCommand(
18+
cmdServe(),
19+
cmdMigrate(),
20+
cmdVersion(),
21+
)
22+
23+
cmdx.SetHelp(rootCmd)
24+
_ = rootCmd.Execute()
25+
}

cli/config.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cli
2+
3+
import (
4+
"github.com/odpf/salt/config"
5+
"github.com/spf13/cobra"
6+
7+
"github.com/odpf/entropy/internal/server"
8+
"github.com/odpf/entropy/internal/store/mongodb"
9+
"github.com/odpf/entropy/pkg/logger"
10+
"github.com/odpf/entropy/pkg/metric"
11+
)
12+
13+
const configFlag = "config"
14+
15+
// Config contains the application configuration
16+
type Config struct {
17+
DB mongodb.DBConfig `mapstructure:"db"`
18+
Log logger.LogConfig `mapstructure:"log"`
19+
Service server.Config `mapstructure:"service"`
20+
NewRelic metric.NewRelicConfig `mapstructure:"newrelic"`
21+
}
22+
23+
func loadConfig(cmd *cobra.Command) (Config, error) {
24+
var opts []config.LoaderOption
25+
26+
cfgFile, _ := cmd.Flags().GetString(configFlag)
27+
if cfgFile != "" {
28+
opts = append(opts, config.WithFile(cfgFile))
29+
} else {
30+
opts = append(opts,
31+
config.WithPath("./"),
32+
config.WithName("entropy"),
33+
)
34+
}
35+
36+
var cfg Config
37+
err := config.NewLoader(opts...).Load(&cfg)
38+
if err != nil {
39+
return cfg, err
40+
}
41+
return cfg, nil
42+
}

cli/migrate.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package cli
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/odpf/entropy/internal/store/mongodb"
7+
)
8+
9+
const (
10+
resourceRepoName = "resources"
11+
providerRepoName = "providers"
12+
)
13+
14+
func cmdMigrate() *cobra.Command {
15+
cmd := &cobra.Command{
16+
Use: "migrate",
17+
Short: "Run DB migrations",
18+
}
19+
20+
cmd.RunE = func(cmd *cobra.Command, args []string) error {
21+
cfg, err := loadConfig(cmd)
22+
if err != nil {
23+
return err
24+
}
25+
26+
return runMigrations(cfg.DB)
27+
}
28+
29+
return cmd
30+
}
31+
32+
func runMigrations(cfg mongodb.DBConfig) error {
33+
mongoStore, err := mongodb.New(&cfg)
34+
if err != nil {
35+
return err
36+
}
37+
38+
resourceRepository := mongodb.NewResourceRepository(mongoStore.Collection(resourceRepoName))
39+
if err = resourceRepository.Migrate(); err != nil {
40+
return err
41+
}
42+
43+
providerRepository := mongodb.NewProviderRepository(mongoStore.Collection(providerRepoName))
44+
if err = providerRepository.Migrate(); err != nil {
45+
return err
46+
}
47+
48+
return nil
49+
}

0 commit comments

Comments
 (0)