Skip to content

Commit

Permalink
Merge pull request #12 from Krzysztof-Szyper-Epam/merge-with-fmt
Browse files Browse the repository at this point in the history
Merge with docker-terragrunt-fmt
  • Loading branch information
ChristophShyper authored Nov 22, 2019
2 parents 1a42bc8 + e0ed8e0 commit f282dcd
Show file tree
Hide file tree
Showing 24 changed files with 2,244 additions and 492 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,8 @@ dmypy.json
# Pyre type checker
.pyre/

# build version
version.txt

# intellij
.idea/
30 changes: 17 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN set -eux \
unzip

# Get Terraform
# Contrary to orignal by cytopia (https://github.com/cytopia) TF_VERSION needs to point to explicit version, e.g. 0.12.16
ARG TF_VERSION=latest
RUN set -eux \
&& if [ "${TF_VERSION}" = "latest" ]; then \
Expand All @@ -22,7 +23,7 @@ RUN set -eux \
else \
VERSION="$( curl -sS https://releases.hashicorp.com/terraform/ \
| tac | tac \
| grep -Eo "/${TF_VERSION}\.[.0-9]+/" \
| grep -Eo "/${TF_VERSION}/" \
| grep -Eo '[.0-9]+' \
| sort -V \
| tail -1 )"; \
Expand All @@ -34,42 +35,41 @@ RUN set -eux \
&& chmod +x /usr/bin/terraform

# Get Terragrunt
# Contrary to orignal by cytopia (https://github.com/cytopia) TG_VERSION needs to point to explicit version, e.g. 0.21.6
ARG TG_VERSION=latest
RUN set -eux \
&& git clone https://github.com/gruntwork-io/terragrunt /terragrunt \
&& cd /terragrunt \
&& if [ "${TG_VERSION}" = "latest" ]; then \
VERSION="$( git describe --abbrev=0 --tags )"; \
else \
VERSION="$( git tag | grep -E "v${TG_VERSION}\.[.0-9]+" | sort -u | tail -1 )" ;\
VERSION="$( git tag | grep -E "v${TG_VERSION}" | sort -u | tail -1 )" ;\
fi \
&& curl -sS -L \
https://github.com/gruntwork-io/terragrunt/releases/download/${VERSION}/terragrunt_linux_amd64 \
-o /usr/bin/terragrunt \
&& chmod +x /usr/bin/terragrunt

# Get Scenery
ARG SC_VERSION=latest
# Get latest Scenery
# This part was added
RUN set -eux \
&& git clone https://github.com/dmlittle/scenery /scenery \
&& cd /scenery \
&& if [ "${SC_VERSION}" = "latest" ]; then \
VERSION="$( git describe --abbrev=0 --tags )"; \
else \
VERSION="$( git tag | grep -E "${SC_VERSION}\.[.0-9]+" | sort -u | tail -1 )" ;\
fi \
&& VERSION="$( git describe --abbrev=0 --tags )"
&& curl -sS -L \
https://github.com/dmlittle/scenery/releases/download/${VERSION}/scenery-${VERSION}-linux-amd64 \
-o /usr/bin/scenery \
&& chmod +x /usr/bin/scenery

# Use a clean tiny image to store artifacts in
FROM alpine:3.9
# This part was eddited
LABEL \
maintainer="cytopia <cytopia@everythingcli.org>" \
repo="https://github.com/cytopia/docker-terragrunt" \
modifiedby="Krzysztof Szyper <krzysztof_szyper@epam.com>" \
modifiedrepo="https://github.com/Krzysztof-Szyper-Epam/docker-terragrunt"
maintainer="Krzysztof Szyper <krzysztof_szyper@epam.com>" \
repo="https://github.com/Krzysztof-Szyper-Epam/docker-terragrunt" \
original_maintainer="cytopia <cytopia@everythingcli.org>" \
original_repo="https://github.com/cytopia/docker-terragrunt"
# This part has some additions
RUN set -eux \
&& apk add --no-cache git \
&& apk add --no-cache make \
Expand All @@ -87,6 +87,10 @@ RUN set -eux \
&& python -m pip install ply \
&& python -m pip install pyhcl \
&& python -m pip install awscli
# This part was added and edited
COPY fmt/format-hcl.sh /usr/bin/format-hcl.sh
COPY fmt/fmt.sh /fmt.sh
COPY fmt/terragrunt-fmt.sh /terragrunt-fmt.sh
COPY --from=builder /usr/bin/terraform /usr/bin/terraform
COPY --from=builder /usr/bin/terragrunt /usr/bin/terragrunt
COPY --from=builder /usr/bin/scenery /usr/bin/scenery
Expand Down
173 changes: 45 additions & 128 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,132 +1,49 @@
ifneq (,)
.error This Makefile requires GNU Make.
endif

.PHONY: build rebuild lint test _test-tf-version _test-tg-version _test-tf _test-tg tag pull login push enter

CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

DIR = .
FILE = Dockerfile
IMAGE = cytopia/terragrunt
TAG = latest

TF_VERSION = latest
TG_VERSION = latest

build:
docker build --build-arg TF_VERSION=$(TF_VERSION) --build-arg TG_VERSION=$(TG_VERSION) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)

rebuild: pull
docker build --no-cache --build-arg TF_VERSION=$(TF_VERSION) --build-arg TG_VERSION=$(TG_VERSION) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)

lint:
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-cr --text --ignore '.git/,.github/,tests/' --path .
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-crlf --text --ignore '.git/,.github/,tests/' --path .
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-trailing-single-newline --text --ignore '.git/,.github/,tests/' --path .
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-trailing-space --text --ignore '.git/,.github/,tests/' --path .
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-utf8 --text --ignore '.git/,.github/,tests/' --path .
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-utf8-bom --text --ignore '.git/,.github/,tests/' --path .
# Provide versions of Terraform and Terragrunt to use with this Docker image
TF_VERSION ?= 0.12.16
TG_VERSION ?= 0.21.6

# Constants
CURRENT_BRANCH := ${bamboo_planRepository_branchName}
RELEASE_BRANCH := master
DOCKER_NAME := krzysztofszyperepam/docker-terragrunt

# Version tag taken from environment, file, or calculated date
VERSION_FILE := version.txt
ifdef VERSION
$(shell echo "version=$(VERSION)" > $(VERSION_FILE))
$(info using version $(VERSION) from parameter input or environment)
else ifneq ("$(wildcard $(VERSION_FILE))","")
VERSION=$(shell awk -F'=' '/version/{print $$2}' $(VERSION_FILE))
$(info using version $(VERSION) from file $(VERSION_FILE))
else
VERSION=$(shell date -u +"%Y-%m-%dT%H-%M-%SZ")
$(shell echo "version=$(VERSION)" > $(VERSION_FILE))
$(info using version $(VERSION) which is self-calculated)
endif

test:
@$(MAKE) --no-print-directory _test-tf-version
@$(MAKE) --no-print-directory _test-tg-version
@$(MAKE) --no-print-directory _test-tf
@$(MAKE) --no-print-directory _test-tg

_test-tf-version:
@echo "------------------------------------------------------------"
@echo "- Testing correct Terraform version"
@echo "------------------------------------------------------------"
@if [ "$(TF_VERSION)" = "latest" ]; then \
echo "Fetching latest version from HashiCorp release page"; \
LATEST="$$( \
curl -L -sS https://releases.hashicorp.com/terraform/ \
| tac | tac \
| grep -Eo '/[.0-9]+/' \
| grep -Eo '[.0-9]+' \
| sort -V \
| tail -1 \
)"; \
echo "Testing for latest: $${LATEST}"; \
if ! docker run --rm $(IMAGE) terraform --version | grep -E "^Terraform[[:space:]]*v?$${LATEST}$$"; then \
echo "Failed"; \
exit 1; \
fi; \
else \
echo "Testing for tag: $(TF_VERSION)"; \
if ! docker run --rm $(IMAGE) terraform --version | grep -E "^Terraform[[:space:]]*v?$(TF_VERSION)\.[.0-9]+$$"; then \
echo "Failed"; \
exit 1; \
fi; \
fi; \
echo "Success"; \

_test-tg-version:
@echo "------------------------------------------------------------"
@echo "- Testing correct Terragrunt version"
@echo "------------------------------------------------------------"
@if [ "$(TG_VERSION)" = "latest" ]; then \
echo "Fetching latest version from GitHub"; \
LATEST="$$( \
curl -L -sS https://github.com/gruntwork-io/terragrunt/releases \
| tac | tac \
| grep -Eo '/v[.0-9]+/' \
| grep -Eo 'v[.0-9]+' \
| sort -u \
| sort -V \
| tail -1 \
)"; \
echo "Testing for latest: $${LATEST}"; \
if ! docker run --rm $(IMAGE) terragrunt --version | grep -E "^terragrunt[[:space:]]*version[[:space:]]*v?$${LATEST}$$"; then \
echo "Failed"; \
exit 1; \
fi; \
else \
echo "Testing for tag: $(TG_VERSION)"; \
if ! docker run --rm $(IMAGE) terragrunt --version | grep -E "^terragrunt[[:space:]]*version[[:space:]]*v?$(TG_VERSION)\.[.0-9]+$$"; then \
echo "Failed"; \
exit 1; \
fi; \
fi; \
echo "Success"; \

_test-tf:
@echo "------------------------------------------------------------"
@echo "- Testing Terraform"
@echo "------------------------------------------------------------"
@if ! docker run --rm -v $(CURRENT_DIR)/tests/terraform:/data $(IMAGE) terraform fmt; then \
echo "Failed"; \
exit 1; \
fi; \
echo "Success";

_test-tg:
@echo "------------------------------------------------------------"
@echo "- Testing Terragrunt"
@echo "------------------------------------------------------------"
@if ! docker run --rm -v $(CURRENT_DIR)/tests/terragrunt:/data $(IMAGE) terragrunt terragrunt-info; then \
docker run --rm -v $(CURRENT_DIR)/tests/terragrunt:/data $(IMAGE) sh -c "if test -d .terragrunt-cache; then rm -rf .terragrunt-cache; fi"; \
echo "Failed"; \
exit 1; \
fi; \
docker run --rm -v $(CURRENT_DIR)/tests/terragrunt:/data $(IMAGE) sh -c "if test -d .terragrunt-cache; then rm -rf .terragrunt-cache; fi"; \
echo "Success";

tag:
docker tag $(IMAGE) $(IMAGE):$(TAG)

pull:
@grep -E '^\s*FROM' Dockerfile \
| sed -e 's/^FROM//g' -e 's/[[:space:]]*as[[:space:]]*.*$$//g' \
| xargs -n1 docker pull;

login:
yes | docker login --username $(USER) --password $(PASS)

push:
@$(MAKE) tag TAG=$(TAG)
docker push $(IMAGE):$(TAG)
@echo version: $(VERSION)

clean:
rm -f $(VERSION_FILE)

docker-create:
docker rm $(DOCKER_NAME):latest || true
docker build \
--build-arg TF_VERSION=$(TF_VERSION) \
--build-arg TG_VERSION=$(TG_VERSION) \
--file=Dockerfile \
--tag=$(DOCKER_NAME):$(VERSION) .

docker-push:
ifeq ($(CURRENT_BRANCH),$(RELEASE_BRANCH))
docker tag $(DOCKER_NAME):$(VERSION) $(DOCKER_NAME):latest
docker push $(DOCKER_NAME):$(VERSION)
docker push $(DOCKER_NAME):latest
else
docker tag $(DOCKER_NAME):$(VERSION) $(DOCKER_NAME):$(CURRENT_BRANCH)-$(VERSION)
docker push $(DOCKER_NAME):$(CURRENT_BRANCH)-$(VERSION)
endif

enter:
docker run --rm --name $(subst /,-,$(IMAGE)) -it --entrypoint=/bin/sh $(ARG) $(IMAGE):$(TAG)
build-deploy: clean docker-create docker-push
Loading

0 comments on commit f282dcd

Please sign in to comment.