Skip to content

Commit

Permalink
feat: config command runner (#6)
Browse files Browse the repository at this point in the history
* feat: allow running of external commands like kubectx

* fix: documentation and such
  • Loading branch information
jeff-roche committed Jun 13, 2022
1 parent fead4fb commit 473706c
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 16 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ environment:
...
```

### Commands
Additional commands can be run using the commands setting. Any commands specified will be run as the last steps prior to running the top level command specified when running biome.

```yaml
# .biome.yaml
name: my-biome
commands:
- kubectx my-k8s-context
environment:
...
```


## Usage
The most common use case is for use with scripts that need context via environment variables. The need for this tool came about for CI/CD scripts that need AWS context as well as additional environment variables that change based on certain states. This tool will allow you to configure those different states and provide that context to your scripts and pipelines.
Expand Down Expand Up @@ -65,5 +77,6 @@ $ onstaging ./bin/ci/deploy-service.sh
- :white_check_mark: Implement some tests
- Loading Environment variables from a .env file
- :white_check_mark: Encrypted environment variables via [dragoman](https://github.com/meltwater/dragoman)
- Kubernetes context setting
- :white_check_mark: Kubernetes context setting
- *NOTE* this is done through commands
- Potentially switching to [cobra](https://github.com/spf13/cobra) for the cli
9 changes: 7 additions & 2 deletions example.biome.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ environment: # Additional environment vars to load in
MY_USEFUL_ENV: "A value I need"
MY_OTHER_ENV: "Another value I need"
MY_AWS_SECRET_ENV:
secret_arn: "{{ARN}}"
secret_json_key: "my_super_secret_key"
secret_arn: "{{ARN}}" # Secrets manager ARN
secret_json_key: "my_super_secret_key" # JSON key in the secret
MY_DRAGOMAN_SECRET_ENV:
from_dragoman: "[ENC,...]" # Tells the biome to decrypt this secret
commands: # Any additional config steps needed, this is the last thing run
- kubectx my-k8s-context
- npm run someconfigscript

---

Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.11.7 // indirect
github.com/aws/smithy-go v1.11.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/objx v0.2.0 // indirect
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
16 changes: 12 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,31 @@ github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/meltwater/dragoman v1.2.2 h1:ZdpdB2vkm9grPjqvp9/6eZEmGubCQtVPuMUi4NDgdoE=
github.com/meltwater/dragoman v1.2.2/go.mod h1:waYPsylnXTj4F7xblDEeDEKqxNPZjkqcLYd/6DaUoOM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce h1:Roh6XWxHFKrPgC/EQhVubSAGQ6Ozk6IdxHSzt1mR0EI=
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
9 changes: 2 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"flag"
"fmt"
"log"
"os"
"os/exec"

"github.com/jeff-roche/biome/src/lib/cmdr"
"github.com/jeff-roche/biome/src/services"
)

Expand Down Expand Up @@ -51,11 +50,7 @@ func main() {
}

// Execute order 66
cmd := exec.Command(cmds[0], cmds[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
if err := cmd.Run(); err != nil {
if err := cmdr.Run(cmds[0], cmds[1:]...); err != nil {
log.Fatal(err)
}
}
20 changes: 20 additions & 0 deletions src/lib/cmdr/cmdr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmdr

import (
"os"
"os/exec"
)

func Run(cmdStr string, args ...string) error {
cmd := exec.Command(cmdStr, args...)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin

if err := cmd.Run(); err != nil {
return err
}

return nil
}
1 change: 1 addition & 0 deletions src/lib/types/biome.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ type Biome struct {
type BiomeConfig struct {
Name string
AwsProfile string `yaml:"aws_profile"`
Commands []string `yaml:"commands"`
Environment map[string]interface{} `yaml:"environment"`
}
2 changes: 1 addition & 1 deletion src/repos/dragoman.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package repos

import "github.com/meltwater/dragoman/cryptography"

// The interface for the Secrets Manager Repository
// The interface for the Dragoman Repository
type DragomanRepoIfc interface {
Decrypt(string) (string, error)
}
Expand Down
11 changes: 11 additions & 0 deletions src/services/biome_configuration_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package services
import (
"fmt"
"path"
"strings"

"github.com/jeff-roche/biome/src/lib/cmdr"
"github.com/jeff-roche/biome/src/lib/fileio"
"github.com/jeff-roche/biome/src/lib/setters"
"github.com/jeff-roche/biome/src/lib/types"
Expand Down Expand Up @@ -98,5 +100,14 @@ func (svc *BiomeConfigurationService) ActivateBiome() error {
}
}

// Any other environment setup commands
if len(svc.ActiveBiome.Config.Commands) > 0 {
for _, cmd := range svc.ActiveBiome.Config.Commands {
parts := strings.Split(cmd, " ")

cmdr.Run(parts[0], parts[1:]...)
}
}

return nil
}

0 comments on commit 473706c

Please sign in to comment.