Skip to content

Commit

Permalink
small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanmartins committed Nov 30, 2023
1 parent fb7ee98 commit b16bb32
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
dist/
ksops
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM golang:1.21-bullseye AS builder

ARG TARGETOS
ARG TARGETARCH
ARG VERSION

WORKDIR /workspace

Expand All @@ -13,7 +14,6 @@ COPY go.sum go.sum
RUN go mod download -x

# Copy the go source
COPY cmd/ cmd/
COPY pkg/ pkg/
COPY main.go ./

Expand All @@ -22,7 +22,7 @@ COPY main.go ./
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags="-w -s" -o ksops .
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags="-w -s -X main.version=${VERSION}" -o ksops .

# Runtime
FROM alpine:latest
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ files:
## Release Process
Current version: `v2.0.7`

To release a new version, install `goreleaser` and set your GitHub token:

```shell
Expand Down
53 changes: 0 additions & 53 deletions cmd/root.go

This file was deleted.

49 changes: 47 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
package main

import "github.com/argyle-engineering/ksops/v2/cmd"
import (
"github.com/argyle-engineering/ksops/v2/pkg"
"github.com/spf13/cobra"
"os"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/fn/framework"
"sigs.k8s.io/kustomize/kyaml/kio"
)

func main() {
cmd.Execute()
rootCmd.SetVersionTemplate("{{.Version}}\n")
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

var version string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "ksops",
Short: "KSOPS is a flexible Kustomize KRM-based plugin for SOPS encrypted resources",
Long: `KSOPS is a flexible Kustomize KRM-based plugin for SOPS encrypted resources.
- Provides the ability to fail silently if the generator fails to decrypt files.
- Generates dummy secrets with the 'KSOPS_GENERATE_DUMMY_SECRETS' environment variable.`,
RunE: func(cmd *cobra.Command, args []string) error {

// No config is required
p := framework.SimpleProcessor{Config: nil, Filter: kio.FilterFunc(pkg.Ksops)}

// STDIN and STDOUT will be used if no reader or writer respectively is provided.
err := framework.Execute(p, nil)

return errors.Wrap(err)
},
Version: version,
}

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.ksops.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
//rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

0 comments on commit b16bb32

Please sign in to comment.