Skip to content

Commit 0cdb2f4

Browse files
authored
Merge pull request #28 from cytopia/release-0.15
Add terraform-docs 0.8.0 preview
2 parents 53d20b1 + 7de50d8 commit 0cdb2f4

15 files changed

+818
-53
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ env:
3333
- VERSION=0.5.0
3434
- VERSION=0.6.0
3535
- VERSION=0.7.0
36+
- VERSION=0.8.0-rc.1
37+
- VERSION=0.8.0-rc.2
3638
- VERSION=latest
3739

3840

Dockerfile renamed to Dockerfile-0.11

+2-8
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ RUN set -x \
3434
elif [ "${VERSION}" = "0.7.0" ]; then \
3535
make test \
3636
&& make gox build-all GOOS=linux GOARCH=amd64 \
37-
&& mv bin/terraform-docs-0.7.0-linux-amd64 /usr/local/bin/terraform-docs; \
38-
# Build terraform-docs latest
39-
elif [ "${VERSION}" = "latest" ]; then \
40-
go get github.com/mitchellh/gox \
41-
&& make test \
42-
&& make build-all GOOS=linux GOARCH=amd64 \
43-
&& mv bin/terraform-docs-latest-linux-amd64 /usr/local/bin/terraform-docs; \
37+
&& mv bin/terraform-docs-${VERSION}-linux-amd64 /usr/local/bin/terraform-docs; \
4438
# Build terraform-docs > 0.3.0
4539
else \
4640
make deps \
@@ -69,7 +63,7 @@ LABEL \
6963
maintainer="cytopia <[email protected]>" \
7064
repo="https://github.com/cytopia/docker-terraform-docs"
7165
COPY --from=builder /usr/local/bin/terraform-docs /usr/local/bin/terraform-docs
72-
COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh
66+
COPY ./data/docker-entrypoint-0.11.sh /docker-entrypoint.sh
7367
COPY ./data/terraform-docs.awk /terraform-docs.awk
7468

7569
ENV WORKDIR /data

Dockerfile-0.12

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
FROM golang:alpine3.9 as builder
2+
3+
# Install dependencies
4+
RUN set -x \
5+
&& apk add --no-cache \
6+
bash \
7+
curl \
8+
gcc \
9+
git \
10+
make \
11+
musl-dev \
12+
&& curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
13+
14+
# Get and build terraform-docs
15+
ARG VERSION=latest
16+
RUN set -x \
17+
&& export GOPATH=/go \
18+
&& mkdir -p /go/src/github.com/segmentio \
19+
&& git clone https://github.com/segmentio/terraform-docs /go/src/github.com/segmentio/terraform-docs \
20+
&& cd /go/src/github.com/segmentio/terraform-docs \
21+
&& if [ "${VERSION}" != "latest" ]; then \
22+
git checkout v${VERSION}; \
23+
fi \
24+
# Build terraform-docs latest
25+
&& if [ "${VERSION}" = "latest" ]; then \
26+
go get github.com/mitchellh/gox \
27+
&& make test \
28+
&& make build-all GOOS=linux GOARCH=amd64 \
29+
&& mv bin/terraform-docs-${VERSION}-linux-amd64 /usr/local/bin/terraform-docs; \
30+
# Build terraform-docs 0.8.0-rc.1 and above
31+
else \
32+
go get github.com/mitchellh/gox \
33+
&& make test \
34+
&& make build-all GOOS=linux GOARCH=amd64 \
35+
&& mv bin/terraform-docs-${VERSION}-linux-amd64 /usr/local/bin/terraform-docs; \
36+
fi \
37+
&& chmod +x /usr/local/bin/terraform-docs
38+
39+
# Version pre-check
40+
RUN set -x \
41+
&& if [ "${VERSION}" != "latest" ]; then \
42+
terraform-docs --version | grep "${VERSION}"; \
43+
else \
44+
terraform-docs --version | grep -E "(terraform-docs[[:space:]])?(version[[:space:]])?(dev|latest)"; \
45+
fi
46+
47+
48+
# Use a clean tiny image to store artifacts in
49+
FROM alpine:3.8
50+
LABEL \
51+
maintainer="cytopia <[email protected]>" \
52+
repo="https://github.com/cytopia/docker-terraform-docs"
53+
COPY --from=builder /usr/local/bin/terraform-docs /usr/local/bin/terraform-docs
54+
COPY ./data/docker-entrypoint-0.12.sh /docker-entrypoint.sh
55+
56+
ENV WORKDIR /data
57+
WORKDIR /data
58+
59+
CMD ["terraform-docs", "--version"]
60+
ENTRYPOINT ["/docker-entrypoint.sh"]

Makefile

+58-17
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,64 @@ endif
44

55
.PHONY: build rebuild lint test _test-version _test-run-one _test-run-two tag pull login push enter
66

7-
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
8-
7+
# --------------------------------------------------------------------------------------------------
8+
# VARIABLES
9+
# --------------------------------------------------------------------------------------------------
910
DIR = .
10-
FILE = Dockerfile
11+
FILE_012 = Dockerfile-0.12
12+
FILE_011 = Dockerfile-0.11
1113
IMAGE = cytopia/terraform-docs
1214
TAG = latest
15+
NO_CACHE =
16+
17+
18+
# --------------------------------------------------------------------------------------------------
19+
# DEFAULT TARGET
20+
# --------------------------------------------------------------------------------------------------
21+
help:
22+
@echo "lint Lint this repository."
23+
@echo "build [TAG=x.y.z] Build terraform-docs docker image."
24+
@echo "rebuild [TAG=x.y.z] Build terraform-docs docker image without cache."
25+
@echo "test [TAG=x.y.z] Test built terraform-docs docker image."
1326

27+
28+
# --------------------------------------------------------------------------------------------------
29+
# BUILD TARGETS
30+
# --------------------------------------------------------------------------------------------------
1431
build:
15-
docker build --build-arg VERSION=$(TAG) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
32+
if [ "$(TAG)" = "0.1.0" ] \
33+
|| [ "$(TAG)" = "0.1.1" ] \
34+
|| [ "$(TAG)" = "0.2.0" ] \
35+
|| [ "$(TAG)" = "0.3.0" ] \
36+
|| [ "$(TAG)" = "0.4.0" ] \
37+
|| [ "$(TAG)" = "0.4.5" ] \
38+
|| [ "$(TAG)" = "0.5.0" ] \
39+
|| [ "$(TAG)" = "0.6.0" ] \
40+
|| [ "$(TAG)" = "0.7.0" ]; then \
41+
docker build $(NO_CACHE) --build-arg VERSION=$(TAG) -t $(IMAGE) -f $(DIR)/$(FILE_011) $(DIR); \
42+
else \
43+
docker build $(NO_CACHE) --build-arg VERSION=$(TAG) -t $(IMAGE) -f $(DIR)/$(FILE_012) $(DIR); \
44+
fi
45+
46+
rebuild: NO_CACHE=--no-cache
47+
rebuild: build
1648

17-
rebuild: pull
18-
docker build --no-cache --build-arg VERSION=$(TAG) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
1949

50+
# --------------------------------------------------------------------------------------------------
51+
# LINT TARGETS
52+
# --------------------------------------------------------------------------------------------------
2053
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 .
54+
@docker run --rm -v $(PWD):/data cytopia/file-lint file-cr --text --ignore '.git/,.github/,tests/' --path .
55+
@docker run --rm -v $(PWD):/data cytopia/file-lint file-crlf --text --ignore '.git/,.github/,tests/' --path .
56+
@docker run --rm -v $(PWD):/data cytopia/file-lint file-trailing-single-newline --text --ignore '.git/,.github/,tests/' --path .
57+
@docker run --rm -v $(PWD):/data cytopia/file-lint file-trailing-space --text --ignore '.git/,.github/,tests/' --path .
58+
@docker run --rm -v $(PWD):/data cytopia/file-lint file-utf8 --text --ignore '.git/,.github/,tests/' --path .
59+
@docker run --rm -v $(PWD):/data cytopia/file-lint file-utf8-bom --text --ignore '.git/,.github/,tests/' --path .
2760

61+
62+
# --------------------------------------------------------------------------------------------------
63+
# TEST TARGETS
64+
# --------------------------------------------------------------------------------------------------
2865
test:
2966
@$(MAKE) --no-print-directory _test-version
3067
@$(MAKE) --no-print-directory _test-run-one
@@ -64,7 +101,7 @@ _test-run-one:
64101
@echo '<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' > tests/basic/TEST-$(TAG).md
65102
@echo >> tests/basic/TEST-$(TAG).md
66103
@echo '<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' >> tests/basic/TEST-$(TAG).md
67-
@if ! docker run --rm -v $(CURRENT_DIR)/tests/basic:/data $(IMAGE) terraform-docs-replace md TEST-$(TAG).md; then \
104+
@if ! docker run --rm -v $(PWD)/tests/basic:/data $(IMAGE) terraform-docs-replace md TEST-$(TAG).md; then \
68105
echo "Failed"; \
69106
exit 1; \
70107
fi; \
@@ -83,27 +120,31 @@ _test-run-two:
83120
@echo "- Testing terraform-docs (2/2)"
84121
@echo "------------------------------------------------------------"
85122
$(eval TFDOC_ARG_SORT = $(shell \
86-
if [ "$(TAG)" = "latest" ] || [ "$(TAG)" = "0.7.0" ] || [ "$(TAG)" = "0.6.0" ] || [ "$(TAG)" = "0.5.0" ]; then \
123+
if [ "$(TAG)" != "0.1.0" ] && [ "$(TAG)" != "0.1.1" ] && [ "$(TAG)" != "0.2.0" ] && [ "$(TAG)" != "0.3.0" ] && [ "$(TAG)" != "0.4.0" ] && [ "$(TAG)" != "0.4.5" ]; then \
87124
echo "--sort-inputs-by-required"; \
88125
fi; \
89126
))
90127
$(eval TFDOC_ARG_AGGREGATE = $(shell \
91-
if [ "$(TAG)" = "latest" ] || [ "$(TAG)" = "0.7.0" ] || [ "$(TAG)" = "0.6.0" ] || [ "$(TAG)" = "0.5.0" ] || [ "$(TAG)" = "0.4.5" ] || [ "$(TAG)" = "0.4.0" ]; then \
128+
if [ "$(TAG)" != "0.1.0" ] && [ "$(TAG)" != "0.1.1" ] && [ "$(TAG)" != "0.2.0" ] && [ "$(TAG)" != "0.3.0" ]; then \
92129
echo "--with-aggregate-type-defaults"; \
93130
fi; \
94131
))
95132
@# ---- Test Terraform < 0.12 ----
96-
@if ! docker run --rm -v $(CURRENT_DIR)/tests/default:/data $(IMAGE) terraform-docs-replace $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md TEST-$(TAG).md; then \
133+
@if ! docker run --rm -v $(PWD)/tests/default:/data $(IMAGE) terraform-docs-replace $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md TEST-$(TAG).md; then \
97134
echo "Failed"; \
98135
exit 1; \
99136
fi
100137
@# ---- Test Terraform >= 0.12 ----
101-
@if ! docker run --rm -v $(CURRENT_DIR)/tests/0.12:/data $(IMAGE) terraform-docs-replace-012 $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md TEST-$(TAG).md; then \
138+
@if ! docker run --rm -v $(PWD)/tests/0.12:/data $(IMAGE) terraform-docs-replace-012 $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md TEST-$(TAG).md; then \
102139
echo "Failed"; \
103140
exit 1; \
104141
fi; \
105142
echo "Success";
106143

144+
145+
# --------------------------------------------------------------------------------------------------
146+
# HELPER TARGETS
147+
# --------------------------------------------------------------------------------------------------
107148
tag:
108149
docker tag $(IMAGE) $(IMAGE):$(TAG)
109150

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ changes will be introduced).
6464
| Docker tag | Build from docker-terraform-docs | Build from terraform-docs |
6565
|------------|----------------------------------|---------------------------|
6666
| `latest` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Branch: master](https://github.com/segmentio/terraform-docs) |
67+
| `0.8.0-rc.2` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Tag: v0.8.0-rc.2](https://github.com/segmentio/terraform-docs/tree/v0.8.0-rc.2) |
68+
| `0.8.0-rc.1` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Tag: v0.8.0-rc.1](https://github.com/segmentio/terraform-docs/tree/v0.8.0-rc.1) |
6769
| `0.7.0` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Tag: v0.7.0](https://github.com/segmentio/terraform-docs/tree/v0.7.0) |
6870
| `0.6.0` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Tag: v0.6.0](https://github.com/segmentio/terraform-docs/tree/v0.6.0) |
6971
| `0.5.0` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Tag: v0.5.0](https://github.com/segmentio/terraform-docs/tree/v0.5.0) |
@@ -82,6 +84,8 @@ you will have to take care yourself and update your CI tools every time a new ta
8284
| Docker tag | Build from docker-terraform-docs | Build from terraform-docs |
8385
|----------------|----------------------------------|---------------------------|
8486
| `latest-<tag>` | Tag: `<tag>` | [Branch: master](https://github.com/segmentio/terraform-docs) |
87+
| `0.8.0-rc.2-<tag>` | Tag: `<tag>` | [Tag: v0.8.0-rc.2](https://github.com/segmentio/terraform-docs/tree/v0.8.0-rc.2) |
88+
| `0.8.0-rc.1-<tag>` | Tag: `<tag>` | [Tag: v0.8.0-rc.1](https://github.com/segmentio/terraform-docs/tree/v0.8.0-rc.1) |
8589
| `0.7.0-<tag>` | Tag: `<tag>` | [Tag: v0.7.0](https://github.com/segmentio/terraform-docs/tree/v0.7.0) |
8690
| `0.6.0-<tag>` | Tag: `<tag>` | [Tag: v0.6.0](https://github.com/segmentio/terraform-docs/tree/v0.6.0) |
8791
| `0.5.0-<tag>` | Tag: `<tag>` | [Tag: v0.5.0](https://github.com/segmentio/terraform-docs/tree/v0.5.0) |
@@ -140,13 +144,13 @@ Create markdown output and sent to stdout:
140144
docker run --rm \
141145
-v $(pwd):/data \
142146
cytopia/terraform-docs \
143-
terraform-docs --sort-inputs-by-required terraform-docs --with-aggregate-type-defaults md .
147+
terraform-docs --sort-inputs-by-required --with-aggregate-type-defaults md .
144148

145149
# [Terraform >= 0.12]
146150
docker run --rm \
147151
-v $(pwd):/data \
148152
cytopia/terraform-docs \
149-
terraform-docs-012 --sort-inputs-by-required terraform-docs --with-aggregate-type-defaults md .
153+
terraform-docs-012 --sort-inputs-by-required --with-aggregate-type-defaults md .
150154
```
151155
152156
### Store in file

data/docker-entrypoint.sh renamed to data/docker-entrypoint-0.11.sh

+24-22
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ if [ "${#}" -ge "1" ]; then
111111
# Remove first argument "replace"
112112
shift;
113113
mkdir -p /tmp-012
114-
awk -f /terraform-docs.awk *.tf > "/tmp-012/tmp.tf"
114+
awk -f /terraform-docs.awk -- *.tf > "/tmp-012/tmp.tf"
115115
# Get terraform-docs output
116116
>&2 echo "terraform-docs-012 ${*} ${WORKDIR}"
117117
if ! DOCS="$(terraform-docs "${@}" "/tmp-012")"; then
@@ -123,39 +123,41 @@ if [ "${#}" -ge "1" ]; then
123123
# Create temporary README.md
124124
mkdir -p /tmp
125125
grep -B 100000000 -F "${DELIM_START}" "${WORKDIR}/${MY_FILE}" > /tmp/README.md
126-
printf "%s\n\n" "${DOCS}" >> /tmp/README.md
126+
printf "%s\\n\\n" "${DOCS}" >> /tmp/README.md
127127
grep -A 100000000 -F "${DELIM_CLOSE}" "${WORKDIR}/${MY_FILE}" >> /tmp/README.md
128128

129129
# Adjust permissions of temporary file
130-
chown ${UID}:${GID} /tmp/README.md
131-
chmod ${PERM} /tmp/README.md
130+
chown "${UID}:${GID}" /tmp/README.md
131+
chmod "${PERM}" /tmp/README.md
132132

133133
# Overwrite existing file
134134
mv -f /tmp/README.md "${WORKDIR}/${MY_FILE}"
135135
exit 0
136136

137137
###
138-
### terraform-docs command (< 0.12)
138+
### terraform-docs command
139139
###
140-
elif [ "${1}" = "terraform-docs" ]; then
141-
exec "${@}"
140+
elif [ "${1}" = "terraform-docs" ] || [ "${1}" = "terraform-docs-012" ]; then
142141

143-
###
144-
### terraform-docs command (>= 0.12)
145-
###
146-
elif [ "${1}" = "terraform-docs-012" ]; then
147-
mkdir -p /tmp-012
148-
awk -f /terraform-docs.awk *.tf > "/tmp-012/tmp.tf"
142+
# Terraform < 0.12
143+
if [ "${1}" = "terraform-docs" ]; then
144+
exec "${@}"
149145

150-
# Remove last argument (path)
151-
args="$(trim_last_arg "${@}")" # get all the args except the last arg
152-
eval "set -- ${args}" # update the shell's arguments with the new value
153-
# Remove first argument (terraform-docs-012)
154-
shift
155-
# Execute
156-
if ! terraform-docs "${@}" "/tmp-012/"; then
157-
cat -n "/tmp-012/tmp.tf" >&2
158-
exit 1
146+
# Terraform >= 0.12
147+
else
148+
mkdir -p /tmp-012
149+
awk -f /terraform-docs.awk -- *.tf > "/tmp-012/tmp.tf"
150+
151+
# Remove last argument (path)
152+
args="$(trim_last_arg "${@}")" # get all the args except the last arg
153+
eval "set -- ${args}" # update the shell's arguments with the new value
154+
# Remove first argument (terraform-docs-012)
155+
shift
156+
# Execute
157+
if ! terraform-docs "${@}" "/tmp-012/"; then
158+
cat -n "/tmp-012/tmp.tf" >&2
159+
exit 1
160+
fi
159161
fi
160162

161163
###

0 commit comments

Comments
 (0)