Skip to content

Commit

Permalink
cmd: introduce subcommands for gokakashi (#21)
Browse files Browse the repository at this point in the history
* cmd: introduce subcommands for gokakashi

* fix docker file

* explicitly ignore error in help command
  • Loading branch information
scriptnull authored Oct 18, 2024
1 parent 77acf2d commit b711916
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN go mod tidy
COPY . .

# Build the Go binary for amd64
RUN GOARCH=amd64 go build -o goKakashi ./cmd/goKakashi.go
RUN GOARCH=amd64 go build -o gokakashi

# Stage 2: Final image for running the application with Alpine
FROM alpine:3.20
Expand Down Expand Up @@ -48,7 +48,7 @@ WORKDIR /app
RUN mkdir -p /app/website

# Copy the Go binary from the builder stage
COPY --from=builder /app/goKakashi /app/goKakashi
COPY --from=builder /app/gokakashi /app/gokakashi

# Expose ports
EXPOSE 8080
Expand All @@ -60,7 +60,7 @@ ENV DOCKER_PASSWORD="your-dockerhub-password"
ENV LINEAR_API_KEY="your-linear-api-key"

# Make sure the binary is executable
RUN chmod +x /app/goKakashi
RUN chmod +x /app/gokakashi

# Set the entrypoint to the application binary
ENTRYPOINT ["/app/goKakashi"]
ENTRYPOINT ["/app/gokakashi"]
29 changes: 29 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "gokakashi",
Short: "GoKakashi - The Container image vulnerability management platform",
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
}

func init() {
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(serverCmd)
rootCmd.AddCommand(scanCmd)
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
14 changes: 14 additions & 0 deletions cmd/scan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cmd

import (
"github.com/spf13/cobra"
)

var scanCmd = &cobra.Command{
Use: "scan",
Short: "Scan a container image",
Run: scanImage,
}

func scanImage(cmd *cobra.Command, args []string) {
}
11 changes: 9 additions & 2 deletions cmd/goKakashi.go → cmd/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cmd

import (
"flag"
Expand All @@ -14,9 +14,16 @@ import (
"github.com/ashwiniag/goKakashi/pkg/utils"
"github.com/ashwiniag/goKakashi/pkg/web"
"github.com/robfig/cron/v3"
"github.com/spf13/cobra"
)

func main() {
var serverCmd = &cobra.Command{
Use: "server",
Short: "Start the GoKakshi Server",
Run: runServer,
}

func runServer(cmd *cobra.Command, args []string) {
log.Println("=== Starting goKakashi Tool ===")

// Get config file from command-line argument
Expand Down
15 changes: 15 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("v0.0.4")
},
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ require (
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand All @@ -14,8 +17,14 @@ github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzG
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/ashwiniag/goKakashi/cmd"

func main() {
cmd.Execute()
}

0 comments on commit b711916

Please sign in to comment.