Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GiGurra committed Jul 14, 2023
1 parent 634fc0f commit 10f5683
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 20 deletions.
41 changes: 27 additions & 14 deletions internal/flycd/deployment_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,6 @@ func deployAppFromFolder(
return "", fmt.Errorf("cloning git repo: %w", err)
}

if cfg.MergeCfg.All {
err = cfgDir.CopyContentsTo(cloneResult.Dir)
if err != nil {
return "", fmt.Errorf("could not copy config dir contents to cloned repo dir for %+v: %w", cfg, err)
}
} else if len(cfg.MergeCfg.Exact) > 0 {
for _, exactPath := range cfg.MergeCfg.Exact {
err = cfgDir.CopyFile(exactPath, cloneResult.Dir.Cwd()+"/"+exactPath)
if err != nil {
return "", fmt.Errorf("could not copy config file '%s' to cloned repo dir for %+v: %w", exactPath, cfg, err)
}
}
}

tempDir = cloneResult.Dir
appHash = cloneResult.Hash

Expand Down Expand Up @@ -276,6 +262,33 @@ func deployAppFromFolder(
return "", fmt.Errorf("unknown source type %s", cfg.Source.Type)
}

// Check if to copy config contents to tempDir
if cfg.MergeCfg.All {
err = cfgDir.CopyContentsTo(tempDir)
// list files in clone dir
/* filesInCloneDir := []string{}
err = filepath.Walk(tempDir.Cwd(), func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
filesInCloneDir = append(filesInCloneDir, strings.TrimPrefix(path, tempDir.Cwd()+"/"))
}
return nil
})
fmt.Printf("files in clone dir:\n")
for _, file := range filesInCloneDir {
fmt.Printf("file: %s\n", file)
}*/
if err != nil {
return "", fmt.Errorf("could not copy config dir contents to cloned repo dir for %+v: %w", cfg, err)
}
} else if len(cfg.MergeCfg.Include) > 0 {
for _, exactPath := range cfg.MergeCfg.Include {
err = cfgDir.CopyFile(exactPath, tempDir.Cwd()+"/"+exactPath)
if err != nil {
return "", fmt.Errorf("could not copy config file '%s' to cloned repo dir for %+v: %w", exactPath, cfg, err)
}
}
}

if cfg.Env == nil {
cfg.Env = make(map[string]string)
}
Expand Down
33 changes: 33 additions & 0 deletions internal/flycd/deployment_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,36 @@ func TestDeployFromFolder_existingApp(t *testing.T) {
}

}

func TestDeployFromFolder_appMergingConfig(t *testing.T) {
ctx := context.Background()
flyClient := mocks.NewMockFlyClient(t)
deployService := NewDeployService(flyClient)
deployCfg := model.
NewDefaultDeployConfig().
WithAbortOnFirstError(true).
WithRetries(0)

fmt.Printf("flyClient: %+v\n", flyClient)

flyClient.
EXPECT().
ExistsApp(mock.Anything, mock.Anything).
Return(true, nil)

flyClient.
EXPECT().
GetDeployedAppConfig(mock.Anything, mock.Anything).
Return(model.AppConfig{}, nil)

flyClient.
EXPECT().
DeployExistingApp(mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil)

_, err := deployService.DeployAppFromFolder(ctx, "../../test/test-projects/deploy-tests/apps/app2", deployCfg)
if err != nil {
t.Fatalf("DeployAppFromFolder failed: %v", err)
}

}
4 changes: 2 additions & 2 deletions internal/flycd/model/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func (a *AppConfig) Validate(options ...ValidateAppConfigOptions) error {
a.Mounts = []Mount{}
}

if a.MergeCfg.Exact == nil {
a.MergeCfg.Exact = []string{}
if a.MergeCfg.Include == nil {
a.MergeCfg.Include = []string{}
}

// only permit apps that are valid dns names
Expand Down
6 changes: 4 additions & 2 deletions internal/flycd/model/source_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ func (g *GitRef) IsEmpty() bool {
}

type MergeCfg struct {
All bool `yaml:"all,omitempty" toml:"all" json:"all,omitempty"`
Exact []string `yaml:"exact,omitempty" toml:"exact" json:"exact,omitempty"`
All bool `yaml:"all,omitempty" toml:"all" json:"all,omitempty"`
Include []string `yaml:"include,omitempty" toml:"include,omitempty" json:"include,omitempty"`
// TODO: Implement
//Exclude []string `yaml:"exclude,omitempty" toml:"exclude,omitempty" json:"exclude,omitempty"`
}

type Source struct {
Expand Down
6 changes: 4 additions & 2 deletions test/test-projects/deploy-tests/apps/app2/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ app: app2
primary_region: arn
org: personal
source:
type: git
repo: [email protected]:TestUser/OtherTestRepo.git
type: local
path: "../app1"
merge_cfg:
all: true
Empty file.

0 comments on commit 10f5683

Please sign in to comment.