Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
Refactor Project Structure (#325)
Browse files Browse the repository at this point in the history
* added logger & git pkg

* tests pass

* migrated everything to internal

* fix logger

* update go version

* fix clone calls

* clean up git.Clone

* fix docs

* add build docs
  • Loading branch information
evanlouie authored Nov 4, 2020
1 parent f2aed3a commit 9650c0e
Show file tree
Hide file tree
Showing 39 changed files with 733 additions and 925 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ generation of Kubernetes resource manifests that an in-cluster GitOps pod like
[Weaveworks' Flux](https://github.com/weaveworks/flux) watches and reconciles
with the current set of applied resource manifests in your Kubernetes cluster.

## Installation

You can grab the latest releases from the
[releases page](https://github.com/microsoft/fabrikate/releases) or build the
bleeding edge from source with:

```bash
git clone https://github.com/microsoft/fabrikate
cd fabrikate
go build -o fab cmd/cli/main.go
```

## Getting Started

First, install the latest `fab` cli on your local machine from
Expand Down
2 changes: 1 addition & 1 deletion main.go → cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"reflect"

"github.com/microsoft/fabrikate/cmd"
"github.com/microsoft/fabrikate/internal/cmd"
"github.com/timfpark/yaml"
)

Expand Down
16 changes: 14 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
module github.com/microsoft/fabrikate

go 1.12
go 1.15

require (
github.com/golang/protobuf v1.3.2 // indirect
github.com/google/go-github/v28 v28.0.1
github.com/google/uuid v1.1.1
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/kyokomi/emoji v2.1.0+incompatible
github.com/onsi/ginkgo v1.11.0 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/otiai10/copy v1.0.1
github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776 // indirect
github.com/sirupsen/logrus v1.4.2
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.5.1
github.com/timfpark/conjungo v1.0.1
github.com/timfpark/yaml v0.0.0-20190612232118-2e9e29c9df01
helm.sh/helm/v3 v3.2.0
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 // indirect
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 // indirect
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7 // indirect
golang.org/x/text v0.3.2 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
)
492 changes: 2 additions & 490 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cmd/add.go → internal/cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"

"github.com/kyokomi/emoji"
"github.com/microsoft/fabrikate/core"
"github.com/microsoft/fabrikate/logger"
"github.com/microsoft/fabrikate/internal/core"
"github.com/microsoft/fabrikate/internal/logger"
"github.com/spf13/cobra"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/add_test.go → internal/cmd/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"testing"

"github.com/microsoft/fabrikate/core"
"github.com/microsoft/fabrikate/internal/core"
"github.com/stretchr/testify/assert"
)

Expand All @@ -17,7 +17,7 @@ func TestAdd(t *testing.T) {
_ = os.Chdir(cwd)
}()

err = os.Chdir("../testdata/add")
err = os.Chdir("../../testdata/add")
assert.Nil(t, err)

_ = os.Remove("./component.yaml")
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions cmd/generate.go → internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"strings"

"github.com/kyokomi/emoji"
"github.com/microsoft/fabrikate/core"
"github.com/microsoft/fabrikate/generators"
"github.com/microsoft/fabrikate/logger"
"github.com/microsoft/fabrikate/internal/core"
"github.com/microsoft/fabrikate/internal/generators"
"github.com/microsoft/fabrikate/internal/logger"
"github.com/spf13/cobra"
)

Expand Down
14 changes: 7 additions & 7 deletions cmd/generate_test.go → internal/cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"testing"

"github.com/microsoft/fabrikate/core"
"github.com/microsoft/fabrikate/internal/core"
)

func TestGenerate(t *testing.T) {
Expand All @@ -21,23 +21,23 @@ func TestGenerate(t *testing.T) {
{
"json",
args{
"../testdata/generate",
"../../testdata/generate",
[]string{"prod-east", "prod"},
false,
},
map[string]int{
"microservices-workload": 0,
"infra": 0,
"fabrikate-jaeger": 409,
"jaeger": 26877,
"jaeger": 26916,
},
false,
},

{
"yaml",
args{
"../testdata/generate-yaml",
"../../testdata/generate-yaml",
[]string{"prod"},
false,
},
Expand All @@ -52,7 +52,7 @@ func TestGenerate(t *testing.T) {
{
"remote static",
args{
"../testdata/generate-remote-static",
"../../testdata/generate-remote-static",
[]string{"common"},
false,
},
Expand All @@ -66,7 +66,7 @@ func TestGenerate(t *testing.T) {
{
"hooks",
args{
"../testdata/generate-hooks",
"../../testdata/generate-hooks",
[]string{"prod"},
false,
},
Expand All @@ -79,7 +79,7 @@ func TestGenerate(t *testing.T) {
{
"disabled subcomponent",
args{
"../testdata/generate-disabled",
"../../testdata/generate-disabled",
[]string{"disabled"},
false,
},
Expand Down
11 changes: 6 additions & 5 deletions cmd/install.go → internal/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"os/exec"

"github.com/kyokomi/emoji"
"github.com/microsoft/fabrikate/core"
"github.com/microsoft/fabrikate/generators"
"github.com/microsoft/fabrikate/logger"
"github.com/microsoft/fabrikate/internal/core"
"github.com/microsoft/fabrikate/internal/generators"
"github.com/microsoft/fabrikate/internal/git"
"github.com/microsoft/fabrikate/internal/logger"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -45,8 +46,8 @@ func Install(path string) (err error) {
return err
} else if len(accessTokens) > 0 {
for repo, token := range accessTokens {
if _, exists := core.GitAccessTokens.Get(repo); !exists {
core.GitAccessTokens.Set(repo, token)
if _, exists := git.AccessTokens.Get(repo); !exists {
git.AccessTokens.Set(repo, token)
}
}
}
Expand Down
16 changes: 7 additions & 9 deletions cmd/install_test.go → internal/cmd/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package cmd

import (
"testing"

"github.com/microsoft/fabrikate/util"
)

func TestInstall(t *testing.T) {
Expand All @@ -17,44 +15,44 @@ func TestInstall(t *testing.T) {
}{
{
"json",
args{"../testdata/install"},
args{"../../testdata/install"},
false,
},

{
"yaml",
args{"../testdata/install-yaml"},
args{"../../testdata/install-yaml"},
false,
},

{
"hooks",
args{"../testdata/install-hooks"},
args{"../../testdata/install-hooks"},
false,
},

{
"private git",
args{"../testdata/install-private"},
args{"../../testdata/install-private"},
true,
},

{
"helm",
args{"../testdata/install-helm"},
args{"../../testdata/install-helm"},
false,
},

{
"repo-alias",
args{"../testdata/repo-alias"},
args{"../../testdata/repo-alias"},
false,
},
}

for _, tt := range tests {
defer func() {
_ = util.UninstallComponents(tt.args.path)
// _ = util.UninstallComponents(tt.args.path)
}()

t.Run(tt.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/remove.go → internal/cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"strings"

"github.com/microsoft/fabrikate/core"
"github.com/microsoft/fabrikate/internal/core"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/remove_test.go → internal/cmd/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"testing"

"github.com/microsoft/fabrikate/core"
"github.com/microsoft/fabrikate/internal/core"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go → internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/microsoft/fabrikate/logger"
"github.com/microsoft/fabrikate/internal/logger"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down
6 changes: 3 additions & 3 deletions cmd/set.go → internal/cmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io/ioutil"
"strings"

"github.com/microsoft/fabrikate/core"
"github.com/microsoft/fabrikate/internal/core"
"github.com/microsoft/fabrikate/util"
"github.com/spf13/cobra"
"github.com/timfpark/yaml"
Expand Down Expand Up @@ -152,11 +152,11 @@ $ fab set --environment prod data.replicas=4 username="ops"
Sets the value of 'data.replicas' equal to 4 and 'username' equal to 'ops' in the 'prod' config for the current component.
$ fab set --subcomponent "myapp" endpoint="east-db"
$ fab set --subcomponent "myapp" endpoint="east-db"
Sets the value of 'endpoint' equal to 'east-db' in the 'common' config (the default) for subcomponent 'myapp'.
$ fab set --subcomponent "myapp.mysubcomponent" data.replicas=5
$ fab set --subcomponent "myapp.mysubcomponent" data.replicas=5
Sets the subkey "replicas" in the key 'data' equal to 5 in the 'common' config (the default) for the subcomponent 'mysubcomponent' of the subcomponent 'myapp'.
Expand Down
2 changes: 1 addition & 1 deletion cmd/set_test.go → internal/cmd/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestSetValue(t *testing.T) {
_ = os.Chdir(cwd)
}()

err = os.Chdir("../testdata/set")
err = os.Chdir("../../testdata/set")
assert.Nil(t, err)
noNewConfigKeys := false

Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go → internal/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package cmd

import (
"github.com/microsoft/fabrikate/logger"
"github.com/microsoft/fabrikate/internal/logger"
"github.com/spf13/cobra"
)

Expand Down
10 changes: 8 additions & 2 deletions core/component.go → internal/core/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
"sync"

"github.com/kyokomi/emoji"
"github.com/microsoft/fabrikate/logger"
"github.com/microsoft/fabrikate/internal/git"
"github.com/microsoft/fabrikate/internal/logger"
"github.com/timfpark/yaml"
)

Expand Down Expand Up @@ -215,7 +216,12 @@ func (c *Component) InstallComponent(componentPath string) (err error) {
}

logger.Info(emoji.Sprintf(":helicopter: Installing component '%s' with git from '%s'", c.Name, c.Source))
if err = Git.CloneRepo(c.Source, c.Version, subcomponentPath, c.Branch); err != nil {
cloneOpts := &git.CloneOpts{
URL: c.Source,
SHA: c.Version,
Branch: c.Branch,
Into: subcomponentPath}
if err = git.Clone(cloneOpts); err != nil {
return err
}
return nil
Expand Down
Loading

0 comments on commit 9650c0e

Please sign in to comment.