Skip to content

Commit

Permalink
vault support
Browse files Browse the repository at this point in the history
  • Loading branch information
paramah committed Dec 9, 2021
1 parent caaa4e8 commit 0d8819f
Show file tree
Hide file tree
Showing 21 changed files with 628 additions and 155 deletions.
2 changes: 1 addition & 1 deletion app/cmd/docker/exec.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package docker

import (
"github.com/urfave/cli/v2"
"github.com/paramah/ledo/app/modules/compose"
"github.com/paramah/ledo/app/modules/context"
"github.com/urfave/cli/v2"
)

var CmdComposeExec = cli.Command{
Expand Down
51 changes: 25 additions & 26 deletions app/cmd/docker/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ var CmdDockerLogin = cli.Command{
}

var CmdDockerEcrLogin = cli.Command{
Name: "ecr",
Aliases: []string{"e"},
Flags: []cli.Flag {
&cli.StringFlag{
Name: "region",
Aliases: []string{"r"},
Usage: "aws-region",
Required: true,
EnvVars: []string{"AWS_REGION"},
},
&cli.StringFlag{
Name: "key",
Aliases: []string{"k"},
Usage: "AWS access key",
Required: true,
EnvVars: []string{"AWS_ACCESS_KEY_ID"},
},
&cli.StringFlag{
Name: "secret",
Aliases: []string{"s"},
Usage: "AWS secret key",
Required: true,
EnvVars: []string{"AWS_SECRET_ACCESS_KEY"},
},
},
Name: "ecr",
Aliases: []string{"e"},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "region",
Aliases: []string{"r"},
Usage: "aws-region",
Required: true,
EnvVars: []string{"AWS_REGION"},
},
&cli.StringFlag{
Name: "key",
Aliases: []string{"k"},
Usage: "AWS access key",
Required: true,
EnvVars: []string{"AWS_ACCESS_KEY_ID"},
},
&cli.StringFlag{
Name: "secret",
Aliases: []string{"s"},
Usage: "AWS secret key",
Required: true,
EnvVars: []string{"AWS_SECRET_ACCESS_KEY"},
},
},
Usage: "AWS Elastic Docker Registry",
Description: `Login to docker registry`,
Action: RunDockerEcrLogin,
Expand All @@ -52,4 +52,3 @@ func RunDockerEcrLogin(cmd *cli.Context) error {
docker.DockerEcrLogin(ctx)
return nil
}

2 changes: 1 addition & 1 deletion app/cmd/docker/rm.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package docker

import (
"github.com/urfave/cli/v2"
"github.com/paramah/ledo/app/modules/compose"
"github.com/paramah/ledo/app/modules/context"
"github.com/urfave/cli/v2"
)

var CmdDockerRm = cli.Command{
Expand Down
2 changes: 0 additions & 2 deletions app/cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ var CmdImage = cli.Command{
&image.CmdDockerBuild,
},
}


44 changes: 22 additions & 22 deletions app/cmd/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ var CmdDockerBuild = cli.Command{
ArgsUsage: "version",
Action: RunDockerBuild,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "stage",
Aliases: []string{"s"},
Value: "",
Usage: "select stage to build (multi-stage dockerfile)",
Required: false,
},
&cli.StringFlag{
Name: "dockerfile",
Aliases: []string{"f"},
Value: "./Dockerfile",
Usage: "select dockerfile",
Required: false,
},
&cli.StringFlag{
Name: "opts",
Aliases: []string{"o"},
Value: "--compress",
Usage: "Additional build options",
Required: false,
},
},
&cli.StringFlag{
Name: "stage",
Aliases: []string{"s"},
Value: "",
Usage: "select stage to build (multi-stage dockerfile)",
Required: false,
},
&cli.StringFlag{
Name: "dockerfile",
Aliases: []string{"f"},
Value: "./Dockerfile",
Usage: "select dockerfile",
Required: false,
},
&cli.StringFlag{
Name: "opts",
Aliases: []string{"o"},
Value: "--compress",
Usage: "Additional build options",
Required: false,
},
},
}

func RunDockerBuild(cmd *cli.Context) error {
Expand Down
5 changes: 2 additions & 3 deletions app/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ func runInitLedo(cmd *cli.Context) error {
var dockerComposeServices []helper.DockerProjectAdditionalServiceCfg
var dockerComposeModeConfig []helper.DockerComposeModeCfg


for _, composeMode := range interact.PredefinedDockerComposeModes {
var configMode bool

if composeMode == "base" {
configMode = true
} else {
configMode = interact.InitAdvancedConfigurationAsk("Configure "+composeMode+" stack?")
configMode = interact.InitAdvancedConfigurationAsk("Configure " + composeMode + " stack?")
}

if configMode == true {
Expand All @@ -89,7 +88,7 @@ func runInitLedo(cmd *cli.Context) error {
}
composeFilename := "./docker/docker-compose.yml"
if composeMode != "base" {
composeFilename = "./docker/docker-compose."+composeMode+".yml"
composeFilename = "./docker/docker-compose." + composeMode + ".yml"
}
mdCfg := helper.DockerComposeModeCfg{
DockerComposeName: composeFilename,
Expand Down
24 changes: 24 additions & 0 deletions app/cmd/secrets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"github.com/paramah/ledo/app/cmd/secrets"
"github.com/urfave/cli/v2"
)

var CmdSecrets = cli.Command{
Name: "secrets",
Aliases: []string{"s"},
Category: catHelpers,
Usage: "secrets helper",
Description: `Managing secrets with hashicorp vault.
Requires a vault server with a KV2 resource prefixed /environment to function properly.
The vault path is created from project namespace, project name and selected mode.
`,
Subcommands: []*cli.Command{
&secrets.CmdSecretsRead,
&secrets.CmdSecretsWrite,
},
}
44 changes: 44 additions & 0 deletions app/cmd/secrets/read.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package secrets

import (
"github.com/paramah/ledo/app/modules/context"
"github.com/paramah/ledo/app/modules/secrets"
"github.com/urfave/cli/v2"
)

var CmdSecretsRead = cli.Command{
Name: "read",
Aliases: []string{"r"},
Usage: "read secrets",
Description: `Read secrets from vault`,
Action: RunSecretsRead,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "addr",
Aliases: []string{"a"},
Usage: "vault address",
Required: true,
EnvVars: []string{"VAULT_ADDR"},
},
&cli.StringFlag{
Name: "token",
Aliases: []string{"t"},
Usage: "vault token",
Required: true,
EnvVars: []string{"VAULT_TOKEN"},
},
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "Debug output",
Value: false,
},
},
}

func RunSecretsRead(cmd *cli.Context) error {
ctx := context.InitCommand(cmd)
envs := secrets.SecretRead(ctx, cmd)
secrets.ParseVaultOutput(envs)
return nil
}
49 changes: 49 additions & 0 deletions app/cmd/secrets/write.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package secrets

import (
"github.com/paramah/ledo/app/modules/context"
"github.com/paramah/ledo/app/modules/secrets"
"github.com/urfave/cli/v2"
)

var CmdSecretsWrite = cli.Command{
Name: "write",
Aliases: []string{"w"},
Usage: "write secrets",
Description: `Write secrets to vault`,
Action: RunSecretsWrite,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "addr",
Aliases: []string{"a"},
Usage: "vault address",
Required: true,
EnvVars: []string{"VAULT_ADDR"},
},
&cli.StringFlag{
Name: "token",
Aliases: []string{"t"},
Usage: "vault token",
Required: true,
EnvVars: []string{"VAULT_TOKEN"},
},
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "Debug output",
Value: false,
},
&cli.PathFlag{
Name: "input",
Aliases: []string{"i"},
Usage: "read env from file",
Required: false,
},
},
}

func RunSecretsWrite(cmd *cli.Context) error {
ctx := context.InitCommand(cmd)
secrets.SecretWrite(ctx, cmd)
return nil
}
4 changes: 2 additions & 2 deletions app/modules/aws_ledo/ecr_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func EcrLogin() (*ecr.GetAuthorizationTokenOutput, error) {
var token *ecr.GetAuthorizationTokenOutput

config := &aws.Config{
Region: aws.String(getRegion()),
Region: aws.String(getRegion()),
}
sess, _ := session.NewSession(config)
_, err := sess.Config.Credentials.Get()
if err != nil {
if err != nil {
return token, err
}

Expand Down
2 changes: 1 addition & 1 deletion app/modules/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func CheckDockerComposeVersion() {
composeSemVer, _ := semver.NewVersion(composeVersion)

if !verConstraint.Check(composeSemVer) {
log.Fatal("Wrong docker-compose version, please update to "+DockerComposeVersion+" or higher.")
log.Fatal("Wrong docker-compose version, please update to " + DockerComposeVersion + " or higher.")
}
}

Expand Down
12 changes: 6 additions & 6 deletions app/modules/compose/create_compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (

func CreateComposeFile(ctx *context.LedoContext, dockerProject helper.DockerProjectCfg, composeMode string) error {
if _, err := os.Stat("./docker"); os.IsNotExist(err) {
err := os.Mkdir("./docker", 0755)
if err != nil {
log.Fatal(err)
}
err := os.Mkdir("./docker", 0755)
if err != nil {
log.Fatal(err)
}
}

log.Printf("%v", dockerProject)
Expand All @@ -29,7 +29,7 @@ func CreateComposeFile(ctx *context.LedoContext, dockerProject helper.DockerProj
composeFilename := "./docker/docker-compose.yml"

if composeMode != "base" {
composeFilename = "./docker/docker-compose."+composeMode+".yml"
composeFilename = "./docker/docker-compose." + composeMode + ".yml"
}

f, err := os.Create(composeFilename)
Expand All @@ -39,4 +39,4 @@ func CreateComposeFile(ctx *context.LedoContext, dockerProject helper.DockerProj
err = tpl.Execute(f, ctx)

return err
}
}
Loading

0 comments on commit 0d8819f

Please sign in to comment.