-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1337492
commit 5ae5e5e
Showing
9 changed files
with
409 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
dockerfile-inspector | ||
config.yaml |
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 @@ | ||
## Dockerfile Inspector |
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,73 @@ | ||
package cmd | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
var ( | ||
dockerFilePath string | ||
outputFormat string | ||
logLevel string | ||
logFmt string | ||
version string | ||
dockerFileContent *os.File | ||
) | ||
|
||
func init() { | ||
rootCmd.PersistentFlags().StringVarP(&dockerFilePath, "docker.file", "d", "Dockerfile", "Location of Dockerfile.") | ||
rootCmd.PersistentFlags().StringVarP(&outputFormat, "ouput.format", "o", "table", "Output format of report, available options - json, table, xml") | ||
rootCmd.PersistentFlags().StringVarP(&dockerFilePath, "docker.file", "d", "Dockerfile", "Location of Dockerfile.") | ||
rootCmd.PersistentFlags().StringVarP(&logLevel, "log.level", "", logrus.InfoLevel.String(), "dockerfile-inspector logging level.") | ||
rootCmd.PersistentFlags().StringVarP(&logFmt, "log.format", "", "text", "dockerfile-inspector log format.") | ||
flag.Parse() | ||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine) | ||
} | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "dockerfile-inspector", | ||
Short: "dockerfile-inspector", | ||
Long: `A tool for checking Dockerfile best practices.`, | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
parsedLevel, err := logrus.ParseLevel(logLevel) | ||
if err != nil { | ||
logrus.Errorf("log-level flag has invalid value %s", logLevel) | ||
} else { | ||
logrus.SetLevel(parsedLevel) | ||
} | ||
if logFmt == "json" { | ||
logrus.SetFormatter(&logrus.JSONFormatter{}) | ||
} else { | ||
logrus.SetFormatter(&logrus.TextFormatter{ | ||
DisableColors: true, | ||
FullTimestamp: true, | ||
}) | ||
} | ||
dockerFileContent, err = os.Open(dockerFilePath) | ||
if err != nil { | ||
logrus.Errorf("Error parsing config at %s: %v", dockerFilePath, err) | ||
os.Exit(1) | ||
} | ||
|
||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := cmd.Help() | ||
if err != nil { | ||
logrus.Error(err) | ||
} | ||
os.Exit(1) | ||
}, | ||
} | ||
|
||
// Execute the stuff | ||
func Execute(VERSION string) { | ||
version = VERSION | ||
if err := rootCmd.Execute(); err != nil { | ||
logrus.Error(err) | ||
os.Exit(1) | ||
} | ||
} |
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,21 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Prints the current version.", | ||
Long: `Prints the current version of dockerfile-inspector.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
versionOutput := fmt.Sprintf("dockerfile-inspector %s", version) | ||
fmt.Println(versionOutput) | ||
}, | ||
} |
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,9 @@ | ||
module dockerfile-inspector | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/sirupsen/logrus v1.7.0 | ||
github.com/spf13/cobra v1.1.1 | ||
github.com/spf13/pflag v1.0.5 | ||
) |
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,14 @@ | ||
package main | ||
|
||
import ( | ||
"dockerfile-inspector/cmd" | ||
) | ||
|
||
const ( | ||
// Version represents the current release version of dockerfile-inspector | ||
Version = "0.1" | ||
) | ||
|
||
func main() { | ||
cmd.Execute(Version) | ||
} |
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 @@ | ||
package rule |
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 @@ | ||
package utils |