Skip to content

Commit

Permalink
Merge pull request #33 from cytopia/release-0.18
Browse files Browse the repository at this point in the history
Release 0.18
  • Loading branch information
cytopia authored Feb 3, 2020
2 parents 89c0c46 + 40d6e0f commit 1bcddf6
Show file tree
Hide file tree
Showing 106 changed files with 3,917 additions and 49 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ env:
- VERSION=0.8.0-rc.2
- VERSION=0.8.0-rc.3
- VERSION=0.8.0
- VERSION=0.8.1
- VERSION=latest


Expand Down
1 change: 0 additions & 1 deletion Dockerfile-0.11
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ COPY --from=builder /usr/local/bin/terraform-docs /usr/local/bin/terraform-docs
COPY ./data/docker-entrypoint-0.11.sh /docker-entrypoint.sh
COPY ./data/terraform-docs.awk /terraform-docs.awk

ENV WORKDIR /data
WORKDIR /data

CMD ["terraform-docs", "--version"]
Expand Down
3 changes: 0 additions & 3 deletions Dockerfile-0.12
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ RUN set -x \
# Build terraform-docs latest
&& if [ "${VERSION}" = "latest" ]; then \
go get github.com/mitchellh/gox \
&& make test \
&& make build-all GOOS=linux GOARCH=amd64 \
&& mv bin/terraform-docs-${VERSION}-linux-amd64 /usr/local/bin/terraform-docs; \
# Build terraform-docs 0.8.0-rc.1 and above
else \
go get github.com/mitchellh/gox \
&& make test \
&& make build-all GOOS=linux GOARCH=amd64 \
&& mv bin/terraform-docs-${VERSION}-linux-amd64 /usr/local/bin/terraform-docs; \
fi \
Expand All @@ -53,7 +51,6 @@ LABEL \
COPY --from=builder /usr/local/bin/terraform-docs /usr/local/bin/terraform-docs
COPY ./data/docker-entrypoint-0.12.sh /docker-entrypoint.sh

ENV WORKDIR /data
WORKDIR /data

CMD ["terraform-docs", "--version"]
Expand Down
92 changes: 79 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ifneq (,)
.error This Makefile requires GNU Make.
endif

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

# --------------------------------------------------------------------------------------------------
# VARIABLES
Expand Down Expand Up @@ -64,8 +64,10 @@ lint:
# --------------------------------------------------------------------------------------------------
test:
@$(MAKE) --no-print-directory _test-version
@$(MAKE) --no-print-directory _test-run-one
@$(MAKE) --no-print-directory _test-run-two
@$(MAKE) --no-print-directory _test-run-generate-one
@$(MAKE) --no-print-directory _test-run-generate-two
@$(MAKE) --no-print-directory _test-run-replace-one
@$(MAKE) --no-print-directory _test-run-replace-two

_test-version:
@echo "------------------------------------------------------------"
Expand Down Expand Up @@ -94,28 +96,25 @@ _test-version:
fi; \
echo "Success"; \

_test-run-one:
_test-run-generate-one:
@echo "------------------------------------------------------------"
@echo "- Testing terraform-docs (1/2)"
@echo "------------------------------------------------------------"
@echo '<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' > tests/basic/TEST-$(TAG).md
@echo >> tests/basic/TEST-$(TAG).md
@echo '<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' >> tests/basic/TEST-$(TAG).md
@if ! docker run --rm -v $(PWD)/tests/basic:/data $(IMAGE) terraform-docs-replace md TEST-$(TAG).md; then \
@if ! docker run --rm -v $(PWD)/tests:/data $(IMAGE) terraform-docs md /data/output/generate/basic/ > tests/output/generate/basic/TEST-$(TAG).md; then \
echo "Failed"; \
exit 1; \
fi; \
if ! grep '## Inputs' tests/basic/TEST-$(TAG).md; then \
if ! grep '## Inputs' tests/output/generate/basic/TEST-$(TAG).md; then \
echo "Failed"; \
exit 1; \
fi; \
if ! grep 'test description' tests/basic/TEST-$(TAG).md; then \
if ! grep -E '^variable.*$$' tests/output/generate/basic/main.tf | awk -F'"' '{print $$2}' | xargs -n1 sh -c 'if ! cat tests/output/generate/basic/TEST-$(TAG).md | sed "s/\\\//g" | grep -E "[[:space:]]$$1[[:space:]]" >/dev/null; then echo "[ERROR] $$1"; false; else echo "[SUCC] $$1"; true; fi' -- ; then \
echo "Failed"; \
exit 1; \
fi; \
echo "Success";

_test-run-two:
_test-run-generate-two:
@echo "------------------------------------------------------------"
@echo "- Testing terraform-docs (2/2)"
@echo "------------------------------------------------------------"
Expand All @@ -130,12 +129,79 @@ _test-run-two:
fi; \
))
@# ---- Test Terraform < 0.12 ----
@if ! docker run --rm -v $(PWD)/tests/default:/data $(IMAGE) terraform-docs-replace $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md TEST-$(TAG).md; then \
@if ! docker run --rm -v $(PWD)/tests:/data $(IMAGE) terraform-docs $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md /data/output/generate/default/ > tests/output/generate/default/TEST-$(TAG).md; then \
echo "Failed"; \
exit 1; \
fi; \
if ! grep -E '^variable.*$$' tests/output/generate/default/main.tf | awk -F'"' '{print $$2}' | xargs -n1 sh -c 'if ! cat tests/output/generate/default/TEST-$(TAG).md | sed "s/\\\//g" | grep -E "[[:space:]]$$1[[:space:]]" >/dev/null; then echo "[ERROR] $$1"; false; else echo "[SUCC] $$1"; true; fi' -- ; then \
echo "Failed"; \
exit 1; \
fi
@# ---- Test Terraform >= 0.12 ----
@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 \
@if ! docker run --rm -v $(PWD)/tests:/data $(IMAGE) terraform-docs-012 $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md /data/output/generate/0.12/ > tests/output/generate/0.12/TEST-$(TAG).md; then \
echo "Failed"; \
exit 1; \
fi; \
if ! grep -E '^variable.*$$' tests/output/generate/0.12/main.tf | awk -F'"' '{print $$2}' | xargs -n1 sh -c 'if ! cat tests/output/generate/0.12/TEST-$(TAG).md | sed "s/\\\//g" | grep -E "[[:space:]]$$1[[:space:]]" >/dev/null; then echo "[ERROR] $$1"; false; else echo "[SUCC] $$1"; true; fi' -- ; then \
echo "Failed"; \
exit 1; \
fi
@echo "Success";

_test-run-replace-one:
@echo "------------------------------------------------------------"
@echo "- Testing terraform-docs-replace (1/2)"
@echo "------------------------------------------------------------"
@echo '<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' > tests/output/replace/basic/TEST-$(TAG).md
@echo >> tests/output/replace/basic/TEST-$(TAG).md
@echo '<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' >> tests/output/replace/basic/TEST-$(TAG).md
@if ! docker run --rm -v $(PWD)/tests:/data $(IMAGE) terraform-docs-replace md /data/output/replace/basic/TEST-$(TAG).md; then \
echo "Failed"; \
exit 1; \
fi; \
if ! grep '## Inputs' tests/output/replace/basic/TEST-$(TAG).md; then \
echo "Failed"; \
exit 1; \
fi; \
if ! grep 'test description' tests/output/replace/basic/TEST-$(TAG).md; then \
echo "Failed"; \
exit 1; \
fi; \
if ! grep -E '^variable.*$$' tests/output/replace/basic/main.tf | awk -F'"' '{print $$2}' | xargs -n1 sh -c 'if ! cat tests/output/replace/basic/TEST-$(TAG).md | sed "s/\\\//g" | grep -E "[[:space:]]$$1[[:space:]]" >/dev/null; then echo "[ERROR] $$1"; false; else echo "[SUCC] $$1"; true; fi' -- ; then \
echo "Failed"; \
exit 1; \
fi; \
echo "Success";

_test-run-replace-two:
@echo "------------------------------------------------------------"
@echo "- Testing terraform-docs-replace (2/2)"
@echo "------------------------------------------------------------"
$(eval TFDOC_ARG_SORT = $(shell \
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 \
echo "--sort-inputs-by-required"; \
fi; \
))
$(eval TFDOC_ARG_AGGREGATE = $(shell \
if [ "$(TAG)" != "0.1.0" ] && [ "$(TAG)" != "0.1.1" ] && [ "$(TAG)" != "0.2.0" ] && [ "$(TAG)" != "0.3.0" ]; then \
echo "--with-aggregate-type-defaults"; \
fi; \
))
@# ---- Test Terraform < 0.12 ----
@if ! docker run --rm -v $(PWD)/tests:/data $(IMAGE) terraform-docs-replace $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md /data/output/replace/default/TEST-$(TAG).md; then \
echo "Failed"; \
exit 1; \
fi; \
if ! grep -E '^variable.*$$' tests/output/replace/default/main.tf | awk -F'"' '{print $$2}' | xargs -n1 sh -c 'if ! cat tests/output/replace/default/TEST-$(TAG).md | sed "s/\\\//g" | grep -E "[[:space:]]$$1[[:space:]]" >/dev/null; then echo "[ERROR] $$1"; false; else echo "[SUCC] $$1"; true; fi' -- ; then \
echo "Failed"; \
exit 1; \
fi
@# ---- Test Terraform >= 0.12 ----
@if ! docker run --rm -v $(PWD)/tests:/data $(IMAGE) terraform-docs-replace-012 $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md /data/output/replace/0.12/TEST-$(TAG).md; then \
echo "Failed"; \
exit 1; \
fi; \
if ! grep -E '^variable.*$$' tests/output/replace/0.12/main.tf | awk -F'"' '{print $$2}' | xargs -n1 sh -c 'if ! cat tests/output/replace/0.12/TEST-$(TAG).md | sed "s/\\\//g" | grep -E "[[:space:]]$$1[[:space:]]" >/dev/null; then echo "[ERROR] $$1"; false; else echo "[SUCC] $$1"; true; fi' -- ; then \
echo "Failed"; \
exit 1; \
fi; \
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ changes will be introduced).
| Docker tag | Build from docker-terraform-docs | Build from terraform-docs |
|------------|----------------------------------|---------------------------|
| `latest` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Branch: master](https://github.com/segmentio/terraform-docs) |
| `0.8.1` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Tag: v0.8.1](https://github.com/segmentio/terraform-docs/tree/v0.8.1) |
| `0.8.0` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Tag: v0.8.0](https://github.com/segmentio/terraform-docs/tree/v0.8.0) |
| `0.8.0-rc.3` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Tag: v0.8.0-rc.3](https://github.com/segmentio/terraform-docs/tree/v0.8.0-rc.3) |
| `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) |
Expand All @@ -86,6 +87,7 @@ you will have to take care yourself and update your CI tools every time a new ta
| Docker tag | Build from docker-terraform-docs | Build from terraform-docs |
|----------------|----------------------------------|---------------------------|
| `latest-<tag>` | Tag: `<tag>` | [Branch: master](https://github.com/segmentio/terraform-docs) |
| `0.8.1-<tag>` | Tag: `<tag>` | [Tag: v0.8.1](https://github.com/segmentio/terraform-docs/tree/v0.8.1) |
| `0.8.0-<tag>` | Tag: `<tag>` | [Tag: v0.8.0](https://github.com/segmentio/terraform-docs/tree/v0.8.0) |
| `0.8.0-rc.3-<tag>` | Tag: `<tag>` | [Tag: v0.8.0-rc.3](https://github.com/segmentio/terraform-docs/tree/v0.8.0-rc.3) |
| `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) |
Expand Down
42 changes: 24 additions & 18 deletions data/docker-entrypoint-0.11.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,41 +79,41 @@ if [ "${#}" -ge "1" ]; then


# Check if file exists
if [ ! -f "${WORKDIR}/${MY_FILE}" ]; then
>&2 echo "Error, ${MY_FILE} not found in: ${WORKDIR}/${MY_FILE}"
if [ ! -f "${MY_FILE}" ]; then
>&2 echo "Error, File not found in: ${MY_FILE}"
exit 1
fi
# Check if starting delimiter exists in file
if ! grep -Fq "${DELIM_START}" "${WORKDIR}/${MY_FILE}"; then
if ! grep -Fq "${DELIM_START}" "${MY_FILE}"; then
>&2 echo "Error, Starting delimiter not found ${MY_FILE}: '${DELIM_START}'"
exit 1
fi
# Check if closint delimiter exists in file
if ! grep -Fq "${DELIM_CLOSE}" "${WORKDIR}/${MY_FILE}"; then
if ! grep -Fq "${DELIM_CLOSE}" "${MY_FILE}"; then
>&2 echo "Error, Closing delimiter not found ${MY_FILE}: '${DELIM_CLOSE}'"
exit 1
fi

# Get owner and permissions of current file
UID="$(stat -c %u "${WORKDIR}/${MY_FILE}")"
GID="$(stat -c %g "${WORKDIR}/${MY_FILE}")"
PERM="$(stat -c %a "${WORKDIR}/${MY_FILE}")"
UID="$(stat -c %u "${MY_FILE}")"
GID="$(stat -c %g "${MY_FILE}")"
PERM="$(stat -c %a "${MY_FILE}")"

# Terraform < 0.12
if [ "${1}" = "terraform-docs-replace" ]; then
# Remove first argument "replace"
shift;
# Get terraform-docs output
>&2 echo "terraform-docs ${*} ${WORKDIR}"
DOCS="$(terraform-docs "${@}" "${WORKDIR}")"
>&2 echo "terraform-docs ${*} $(dirname "${MY_FILE}")"
DOCS="$(terraform-docs "${@}" "$(dirname "${MY_FILE}")")"
# Terraform >= 0.12
else
# Remove first argument "replace"
shift;
mkdir -p /tmp-012
awk -f /terraform-docs.awk -- *.tf > "/tmp-012/tmp.tf"
awk -f /terraform-docs.awk -- "$(dirname "${MY_FILE}")/"*.tf > "/tmp-012/tmp.tf"
# Get terraform-docs output
>&2 echo "terraform-docs-012 ${*} ${WORKDIR}"
>&2 echo "terraform-docs-012 ${*} $(dirname "${MY_FILE}")"
if ! DOCS="$(terraform-docs "${@}" "/tmp-012")"; then
cat -n "/tmp-012/tmp.tf" >&2
exit 1
Expand All @@ -122,16 +122,16 @@ if [ "${#}" -ge "1" ]; then

# Create temporary README.md
mkdir -p /tmp
grep -B 100000000 -F "${DELIM_START}" "${WORKDIR}/${MY_FILE}" > /tmp/README.md
grep -B 100000000 -F "${DELIM_START}" "${MY_FILE}" > /tmp/README.md
printf "%s\\n\\n" "${DOCS}" >> /tmp/README.md
grep -A 100000000 -F "${DELIM_CLOSE}" "${WORKDIR}/${MY_FILE}" >> /tmp/README.md
grep -A 100000000 -F "${DELIM_CLOSE}" "${MY_FILE}" >> /tmp/README.md

# Adjust permissions of temporary file
chown "${UID}:${GID}" /tmp/README.md
chmod "${PERM}" /tmp/README.md

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

###
Expand All @@ -141,19 +141,25 @@ if [ "${#}" -ge "1" ]; then

# Terraform < 0.12
if [ "${1}" = "terraform-docs" ]; then
>&2 echo "${*}"
exec "${@}"

# Terraform >= 0.12
else
mkdir -p /tmp-012
awk -f /terraform-docs.awk -- *.tf > "/tmp-012/tmp.tf"

# Remove last argument (path)
# Store and Remove last argument (filename)
eval MY_DIR="\${$#}" # store last argument
args="$(trim_last_arg "${@}")" # get all the args except the last arg
eval "set -- ${args}" # update the shell's arguments with the new value
# Remove first argument (terraform-docs-012)

mkdir -p /tmp-012
awk -f /terraform-docs.awk -- "${MY_DIR}/"*.tf > "/tmp-012/tmp.tf"

# Remove first argument
shift

# Execute
>&2 echo "terraform-docs ${*} ${MY_DIR}"
if ! terraform-docs "${@}" "/tmp-012/"; then
cat -n "/tmp-012/tmp.tf" >&2
exit 1
Expand Down
30 changes: 17 additions & 13 deletions data/docker-entrypoint-0.12.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,51 +81,55 @@ if [ "${#}" -ge "1" ]; then


# Check if file exists
if [ ! -f "${WORKDIR}/${MY_FILE}" ]; then
>&2 echo "Error, ${MY_FILE} not found in: ${WORKDIR}/${MY_FILE}"
if [ ! -f "${MY_FILE}" ]; then
>&2 echo "Error, File not found in: ${MY_FILE}"
exit 1
fi
# Check if starting delimiter exists in file
if ! grep -Fq "${DELIM_START}" "${WORKDIR}/${MY_FILE}"; then
if ! grep -Fq "${DELIM_START}" "${MY_FILE}"; then
>&2 echo "Error, Starting delimiter not found ${MY_FILE}: '${DELIM_START}'"
exit 1
fi
# Check if closint delimiter exists in file
if ! grep -Fq "${DELIM_CLOSE}" "${WORKDIR}/${MY_FILE}"; then
if ! grep -Fq "${DELIM_CLOSE}" "${MY_FILE}"; then
>&2 echo "Error, Closing delimiter not found ${MY_FILE}: '${DELIM_CLOSE}'"
exit 1
fi

# Get owner and permissions of current file
UID="$(stat -c %u "${WORKDIR}/${MY_FILE}")"
GID="$(stat -c %g "${WORKDIR}/${MY_FILE}")"
PERM="$(stat -c %a "${WORKDIR}/${MY_FILE}")"
UID="$(stat -c %u "${MY_FILE}")"
GID="$(stat -c %g "${MY_FILE}")"
PERM="$(stat -c %a "${MY_FILE}")"

# Remove first argument "replace"
shift;
# Get terraform-docs output
>&2 echo "terraform-docs ${*} ${WORKDIR}"
DOCS="$(terraform-docs "${@}" "${WORKDIR}")"
>&2 echo "terraform-docs ${*} $(dirname "${MY_FILE}")"
DOCS="$(terraform-docs "${@}" "$(dirname "${MY_FILE}")")"

# Create temporary README.md
mkdir -p /tmp
grep -B 100000000 -F "${DELIM_START}" "${WORKDIR}/${MY_FILE}" > /tmp/README.md
grep -B 100000000 -F "${DELIM_START}" "${MY_FILE}" > /tmp/README.md
printf "%s\\n\\n" "${DOCS}" >> /tmp/README.md
grep -A 100000000 -F "${DELIM_CLOSE}" "${WORKDIR}/${MY_FILE}" >> /tmp/README.md
grep -A 100000000 -F "${DELIM_CLOSE}" "${MY_FILE}" >> /tmp/README.md

# Adjust permissions of temporary file
chown "${UID}:${GID}" /tmp/README.md
chmod "${PERM}" /tmp/README.md

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

###
### terraform-docs command
###
elif [ "${1}" = "terraform-docs" ] || [ "${1}" = "terraform-docs-012" ]; then
exec "${@}"

# Remove first argument "replace"
shift
>&2 echo "terraform-docs ${*}"
terraform-docs "${@}"

###
### Unsupported command
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1bcddf6

Please sign in to comment.