diff --git a/Dockerfile b/Dockerfile index 591e3907..34a780c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,10 @@ FROM alpine:latest -ARG TERRAFORM_VERSION=0.9.8 -ARG TERRAFORM_QUANTUM=0.1 -ARG TERRAGRUNT_VERSION=0.12.18.04 -ARG GOTEMPLATE_VERSION=1.0 +ARG TERRAFORM_VERSION=0.9.11 +ARG TERRAFORM_QUANTUM=0.2 +ARG TERRAGRUNT_VERSION=0.12.24.01 +ARG GOTEMPLATE_VERSION=1.01 +ARG TFLINT_VERSION=0.3.6 LABEL vendor="Coveo" LABEL maintainer "jgiroux@coveo.com" @@ -11,9 +12,10 @@ LABEL maintainer "jgiroux@coveo.com" RUN apk update && apk add openssl ca-certificates RUN wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -O terraform.zip && unzip terraform.zip && mv terraform /usr/local/bin && rm terraform.zip -RUN wget https://github.com/coveo/terraform-provider-quantum/releases/download/v${TERRAFORM_QUANTUM}/terraform-provider-quantum_linux -O /usr/local/bin/terraform-provider-quantum && chmod +x /usr/local/bin/terraform-provider-quantum +RUN wget https://github.com/coveo/terraform-provider-quantum/releases/download/v${TERRAFORM_QUANTUM}/terraform-provider-quantum_linux_x64 -O /usr/local/bin/terraform-provider-quantum && chmod +x /usr/local/bin/terraform-provider-quantum RUN wget https://github.com/coveo/terragrunt/releases/download/v${TERRAGRUNT_VERSION}/terragrunt_linux_amd64 -O /usr/bin/terragrunt && chmod +x /usr/bin/terragrunt RUN wget https://github.com/coveo/gotemplate/releases/download/v${GOTEMPLATE_VERSION}/gotemplate_linux -O /usr/bin/gotemplate && chmod +x /usr/bin/gotemplate +RUN wget https://github.com/wata727/tflint/releases/download/v${TFLINT_VERSION}/tflint_linux_amd64.zip -O tflint.zip && unzip tflint.zip && mv tflint /usr/local/bin && rm tflint.zip RUN apk add bash zsh fish RUN apk add py2-pip python3 diff --git a/Dockerfile.Base b/Dockerfile.Base index 95b71524..95354d41 100644 --- a/Dockerfile.Base +++ b/Dockerfile.Base @@ -1,8 +1,8 @@ FROM alpine:latest -ARG TERRAFORM_VERSION=0.9.8 -ARG TERRAGRUNT_VERSION=0.12.18.04 -ARG GOTEMPLATE_VERSION=1.0 +ARG TERRAFORM_VERSION=0.9.11 +ARG TERRAGRUNT_VERSION=0.12.24.01 +ARG GOTEMPLATE_VERSION=1.01 LABEL vendor="Coveo" LABEL maintainer "jgiroux@coveo.com" diff --git a/Dockerfile.Full b/Dockerfile.Full index ba7d0399..7736f81e 100644 --- a/Dockerfile.Full +++ b/Dockerfile.Full @@ -1,9 +1,11 @@ FROM ubuntu:latest -ARG TERRAFORM_VERSION=0.9.8 -ARG TERRAFORM_QUANTUM=0.1 -ARG TERRAGRUNT_VERSION=0.12.18.04 -ARG GOTEMPLATE_VERSION=1.0 +ARG TERRAFORM_VERSION=0.9.11 +ARG TERRAFORM_QUANTUM=0.2 +ARG TERRAGRUNT_VERSION=0.12.24.01 +ARG GOTEMPLATE_VERSION=1.01 +ARG TFLINT_VERSION=0.3.6 + ARG DEBIAN_FRONTEND=noninteractive LABEL vendor="Coveo" @@ -45,9 +47,10 @@ RUN powershell -c Install-Package AWSPowerShell.NetCore -Force > /dev/null # Installiing terraform and terragrunt RUN curl -sL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -o terraform.zip && unzip terraform.zip && mv terraform /usr/local/bin && rm terraform.zip -RUN curl -sL https://github.com/coveo/terraform-provider-quantum/releases/download/v${TERRAFORM_QUANTUM}/terraform-provider-quantum_linux -o /usr/local/bin/terraform-provider-quantum && chmod +x /usr/local/bin/terraform-provider-quantum +RUN curl -sL https://github.com/coveo/terraform-provider-quantum/releases/download/v${TERRAFORM_QUANTUM}/terraform-provider-quantum_linux_x64 -o /usr/local/bin/terraform-provider-quantum && chmod +x /usr/local/bin/terraform-provider-quantum RUN curl -sL https://github.com/coveo/terragrunt/releases/download/v${TERRAGRUNT_VERSION}/terragrunt_linux_amd64 -o /usr/bin/terragrunt && chmod +x /usr/bin/terragrunt RUN curl -sL https://github.com/coveo/gotemplate/releases/download/v${GOTEMPLATE_VERSION}/gotemplate_linux -o /usr/bin/gotemplate && chmod +x /usr/bin/gotemplate +RUN curl -sL https://github.com/wata727/tflint/releases/download/v${TFLINT_VERSION}/tflint_linux_amd64.zip -o tflint.zip && unzip tflint.zip && mv tflint /usr/local/bin && rm tflint.zip # Install JQ RUN apt-get -y install jq diff --git a/config.go b/config.go index 9cbe2ab4..7f872b0b 100644 --- a/config.go +++ b/config.go @@ -1,8 +1,9 @@ package main import ( - "github.com/gruntwork-io/terragrunt/util" "time" + + aws "github.com/gruntwork-io/terragrunt/aws_helper" ) type tgfConfig struct { @@ -18,15 +19,14 @@ func getDefaultValues() tgfConfig { LogLevel: "notice", } - tags, _ := util.GetSecurityGroupTags("terragrunt-default") - if image, ok := tags["tgf_docker_image"]; ok { + if image, err := aws.GetSSMParameter("/default/tgf/docker-image", ""); err == nil { config.Image = image } - if refresh, ok := tags["tgf_docker_refresh"]; ok { + if refresh, err := aws.GetSSMParameter("/default/tgf/docker-refresh", ""); err == nil { duration := Must(time.ParseDuration(refresh)).(time.Duration) config.Refresh = duration } - if logLevel, ok := tags["tgf_logging_level"]; ok { + if logLevel, err := aws.GetSSMParameter("/default/tgf/logging-level", ""); err == nil { config.LogLevel = logLevel } diff --git a/main.go b/main.go index e3e4e7b6..c651a867 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,11 @@ package main import ( "fmt" - "gopkg.in/alecthomas/kingpin.v2" "os" + "path/filepath" "strings" + + "gopkg.in/alecthomas/kingpin.v2" ) func main() { @@ -41,9 +43,11 @@ func main() { config.Image = strings.Join([]string{split[0], *tag}, ":") } - if lastRefresh(config.Image) > config.Refresh || !checkImage(config.Image) || *refresh { + if !isVersionedImage(config.Image) && lastRefresh(config.Image) > config.Refresh || !checkImage(config.Image) || *refresh { refreshImage(config.Image) } + os.Setenv("TERRAGRUNT_CACHE", filepath.Join("/local", os.TempDir(), "tgf-cache")) + callDocker(config.Image, config.LogLevel, *entryPoint, unmanaged...) } diff --git a/touch.go b/touch.go index 6cf02fa7..f3207dbb 100644 --- a/touch.go +++ b/touch.go @@ -1,11 +1,13 @@ package main import ( - "github.com/gruntwork-io/terragrunt/util" "os" "os/user" "path/filepath" + "regexp" "time" + + "github.com/gruntwork-io/terragrunt/util" ) func getTouchFilename(image string) string { @@ -42,3 +44,11 @@ func touchImageRefresh(image string) { func lastRefresh(image string) time.Duration { return time.Since(getLastRefresh(image)) } + +// By default, versionned images do not need to be refreshed since they should never +// been overwritten with a different version without being tagged with a new version. +func isVersionedImage(image string) bool { + return versionRegex.MatchString(image) +} + +var versionRegex = regexp.MustCompile(`[vV]?\d+\.\d+`)