Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from commitdev/zero-init
Zero init
- Loading branch information
Showing
20 changed files
with
298 additions
and
179 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 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
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package configs | ||
|
||
const ( | ||
TemplatesDir = "tmp/templates" | ||
CommitYml = "zero.yml" | ||
IgnoredPaths = "(?i)zero.module.yml|.git/" | ||
TemplateExtn = ".tmpl" | ||
TemplatesDir = "tmp/templates" | ||
ZeroProjectYml = "zero-project.yml" | ||
IgnoredPaths = "(?i)zero.module.yml|.git/" | ||
TemplateExtn = ".tmpl" | ||
) |
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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"path" | ||
|
||
"github.com/commitdev/zero/configs" | ||
"github.com/commitdev/zero/pkg/util/exit" | ||
) | ||
|
||
const exampleConfig = `name: %s | ||
# Context is normally populated automatically but could be used to inject global params | ||
context: | ||
# module can be in any format the go-getter supports (path, github, url, etc.) | ||
# supports https://github.com/hashicorp/go-getter#url-format | ||
# Example: | ||
# - source: "../development/modules/ci" | ||
# - output: "github-actions" | ||
modules: | ||
- source: "github.com/commitdev/zero-aws-eks-stack" | ||
- source: "github.com/commitdev/zero-deployable-backend" | ||
- source: "github.com/commitdev/zero-deployable-react-frontend" | ||
` | ||
|
||
var RootDir = "./" | ||
|
||
func SetRootDir(dir string) { | ||
RootDir = dir | ||
} | ||
|
||
func Init(dir string, projectName string, projectContext *ZeroProjectConfig) { | ||
// TODO: template the zero-project.yml with projectContext | ||
content := []byte(fmt.Sprintf(exampleConfig, projectName)) | ||
|
||
err := ioutil.WriteFile(path.Join(dir, projectName, configs.ZeroProjectYml), content, 0644) | ||
if err != nil { | ||
exit.Fatal(fmt.Sprintf("Failed to create example %s", configs.ZeroProjectYml)) | ||
} | ||
} |
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,31 @@ | ||
package config_test | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/commitdev/zero/configs" | ||
"github.com/commitdev/zero/internal/config" | ||
) | ||
|
||
func TestInit(t *testing.T) { | ||
const testDir = "../../test-sandbox" | ||
projectName := "test-project" | ||
|
||
config.SetRootDir(testDir) | ||
defer os.RemoveAll(testDir) | ||
|
||
testDirPath := path.Join(config.RootDir, projectName) | ||
// create sandbox dir | ||
err := os.MkdirAll(testDirPath, os.ModePerm) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
config.Init(config.RootDir, projectName, nil) | ||
|
||
if _, err := os.Stat(path.Join(testDirPath, configs.ZeroProjectYml)); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.