Skip to content

Commit

Permalink
Merge pull request #1 from cytopia/release-0.1
Browse files Browse the repository at this point in the history
Initial release
  • Loading branch information
cytopia authored Jul 6, 2019
2 parents ae55ce8 + d6fd38d commit c638404
Show file tree
Hide file tree
Showing 8 changed files with 706 additions and 3 deletions.
73 changes: 73 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---

###
### Enable sudo (required for docker service)
###
sudo: required


###
### Language
###
language: minimal


###
### Add services
###
services:
- docker


###
### Build Matrix
###
env:
matrix:
- VERSION=0.12
- VERSION=latest


###
### Install requirements
###
install:
- retry() {
for ((n=0; n<10; n++)); do
echo "[${n}] ${*}";
if eval "${*}"; then
return 0;
fi;
done;
return 1;
}


###
### Check generation changes, build and test
###
before_script:
- retry make lint
- retry make build TAG=${VERSION}
- retry make test TAG=${VERSION}


###
### Push to Dockerhub
###
script:
# Push to docker hub on success
- if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
while ! make login USER="${DOCKER_USERNAME}" PASS="${DOCKER_PASSWORD}"; do sleep 1; done;
if [ -n "${TRAVIS_TAG}" ]; then
while ! make push TAG="${VERSION}-${TRAVIS_TAG}"; do sleep 1; done;
elif [ "${TRAVIS_BRANCH}" == "master" ]; then
while ! make push TAG=${VERSION}; do sleep 1; done;
elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then
while ! make push TAG="${VERSION}-${TRAVIS_BRANCH}"; do sleep 1; done;
else
echo "Skipping branch ${TRAVIS_BRANCH}";
fi
else
echo "Skipping push on PR";
fi
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM debian:stable-slim as builder

# Install build dependencies
RUN set -eux \
&& DEBIAN_FRONTEND=noninteractive apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -qq -y --no-install-recommends --no-install-suggests \
ca-certificates \
curl \
unzip

# Get Terraform
ARG TF_VERSION=latest
RUN set -eux \
&& if [ "${TF_VERSION}" = "latest" ]; then \
VERSION="$( curl -sS https://releases.hashicorp.com/terraform/ \
| tac | tac \
| grep -Eo '/[.0-9]+/' \
| grep -Eo '[.0-9]+' \
| sort -V \
| tail -1 )"; \
else \
VERSION="$( curl -sS https://releases.hashicorp.com/terraform/ \
| tac | tac \
| grep -Eo "/${TF_VERSION}\.[.0-9]+/" \
| grep -Eo '[.0-9]+' \
| sort -V \
| tail -1 )"; \
fi \
&& curl -sS -L -O \
https://releases.hashicorp.com/terraform/${VERSION}/terraform_${VERSION}_linux_amd64.zip \
&& unzip terraform_${VERSION}_linux_amd64.zip \
&& mv terraform /usr/bin/terraform \
&& chmod +x /usr/bin/terraform

# Use a clean tiny image to store artifacts in
FROM alpine:3.9
LABEL \
maintainer="cytopia <cytopia@everythingcli.org>" \
repo="https://github.com/cytopia/docker-terragrunt-fmt"
RUN set -eux \
&& apk add --no-cache bash
COPY --from=builder /usr/bin/terraform /usr/bin/terraform
COPY data/terragrunt-fmt.sh /terragrunt-fmt.sh

WORKDIR /data
ENTRYPOINT ["/terragrunt-fmt.sh"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 cytopia <https://github.com/cytopia>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
129 changes: 129 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
ifneq (,)
.error This Makefile requires GNU Make.
endif

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

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

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

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

rebuild: pull
docker build --no-cache --build-arg TF_VERSION=$(TAG) -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 .

test:
@$(MAKE) --no-print-directory _test-tf-version
@$(MAKE) --no-print-directory _test-fmt-ok
@$(MAKE) --no-print-directory _test-fmt-fail

_test-tf-version:
@echo "------------------------------------------------------------"
@echo "- Testing correct Terraform version"
@echo "------------------------------------------------------------"
@if [ "$(TAG)" = "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) --version | grep -E "^Terraform[[:space:]]*v?$${LATEST}$$"; then \
echo "Failed"; \
exit 1; \
fi; \
else \
echo "Testing for tag: $(TAG)"; \
if ! docker run --rm $(IMAGE) --version | grep -E "^Terraform[[:space:]]*v?$(TAG)\.[.0-9]+$$"; then \
echo "Failed"; \
exit 1; \
fi; \
fi; \
echo "Success"; \

_test-fmt-ok:
@echo "------------------------------------------------------------"
@echo "- Testing terragrunt-fmt (OK) [recursive]"
@echo "------------------------------------------------------------"
@if ! docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) -write=false -list=true -check -diff -recursive; then \
echo "Failed"; \
exit 1; \
fi; \
echo "Success";
@echo "------------------------------------------------------------"
@echo "- Testing terragrunt-fmt (OK) [dir]"
@echo "------------------------------------------------------------"
@if ! docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) -write=false -list=true -check -diff; then \
echo "Failed"; \
exit 1; \
fi; \
echo "Success";
@echo "------------------------------------------------------------"
@echo "- Testing terragrunt-fmt (OK) [file]"
@echo "------------------------------------------------------------"
@if ! docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) -write=false -list=true -check -diff terragrunt.hcl; then \
echo "Failed"; \
exit 1; \
fi; \
echo "Success";

_test-fmt-fail:
@echo "------------------------------------------------------------"
@echo "- Testing terragrunt-fmt (FAIL) [recursive]"
@echo "------------------------------------------------------------"
@if docker run --rm -v $(CURRENT_DIR)/tests/fail:/data $(IMAGE) -write=false -list=true -check -diff -recursive; then \
echo "Failed"; \
exit 1; \
fi; \
echo "Success";
@echo "------------------------------------------------------------"
@echo "- Testing terragrunt-fmt (FAIL) [dir]"
@echo "------------------------------------------------------------"
@if docker run --rm -v $(CURRENT_DIR)/tests/fail:/data $(IMAGE) -write=false -list=true -check -diff; then \
echo "Failed"; \
exit 1; \
fi; \
echo "Success";
@echo "------------------------------------------------------------"
@echo "- Testing terragrunt-fmt (FAIL) [file]"
@echo "------------------------------------------------------------"
@if docker run --rm -v $(CURRENT_DIR)/tests/fail:/data $(IMAGE) -write=false -list=true -check -diff terragrunt.hcl; then \
echo "Failed"; \
exit 1; \
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)

enter:
docker run --rm --name $(subst /,-,$(IMAGE)) -it --entrypoint=/bin/sh $(ARG) $(IMAGE):$(TAG)
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Tag](https://img.shields.io/github/tag/cytopia/docker-terragrunt-fmt.svg)](https://github.com/cytopia/docker-terragrunt-fmt/releases)
[![](https://images.microbadger.com/badges/version/cytopia/terragrunt-fmt:latest.svg?&kill_cache=1)](https://microbadger.com/images/cytopia/terragrunt-fmt:latest "terragrunt-fmt")
[![](https://images.microbadger.com/badges/image/cytopia/terragrunt-fmt:latest.svg?&kill_cache=1)](https://microbadger.com/images/cytopia/terragrunt-fmt:latest "terragrunt-fmt")
[![](https://img.shields.io/badge/github-cytopia%2Fdocker--terragrunt-fmt-red.svg)](https://github.com/cytopia/docker-terragrunt-fmt "github.com/cytopia/docker-terragrunt-fmt")
[![](https://img.shields.io/badge/github-cytopia%2Fdocker--terragrunt--fmt-red.svg)](https://github.com/cytopia/docker-terragrunt-fmt "github.com/cytopia/docker-terragrunt-fmt")
[![License](https://img.shields.io/badge/license-MIT-%233DA639.svg)](https://opensource.org/licenses/MIT)

> #### All [#awesome-ci](https://github.com/topics/awesome-ci) Docker images
Expand Down Expand Up @@ -53,7 +53,6 @@ they always contain the latest stable version as shown below.
|--------------|------------------------|
| `latest` | latest stable |
| `0.12` | latest stable `0.12.x` |
| `0.11` | latest stable `0.11.x` |


## Docker mounts
Expand Down Expand Up @@ -165,7 +164,7 @@ endif
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

# Adjust according to your needs
IGNORE = */.terragrunt-cache/*/.terraform/
IGNORE = */.terragrunt-cache/,*/.terraform/
FMT_VERSION = latest

help:
Expand Down
Loading

0 comments on commit c638404

Please sign in to comment.