From 32ad28ce60f9e4bd5dbaf2b41e94ebe8a20af9c3 Mon Sep 17 00:00:00 2001 From: Jocelyn Giroux Date: Wed, 26 Jul 2017 13:12:50 -0400 Subject: [PATCH] - Add an option to make the mapping of the home directory optional - Add an option to configure the AWS profile - Add an option to set the logging level - Update terragrunt to v0.12.24.10 --- Dockerfile | 2 +- Dockerfile.Base | 2 +- Dockerfile.Full | 2 +- README.md | 21 ++++++++++++--------- docker.go | 10 +++++++--- main.go | 23 ++++++++++++++++++----- 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 22ebd79..c7ce6b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM alpine:latest ARG TERRAFORM_VERSION=0.9.11 ARG TERRAFORM_QUANTUM=0.3.5 -ARG TERRAGRUNT_VERSION=0.12.24.08 +ARG TERRAGRUNT_VERSION=0.12.24.10 ARG GOTEMPLATE_VERSION=1.01 ARG TFLINT_VERSION=0.3.6 ARG JSON2HCL_VERSION=0.0.6 diff --git a/Dockerfile.Base b/Dockerfile.Base index c02e3f6..4f50994 100644 --- a/Dockerfile.Base +++ b/Dockerfile.Base @@ -1,7 +1,7 @@ FROM alpine:latest ARG TERRAFORM_VERSION=0.9.11 -ARG TERRAGRUNT_VERSION=0.12.24.08 +ARG TERRAGRUNT_VERSION=0.12.24.10 ARG GOTEMPLATE_VERSION=1.01 ARG EXE_FOLDER=/usr/local/bin diff --git a/Dockerfile.Full b/Dockerfile.Full index 13cfecc..8af73f6 100644 --- a/Dockerfile.Full +++ b/Dockerfile.Full @@ -2,7 +2,7 @@ FROM ubuntu:latest ARG TERRAFORM_VERSION=0.9.11 ARG TERRAFORM_QUANTUM=0.3.5 -ARG TERRAGRUNT_VERSION=0.12.24.08 +ARG TERRAGRUNT_VERSION=0.12.24.10 ARG GOTEMPLATE_VERSION=1.01 ARG TFLINT_VERSION=0.3.6 ARG JSON2HCL_VERSION=0.0.6 diff --git a/README.md b/README.md index bfd38e6..98a8274 100644 --- a/README.md +++ b/README.md @@ -38,19 +38,19 @@ or install it through command line: On `OSX`: ```bash -curl -sL https://github.com/coveo/tgf/releases/download/v1.12.2/tgf_1.12.2_macOS_64-bits.zip | bsdtar -xf- -C /usr/local/bin && chmod +x /usr/local/bin/tgf +curl -sL https://github.com/coveo/tgf/releases/download/v1.13.0/tgf_1.13.0_macOS_64-bits.zip | bsdtar -xf- -C /usr/local/bin && chmod +x /usr/local/bin/tgf ``` On `Linux`: ```bash -curl -sL https://github.com/coveo/tgf/releases/download/v1.12.2/tgf_1.12.2_linux_64-bits.zip | gzip -d > /usr/local/bin/tgf && chmod +x /usr/local/bin/tgf +curl -sL https://github.com/coveo/tgf/releases/download/v1.13.0/tgf_1.13.0_linux_64-bits.zip | gzip -d > /usr/local/bin/tgf && chmod +x /usr/local/bin/tgf ``` On `Windows` with Powershell: ```powershell -Invoke-WebRequest https://github.com/coveo/tgf/releases/download/v1.12.2/tgf_1.12.2_windows_64-bits.zip -OutFile tgf.zip +Invoke-WebRequest https://github.com/coveo/tgf/releases/download/v1.13.0/tgf_1.13.0_windows_64-bits.zip -OutFile tgf.zip ``` ## Configuration @@ -108,16 +108,19 @@ Note: *The key names are not case sensitive* > tgf usage: tgf [] -tgf v1.12.2, a docker frontend for terragrunt. Any parameter after -- will be directly sent to the command identified by entrypoint. +tgf v1.13.0, a docker frontend for terragrunt. Any parameter after -- will be directly sent to the command identified by entrypoint. Flags: -h, --help Show context-sensitive help (also try --help-long and --help-man). - -e, --entrypoint=ENTRYPOINT Override the entry point for docker whish is terragrunt by default - -i, --image=IMAGE Use the specified image instead of the default one + -e, --entrypoint=terragrunt Override the entry point for docker + -i, --image=coveo/tgf Use the specified image instead of the default one + -t, --tag=latest Use a different tag on docker image instead of the default one + -p, --profile="" Set the AWS profile configuration to use -d, --debug Print the docker command issued - -t, --tag=TAG Use a different tag on docker image instead of the default one -r, --refresh Force a refresh of the docker image -v, --version Get the current version of tgf + -l, --logging= Set the logging level (critical=0, error=1, warning=2, notice=3, info=4, debug=5) + --no-home Disable the mapping of the home directory ``` If any of the tgf arguments conflicts with an argument of the desired entry point, you must place that argument after -- to ensure that they are @@ -128,14 +131,14 @@ Example: ```bash > tgf --version -v1.12.2 +v1.13.0 ``` Returns the current version of the tgf tool ```bash > tgf -- --version -terragrunt version v0.12.24.01(Coveo) +terragrunt version v0.12.24.10(Coveo) ``` Returns the version of the default entry point (i.e. `Terragrunt`), the --version located after the -- instructs tgf to pass this argument diff --git a/docker.go b/docker.go index 648c907..20d1fa9 100644 --- a/docker.go +++ b/docker.go @@ -13,7 +13,7 @@ import ( "github.com/gruntwork-io/terragrunt/util" ) -func callDocker(config tgfConfig, args ...string) { +func callDocker(config tgfConfig, mapHome bool, args ...string) { command := append([]string{config.EntryPoint}, args...) // Change the default log level for terragrunt @@ -36,11 +36,15 @@ func callDocker(config tgfConfig, args ...string) { dockerArgs := []string{ "run", "-it", "-v", fmt.Sprintf("%v:/local", convertDrive(currentDrive)), - "-v", fmt.Sprintf("%v:%v", convertDrive(home), homeWithoutVolume), - "-e", fmt.Sprintf("HOME=%v", homeWithoutVolume), "-w", util.JoinPath("/local", strings.TrimPrefix(cwd, filepath.VolumeName(cwd))), "--rm", } + if mapHome { + dockerArgs = append(dockerArgs, []string{ + "-v", fmt.Sprintf("%v:%v", convertDrive(home), homeWithoutVolume), + "-e", fmt.Sprintf("HOME=%v", homeWithoutVolume), + }...) + } dockerArgs = append(dockerArgs, getEnviron()...) dockerArgs = append(dockerArgs, config.Image) dockerArgs = append(dockerArgs, command...) diff --git a/main.go b/main.go index 7029fa0..677a7d7 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "path/filepath" "strings" + "github.com/coveo/terragrunt/aws_helper" "gopkg.in/alecthomas/kingpin.v2" ) @@ -24,12 +25,15 @@ func main() { var ( description = fmt.Sprintf("tgf %s, a docker frontend for terragrunt. Any parameter after -- will be directly sent to the command identified by entrypoint.", version) app = NewApplication(kingpin.New(os.Args[0], description)) - defaultEntryPoint = app.Argument("entrypoint", "Override the entry point for docker (default = terragrunt)", 'e').String() - image = app.Argument("image", "Use the specified image instead of the default one", 'i').String() - debug = app.Argument("debug", "Print the docker command issued", 'd').Bool() - tag = app.Argument("tag", "Use a different tag on docker image instead of the default one", 't').String() + defaultEntryPoint = app.Argument("entrypoint", "Override the entry point for docker", 'e').PlaceHolder("terragrunt").String() + image = app.Argument("image", "Use the specified image instead of the default one", 'i').PlaceHolder("coveo/tgf").String() + tag = app.Argument("tag", "Use a different tag on docker image instead of the default one", 't').PlaceHolder("latest").String() + awsProfile = app.Argument("profile", "Set the AWS profile configuration to use", 'p').Default("").String() + debug = app.Switch("debug", "Print the docker command issued", 'd').Bool() refresh = app.Switch("refresh", "Force a refresh of the docker image", 'r').Bool() getVersion = app.Switch("version", "Get the current version of tgf", 'v').Bool() + loggingLevel = app.Argument("logging", "Set the logging level (critical=0, error=1, warning=2, notice=3, info=4, debug=5)", 'l').PlaceHolder("").String() + noHome = app.Switch("no-home", "Disable the mapping of the home directory").Bool() ) app.Author("Coveo") kingpin.CommandLine = app.Application @@ -63,6 +67,15 @@ func main() { os.Setenv("TERRAGRUNT_CACHE", filepath.Join("/local", os.TempDir(), "tgf-cache")) + if *awsProfile != "" { + os.Unsetenv("AWS_PROFILE") + aws_helper.InitAwsSession(*awsProfile) + } + + if *loggingLevel != "" { + config.LogLevel = *loggingLevel + } + if config.RecommendedMinimalVersion != "" && version < config.RecommendedMinimalVersion { fmt.Fprintf(os.Stderr, "Your version of tgf is outdated, you have %s. The recommended minimal version is %s\n\n", version, config.RecommendedMinimalVersion) } @@ -71,5 +84,5 @@ func main() { fmt.Fprintf(os.Stderr, "A new version of tgf image is available, you use %s. The recommended image is %s\n\n", config.Image, config.RecommendedImage) } - callDocker(config, unmanaged...) + callDocker(config, !*noHome, unmanaged...) }