Skip to content

Commit

Permalink
- Add an option to make the mapping of the home directory optional
Browse files Browse the repository at this point in the history
- Add an option to configure the AWS profile
- Add an option to set the logging level

- Update terragrunt to v0.12.24.10
  • Loading branch information
jocgir committed Jul 26, 2017
1 parent 89a01b6 commit 32ad28c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.Base
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.Full
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,16 +108,19 @@ Note: *The key names are not case sensitive*
> tgf
usage: tgf [<flags>]
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=<level> 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
Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...)
Expand Down
23 changes: 18 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"strings"

"github.com/coveo/terragrunt/aws_helper"
"gopkg.in/alecthomas/kingpin.v2"
)

Expand All @@ -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("<level>").String()
noHome = app.Switch("no-home", "Disable the mapping of the home directory").Bool()
)
app.Author("Coveo")
kingpin.CommandLine = app.Application
Expand Down Expand Up @@ -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)
}
Expand All @@ -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...)
}

0 comments on commit 32ad28c

Please sign in to comment.