Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b91ebdb
feat: add bootstrap command and implement bootstrap functionality for…
Jul 9, 2025
f2df800
refactor: update bootstrap functions to accept directory parameter fo…
Jul 10, 2025
02541c9
refactor: enhance bootstrap flag definitions with shorthand options
Jul 10, 2025
7492c6b
feat: enhance bootstrap command to require module name and update fun…
Jul 10, 2025
2247941
feat: enhance bootstrap tests and implement module name replacement f…
Jul 10, 2025
bd839a3
fix: correct bootstrap package name and enhance bootstrap command fun…
Jul 10, 2025
86e26b5
fix: add context to HTTP request in WriteProto method
Jul 10, 2025
5563c7f
refactor: improve bootstrap tests and error handling
Jul 10, 2025
5696b27
fix: improve error handling in bootstrap command
Jul 10, 2025
2c19ca2
refactor: update downloadAndExtractTemplate to use BootstrapConfig
Jul 10, 2025
2854fc1
test: enhance bootstrap tests with additional scenarios
Jul 10, 2025
07ce845
chore: update test coverage badge [skip ci]
Jul 10, 2025
466bb63
feat: implement bootstrap functionality with comprehensive tests
Jul 10, 2025
4e5b7a4
test: enhance downloadFile tests with mock server scenarios
Jul 10, 2025
51b6b4c
test: improve error handling in downloadFile tests
Jul 10, 2025
73f8dc4
test: update bootstrap tests for integration scenarios and zip extrac…
Jul 10, 2025
b979586
test: enhance TestExtractZip for improved validation and error handling
Jul 10, 2025
e42e2e0
chore: update test coverage badge [skip ci]
Jul 10, 2025
52c8c42
feat: add CI/CD variable reminders to bootstrap output
Jul 10, 2025
14c460a
chore: update test coverage badge [skip ci]
Jul 10, 2025
46398db
feat: enhance bootstrap command with module flag and repository type …
Jul 11, 2025
fb6cd17
feat: improve file and directory movement with fallback mechanism
Jul 11, 2025
0da4380
feat: conditionally display CI/CD variable reminders based on reposit…
Jul 11, 2025
54a4ac1
refactor: remove redundant test for invalid repository type in bootst…
Jul 11, 2025
6127266
test: enhance error assertions in CRD tests for improved validation
Jul 11, 2025
96b33c1
chore: update test coverage badge [skip ci]
Jul 11, 2025
5c1a050
feat: add conditional reminders for GitHub and GitLab repository types
Jul 14, 2025
f7065e7
chore: update test coverage badge [skip ci]
Jul 14, 2025
a0cb821
fix: update reminder message for GitLab CI/CD variables
Jul 14, 2025
dae7f29
Merge commit '1cfb03982dd29ed4b6b7fe5ffc04a753fc21b856' into feature/…
ldmonster Aug 12, 2025
427d12c
remove empty run which blocked help
ldmonster Aug 12, 2025
2868847
add module name as required arg, add default dir, split logic to vali…
ldmonster Aug 12, 2025
ef4be49
bump readme
ldmonster Aug 12, 2025
15e9ade
remove useless linter. we know when we use shadowing in err consctuct…
ldmonster Aug 12, 2025
07586ab
lint
ldmonster Aug 12, 2025
a8f0246
add color, add debug logs
ldmonster Aug 12, 2025
6afcbeb
replace config val with calculated one
ldmonster Aug 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ linters:
govet:
enable:
- nilness
- shadow
lll:
line-length: 140
misspell:
Expand Down
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,42 @@ dmt lint /path/to/module1 /path/to/module2 /path/to/module3

Each directory is processed as a separate execution, and results are displayed for each directory individually.

### Gen
### Bootstrap

Generate some automatic rules for you module
\<Coming soon\>
Bootstrap a new Deckhouse module from template:

```shell
dmt bootstrap my-module-name
```

This command will:
- Download the official Deckhouse module template
- Extract it to the current directory (or specified directory)
- Replace template placeholders with your module name
- Configure CI/CD files based on your chosen platform

#### Options

- `--pipeline, -p`: Choose CI/CD platform (`github` or `gitlab`, default: `github`)
- `--directory, -d`: Specify target directory (default: current directory)
- `--repository-url, -r`: Use custom module template repository URL

#### Examples

Bootstrap a GitHub module:
```shell
dmt bootstrap my-awesome-module --pipeline github
```

Bootstrap a GitLab module in specific directory:
```shell
dmt bootstrap my-module --pipeline gitlab --directory ./modules/my-module
```

Use custom template repository:
```shell
dmt bootstrap my-module --repository-url https://github.com/myorg/custom-template/archive/main.zip
```

## Linters list

Expand Down
94 changes: 83 additions & 11 deletions cmd/dmt/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,27 @@ limitations under the License.
package main

import (
"bytes"
"errors"
"fmt"
"os"
"regexp"
"strings"
"text/tabwriter"

"github.com/fatih/color"
"github.com/spf13/cobra"

"github.com/deckhouse/dmt/internal/bootstrap"
"github.com/deckhouse/dmt/internal/flags"
"github.com/deckhouse/dmt/internal/fsutils"
"github.com/deckhouse/dmt/internal/logger"
)

var version = "devel"

var kebabCaseRegex = regexp.MustCompile(`^([a-z][a-z0-9]*)(-[a-z0-9]+)*$`)

func execute() {
rootCmd := &cobra.Command{
Use: "dmt",
Expand All @@ -44,11 +53,8 @@ func execute() {

if flags.PrintVersion {
fmt.Println("dmt version: ", flags.Version)
os.Exit(0)
}
},
Run: func(_ *cobra.Command, _ []string) {
},
}

lintCmd := &cobra.Command{
Expand All @@ -58,20 +64,86 @@ func execute() {
Run: lintCmdFunc,
}

genCmd := &cobra.Command{
Use: "gen",
Short: "generator for Deckhouse modules",
Long: `A lot of useful generators`,
Run: func(_ *cobra.Command, _ []string) {
fmt.Println("under development")
bootstrapCmd := &cobra.Command{
Use: "bootstrap [module-name]",
Short: "bootstrap for Deckhouse modules",
Long: `Bootstrap functionality for module development process`,
Args: cobra.ExactArgs(1),
// in persistent pre run we must check all args and flags
PersistentPreRunE: func(_ *cobra.Command, args []string) error {
// check module name in kebab case
moduleName := args[0]
if !kebabCaseRegex.MatchString(moduleName) {
return errors.New("module name must be in kebab case")
}

// Check flags.BootstrapRepositoryType
repositoryType := strings.ToLower(flags.BootstrapRepositoryType)
if repositoryType != "github" && repositoryType != "gitlab" {
return fmt.Errorf("invalid repository type: %s", repositoryType)
}

return nil
},
RunE: func(_ *cobra.Command, args []string) error {
moduleName := args[0]
repositoryType := strings.ToLower(flags.BootstrapRepositoryType)

config := bootstrap.BootstrapConfig{
ModuleName: moduleName,
RepositoryType: repositoryType,
RepositoryURL: flags.BootstrapRepositoryURL,
Directory: flags.BootstrapDirectory,
}

if err := bootstrap.RunBootstrap(config); err != nil {
return fmt.Errorf("running bootstrap: %w", err)
}

w := new(tabwriter.Writer)

const minWidth = 5

buf := bytes.NewBuffer([]byte{})
w.Init(buf, minWidth, 0, 0, ' ', 0)

switch repositoryType {
case bootstrap.RepositoryTypeGitHub:
fmt.Fprintln(w)
color.New(color.FgHiYellow).Fprintln(w, "Don't forget to add secrets to your GitHub repository:")
fmt.Fprintf(w, "\t%s\n", "- DECKHOUSE_PRIVATE_REPO")
fmt.Fprintf(w, "\t%s\n", "- DEFECTDOJO_API_TOKEN")
fmt.Fprintf(w, "\t%s\n", "- DEFECTDOJO_HOST")
fmt.Fprintf(w, "\t%s\n", "- DEV_MODULES_REGISTRY_PASSWORD")
fmt.Fprintf(w, "\t%s\n", "- GOPROXY")
fmt.Fprintf(w, "\t%s\n", "- PROD_MODULES_READ_REGISTRY_PASSWORD")
fmt.Fprintf(w, "\t%s\n", "- PROD_MODULES_REGISTRY_PASSWORD")
fmt.Fprintf(w, "\t%s\n", "- SOURCE_REPO")
fmt.Fprintf(w, "\t%s\n", "- SOURCE_REPO_SSH_KEY")
case bootstrap.RepositoryTypeGitLab:
fmt.Fprintln(w)
color.New(color.FgHiYellow).Fprintln(w, "Don't forget to modify variables to your .gitlab-ci.yml file:")
fmt.Fprintf(w, "\t%s\n", "- MODULES_MODULE_NAME")
fmt.Fprintf(w, "\t%s\n", "- MODULES_REGISTRY")
fmt.Fprintf(w, "\t%s\n", "- MODULES_MODULE_SOURCE")
fmt.Fprintf(w, "\t%s\n", "- MODULES_MODULE_TAG")
fmt.Fprintf(w, "\t%s\n", "- WERF_VERSION")
fmt.Fprintf(w, "\t%s\n", "- BASE_IMAGES_VERSION")
}

w.Flush()

fmt.Print(buf.String())

return nil
},
Hidden: true,
}

lintCmd.Flags().AddFlagSet(flags.InitLintFlagSet())
bootstrapCmd.Flags().AddFlagSet(flags.InitBootstrapFlagSet())

rootCmd.AddCommand(lintCmd)
rootCmd.AddCommand(genCmd)
rootCmd.AddCommand(bootstrapCmd)
rootCmd.Flags().AddFlagSet(flags.InitDefaultFlagSet())

err := rootCmd.Execute()
Expand Down
Loading