Skip to content

Commit c638404

Browse files
authored
Merge pull request #1 from cytopia/release-0.1
Initial release
2 parents ae55ce8 + d6fd38d commit c638404

File tree

8 files changed

+706
-3
lines changed

8 files changed

+706
-3
lines changed

.travis.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
3+
###
4+
### Enable sudo (required for docker service)
5+
###
6+
sudo: required
7+
8+
9+
###
10+
### Language
11+
###
12+
language: minimal
13+
14+
15+
###
16+
### Add services
17+
###
18+
services:
19+
- docker
20+
21+
22+
###
23+
### Build Matrix
24+
###
25+
env:
26+
matrix:
27+
- VERSION=0.12
28+
- VERSION=latest
29+
30+
31+
###
32+
### Install requirements
33+
###
34+
install:
35+
- retry() {
36+
for ((n=0; n<10; n++)); do
37+
echo "[${n}] ${*}";
38+
if eval "${*}"; then
39+
return 0;
40+
fi;
41+
done;
42+
return 1;
43+
}
44+
45+
46+
###
47+
### Check generation changes, build and test
48+
###
49+
before_script:
50+
- retry make lint
51+
- retry make build TAG=${VERSION}
52+
- retry make test TAG=${VERSION}
53+
54+
55+
###
56+
### Push to Dockerhub
57+
###
58+
script:
59+
# Push to docker hub on success
60+
- if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
61+
while ! make login USER="${DOCKER_USERNAME}" PASS="${DOCKER_PASSWORD}"; do sleep 1; done;
62+
if [ -n "${TRAVIS_TAG}" ]; then
63+
while ! make push TAG="${VERSION}-${TRAVIS_TAG}"; do sleep 1; done;
64+
elif [ "${TRAVIS_BRANCH}" == "master" ]; then
65+
while ! make push TAG=${VERSION}; do sleep 1; done;
66+
elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then
67+
while ! make push TAG="${VERSION}-${TRAVIS_BRANCH}"; do sleep 1; done;
68+
else
69+
echo "Skipping branch ${TRAVIS_BRANCH}";
70+
fi
71+
else
72+
echo "Skipping push on PR";
73+
fi

Dockerfile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
FROM debian:stable-slim as builder
2+
3+
# Install build dependencies
4+
RUN set -eux \
5+
&& DEBIAN_FRONTEND=noninteractive apt-get update -qq \
6+
&& DEBIAN_FRONTEND=noninteractive apt-get install -qq -y --no-install-recommends --no-install-suggests \
7+
ca-certificates \
8+
curl \
9+
unzip
10+
11+
# Get Terraform
12+
ARG TF_VERSION=latest
13+
RUN set -eux \
14+
&& if [ "${TF_VERSION}" = "latest" ]; then \
15+
VERSION="$( curl -sS https://releases.hashicorp.com/terraform/ \
16+
| tac | tac \
17+
| grep -Eo '/[.0-9]+/' \
18+
| grep -Eo '[.0-9]+' \
19+
| sort -V \
20+
| tail -1 )"; \
21+
else \
22+
VERSION="$( curl -sS https://releases.hashicorp.com/terraform/ \
23+
| tac | tac \
24+
| grep -Eo "/${TF_VERSION}\.[.0-9]+/" \
25+
| grep -Eo '[.0-9]+' \
26+
| sort -V \
27+
| tail -1 )"; \
28+
fi \
29+
&& curl -sS -L -O \
30+
https://releases.hashicorp.com/terraform/${VERSION}/terraform_${VERSION}_linux_amd64.zip \
31+
&& unzip terraform_${VERSION}_linux_amd64.zip \
32+
&& mv terraform /usr/bin/terraform \
33+
&& chmod +x /usr/bin/terraform
34+
35+
# Use a clean tiny image to store artifacts in
36+
FROM alpine:3.9
37+
LABEL \
38+
maintainer="cytopia <[email protected]>" \
39+
repo="https://github.com/cytopia/docker-terragrunt-fmt"
40+
RUN set -eux \
41+
&& apk add --no-cache bash
42+
COPY --from=builder /usr/bin/terraform /usr/bin/terraform
43+
COPY data/terragrunt-fmt.sh /terragrunt-fmt.sh
44+
45+
WORKDIR /data
46+
ENTRYPOINT ["/terragrunt-fmt.sh"]

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 cytopia <https://github.com/cytopia>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
ifneq (,)
2+
.error This Makefile requires GNU Make.
3+
endif
4+
5+
.PHONY: build rebuild lint test _test-tf-version _test-fmt-ok _test-fmt-fail tag pull login push enter
6+
7+
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
8+
9+
DIR = .
10+
FILE = Dockerfile
11+
IMAGE = cytopia/terragrunt-fmt
12+
TAG = latest
13+
14+
build:
15+
docker build --build-arg TF_VERSION=$(TAG) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
16+
17+
rebuild: pull
18+
docker build --no-cache --build-arg TF_VERSION=$(TAG) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
19+
20+
lint:
21+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-cr --text --ignore '.git/,.github/,tests/' --path .
22+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-crlf --text --ignore '.git/,.github/,tests/' --path .
23+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-trailing-single-newline --text --ignore '.git/,.github/,tests/' --path .
24+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-trailing-space --text --ignore '.git/,.github/,tests/' --path .
25+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-utf8 --text --ignore '.git/,.github/,tests/' --path .
26+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-utf8-bom --text --ignore '.git/,.github/,tests/' --path .
27+
28+
test:
29+
@$(MAKE) --no-print-directory _test-tf-version
30+
@$(MAKE) --no-print-directory _test-fmt-ok
31+
@$(MAKE) --no-print-directory _test-fmt-fail
32+
33+
_test-tf-version:
34+
@echo "------------------------------------------------------------"
35+
@echo "- Testing correct Terraform version"
36+
@echo "------------------------------------------------------------"
37+
@if [ "$(TAG)" = "latest" ]; then \
38+
echo "Fetching latest version from HashiCorp release page"; \
39+
LATEST="$$( \
40+
curl -L -sS https://releases.hashicorp.com/terraform/ \
41+
| tac | tac \
42+
| grep -Eo '/[.0-9]+/' \
43+
| grep -Eo '[.0-9]+' \
44+
| sort -V \
45+
| tail -1 \
46+
)"; \
47+
echo "Testing for latest: $${LATEST}"; \
48+
if ! docker run --rm $(IMAGE) --version | grep -E "^Terraform[[:space:]]*v?$${LATEST}$$"; then \
49+
echo "Failed"; \
50+
exit 1; \
51+
fi; \
52+
else \
53+
echo "Testing for tag: $(TAG)"; \
54+
if ! docker run --rm $(IMAGE) --version | grep -E "^Terraform[[:space:]]*v?$(TAG)\.[.0-9]+$$"; then \
55+
echo "Failed"; \
56+
exit 1; \
57+
fi; \
58+
fi; \
59+
echo "Success"; \
60+
61+
_test-fmt-ok:
62+
@echo "------------------------------------------------------------"
63+
@echo "- Testing terragrunt-fmt (OK) [recursive]"
64+
@echo "------------------------------------------------------------"
65+
@if ! docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) -write=false -list=true -check -diff -recursive; then \
66+
echo "Failed"; \
67+
exit 1; \
68+
fi; \
69+
echo "Success";
70+
@echo "------------------------------------------------------------"
71+
@echo "- Testing terragrunt-fmt (OK) [dir]"
72+
@echo "------------------------------------------------------------"
73+
@if ! docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) -write=false -list=true -check -diff; then \
74+
echo "Failed"; \
75+
exit 1; \
76+
fi; \
77+
echo "Success";
78+
@echo "------------------------------------------------------------"
79+
@echo "- Testing terragrunt-fmt (OK) [file]"
80+
@echo "------------------------------------------------------------"
81+
@if ! docker run --rm -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE) -write=false -list=true -check -diff terragrunt.hcl; then \
82+
echo "Failed"; \
83+
exit 1; \
84+
fi; \
85+
echo "Success";
86+
87+
_test-fmt-fail:
88+
@echo "------------------------------------------------------------"
89+
@echo "- Testing terragrunt-fmt (FAIL) [recursive]"
90+
@echo "------------------------------------------------------------"
91+
@if docker run --rm -v $(CURRENT_DIR)/tests/fail:/data $(IMAGE) -write=false -list=true -check -diff -recursive; then \
92+
echo "Failed"; \
93+
exit 1; \
94+
fi; \
95+
echo "Success";
96+
@echo "------------------------------------------------------------"
97+
@echo "- Testing terragrunt-fmt (FAIL) [dir]"
98+
@echo "------------------------------------------------------------"
99+
@if docker run --rm -v $(CURRENT_DIR)/tests/fail:/data $(IMAGE) -write=false -list=true -check -diff; then \
100+
echo "Failed"; \
101+
exit 1; \
102+
fi; \
103+
echo "Success";
104+
@echo "------------------------------------------------------------"
105+
@echo "- Testing terragrunt-fmt (FAIL) [file]"
106+
@echo "------------------------------------------------------------"
107+
@if docker run --rm -v $(CURRENT_DIR)/tests/fail:/data $(IMAGE) -write=false -list=true -check -diff terragrunt.hcl; then \
108+
echo "Failed"; \
109+
exit 1; \
110+
fi; \
111+
echo "Success";
112+
113+
tag:
114+
docker tag $(IMAGE) $(IMAGE):$(TAG)
115+
116+
pull:
117+
@grep -E '^\s*FROM' Dockerfile \
118+
| sed -e 's/^FROM//g' -e 's/[[:space:]]*as[[:space:]]*.*$$//g' \
119+
| xargs -n1 docker pull;
120+
121+
login:
122+
yes | docker login --username $(USER) --password $(PASS)
123+
124+
push:
125+
@$(MAKE) tag TAG=$(TAG)
126+
docker push $(IMAGE):$(TAG)
127+
128+
enter:
129+
docker run --rm --name $(subst /,-,$(IMAGE)) -it --entrypoint=/bin/sh $(ARG) $(IMAGE):$(TAG)

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Tag](https://img.shields.io/github/tag/cytopia/docker-terragrunt-fmt.svg)](https://github.com/cytopia/docker-terragrunt-fmt/releases)
55
[![](https://images.microbadger.com/badges/version/cytopia/terragrunt-fmt:latest.svg?&kill_cache=1)](https://microbadger.com/images/cytopia/terragrunt-fmt:latest "terragrunt-fmt")
66
[![](https://images.microbadger.com/badges/image/cytopia/terragrunt-fmt:latest.svg?&kill_cache=1)](https://microbadger.com/images/cytopia/terragrunt-fmt:latest "terragrunt-fmt")
7-
[![](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")
7+
[![](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")
88
[![License](https://img.shields.io/badge/license-MIT-%233DA639.svg)](https://opensource.org/licenses/MIT)
99

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

5857

5958
## Docker mounts
@@ -165,7 +164,7 @@ endif
165164
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
166165

167166
# Adjust according to your needs
168-
IGNORE = */.terragrunt-cache/*/.terraform/
167+
IGNORE = */.terragrunt-cache/,*/.terraform/
169168
FMT_VERSION = latest
170169

171170
help:

0 commit comments

Comments
 (0)