Skip to content

Commit

Permalink
Initial codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
iamabhishek-dubey committed Nov 11, 2020
1 parent 1337492 commit 5ae5e5e
Show file tree
Hide file tree
Showing 9 changed files with 409 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
dockerfile-inspector
config.yaml
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Dockerfile Inspector
73 changes: 73 additions & 0 deletions cmd/root.go
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)
}
}
21 changes: 21 additions & 0 deletions cmd/version.go
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)
},
}
9 changes: 9 additions & 0 deletions go.mod
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
)
289 changes: 289 additions & 0 deletions go.sum

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions main.go
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)
}
1 change: 1 addition & 0 deletions pkg/rule/rule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package rule
1 change: 1 addition & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package utils

0 comments on commit 5ae5e5e

Please sign in to comment.