Skip to content

Commit 6ccc51f

Browse files
authored
Merge pull request #1 from cytopia/release-0.1
Initial release
2 parents 18ad33d + fef7732 commit 6ccc51f

File tree

5 files changed

+266
-2
lines changed

5 files changed

+266
-2
lines changed

.travis.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
3+
###
4+
### Enable sudo (required for docker service)
5+
###
6+
sudo: required
7+
8+
9+
###
10+
### Language
11+
###
12+
language: python
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.1.0
28+
- VERSION=0.1.1
29+
- VERSION=0.2.0
30+
- VERSION=0.3.0
31+
- VERSION=0.4.0
32+
- VERSION=0.4.5
33+
- VERSION=0.5.0
34+
- VERSION=0.6.0
35+
- VERSION=latest
36+
37+
38+
###
39+
### Install requirements
40+
###
41+
install:
42+
# Get newer docker version
43+
- while ! sudo apt-get update; do sleep 1; done
44+
- while ! sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce; do sleep 1; done
45+
- docker version
46+
47+
48+
###
49+
### Check generation changes, build and test
50+
###
51+
before_script:
52+
- while ! make build TAG=${VERSION}; do sleep 1; done
53+
- while ! make test TAG=${VERSION}; do sleep 1; done
54+
55+
56+
###
57+
### Push to Dockerhub
58+
###
59+
script:
60+
# Push to docker hub on success
61+
- if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
62+
make login USER="${DOCKER_USERNAME}" PASS="${DOCKER_PASSWORD}";
63+
if [ -n "${TRAVIS_TAG}" ]; then
64+
make push TAG="${VERSION}-${TRAVIS_TAG}";
65+
elif [ "${TRAVIS_BRANCH}" == "master" ]; then
66+
make push TAG=${VERSION};
67+
elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then
68+
make push TAG="${VERSION}-${TRAVIS_BRANCH}";
69+
else
70+
echo "Skipping branch ${TRAVIS_BRANCH}";
71+
fi
72+
else
73+
echo "Skipping push on PR";
74+
fi

Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM golang:latest as builder
2+
3+
# Install dependencies
4+
RUN set -x \
5+
&& DEBIAN_FRONTEND=noninteractive apt-get update -qq \
6+
&& DEBIAN_FRONTEND=noninteractive apt-get install -qq -y --no-install-recommends --no-install-suggests \
7+
git \
8+
gox \
9+
&& curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
10+
11+
# Get and build terraform-docs
12+
ARG VERSION
13+
RUN set -x \
14+
&& export GOPATH=/go \
15+
&& mkdir -p /go/src/github.com/segmentio \
16+
&& git clone https://github.com/segmentio/terraform-docs /go/src/github.com/segmentio/terraform-docs \
17+
&& cd /go/src/github.com/segmentio/terraform-docs \
18+
&& if [ ${VERSION} != "latest" ]; then \
19+
git checkout v${VERSION}; \
20+
fi \
21+
# Build terraform-docs <= 0.3.0
22+
&& if [ "${VERSION}" = "0.3.0" ] || [ "${VERSION}" = "0.2.0" ] || [ "${VERSION}" = "0.1.1" ] || [ "${VERSION}" = "0.1.0" ]; then \
23+
go get github.com/hashicorp/hcl \
24+
&& go get github.com/tj/docopt \
25+
&& make \
26+
&& mkdir -p bin/linux-amd64 \
27+
&& mv dist/terraform-docs_linux_amd64 bin/linux-amd64/terraform-docs; \
28+
# Build terraform-docs > 0.3.0
29+
else \
30+
make deps \
31+
&& make test \
32+
&& make build-linux-amd64 \
33+
&& if [ ${VERSION} = "0.4.0" ]; then \
34+
mkdir -p bin/linux-amd64 \
35+
&& mv bin/terraform-docs-v${VERSION}-linux-amd64 bin/linux-amd64/terraform-docs; \
36+
fi \
37+
fi \
38+
&& chmod +x bin/linux-amd64/terraform-docs
39+
40+
# Use a clean tiny image to store artifacts in
41+
FROM alpine:latest
42+
COPY --from=builder /go/src/github.com/segmentio/terraform-docs/bin/linux-amd64/terraform-docs /usr/local/bin/terraform-docs
43+
WORKDIR /docs
44+
ENTRYPOINT ["/usr/local/bin/terraform-docs"]
45+
CMD ["--version"]

LICENSE

Lines changed: 21 additions & 0 deletions
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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
DIR = .
2+
FILE = Dockerfile
3+
IMAGE = cytopia/terraform-docs
4+
TAG = latest
5+
6+
.PHONY: build rebuild test tag pull login push enter
7+
8+
build:
9+
docker build --build-arg VERSION=$(TAG) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
10+
11+
rebuild: pull
12+
docker build --no-cache --build-arg VERSION=$(TAG) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
13+
14+
test:
15+
@if [ "$(TAG)" = "latest" ]; then \
16+
echo "Fetching latest version from GitHub"; \
17+
LATEST="$$( \
18+
curl -L -sS https://github.com/segmentio/terraform-docs/releases/latest/ \
19+
| tac | tac \
20+
| grep -Eo "segmentio/terraform-docs/releases/tag/v[.0-9]+" \
21+
| head -1 \
22+
| sed 's/.*v//g' \
23+
)"; \
24+
echo "Testing for latest: $${LATEST}"; \
25+
docker run --rm cytopia/terraform-docs | grep -E "^v?$${LATEST}$$"; \
26+
else \
27+
echo "Testing for tag: $(TAG)"; \
28+
docker run --rm cytopia/terraform-docs | grep -E "^v?$(TAG)$$"; \
29+
fi
30+
31+
tag:
32+
docker tag $(IMAGE) $(IMAGE):$(TAG)
33+
34+
pull:
35+
@grep -E '^\s*FROM' Dockerfile \
36+
| sed -e 's/^FROM//g' -e 's/[[:space:]]*as[[:space:]]*.*$$//g' \
37+
| xargs -n1 docker pull;
38+
39+
login:
40+
yes | docker login --username $(USER) --password $(PASS)
41+
42+
push:
43+
@$(MAKE) tag TAG=$(TAG)
44+
docker push $(IMAGE):$(TAG)
45+
46+
enter:
47+
docker run --rm --name $(subst /,-,$(IMAGE)) -it --entrypoint=/bin/sh $(ARG) $(IMAGE):$(TAG)

README.md

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,95 @@
22

33
[![Build Status](https://travis-ci.com/cytopia/docker-terraform-docs.svg?branch=master)](https://travis-ci.com/cytopia/docker-terraform-docs)
44
[![Tag](https://img.shields.io/github/tag/cytopia/docker-terraform-docs.svg)](https://github.com/cytopia/docker-terraform-docs/releases)
5-
[![](https://images.microbadger.com/badges/version/cytopia/terraform-docs.svg)](https://microbadger.com/images/cytopia/terraform-docs "terraform-docs")
6-
[![](https://images.microbadger.com/badges/image/cytopia/terraform-docs.svg)](https://microbadger.com/images/cytopia/terraform-docs "terraform-docs")
5+
[![](https://images.microbadger.com/badges/version/cytopia/terraform-docs:latest.svg)](https://microbadger.com/images/cytopia/terraform-docs:latest "terraform-docs")
6+
[![](https://images.microbadger.com/badges/image/cytopia/terraform-docs:latest.svg)](https://microbadger.com/images/cytopia/terraform-docs:latest "terraform-docs")
77
[![License](https://img.shields.io/badge/license-MIT-%233DA639.svg)](https://opensource.org/licenses/MIT)
88

99

1010
[![Docker hub](http://dockeri.co/image/cytopia/terraform-docs)](https://hub.docker.com/r/cytopia/terraform-docs)
1111

12+
1213
## Official project
1314

1415
https://github.com/segmentio/terraform-docs
1516

1617

18+
## Available Docker image versions
19+
20+
| Docker tag | Build from |
21+
|------------|------------|
22+
| `latest` | [Branch: master](https://github.com/segmentio/terraform-docs) |
23+
| `0.6.0` | [Tag: v0.6.0](https://github.com/segmentio/terraform-docs/tree/v0.6.0) |
24+
| `0.5.0` | [Tag: v0.5.0](https://github.com/segmentio/terraform-docs/tree/v0.5.0) |
25+
| `0.4.5` | [Tag: v0.4.5](https://github.com/segmentio/terraform-docs/tree/v0.4.5) |
26+
| `0.4.0` | [Tag: v0.4.0](https://github.com/segmentio/terraform-docs/tree/v0.4.0) |
27+
| `0.3.0` | [Tag: v0.3.0](https://github.com/segmentio/terraform-docs/tree/v0.3.0) |
28+
| `0.2.0` | [Tag: v0.2.0](https://github.com/segmentio/terraform-docs/tree/v0.2.0) |
29+
| `0.1.1` | [Tag: v0.1.1](https://github.com/segmentio/terraform-docs/tree/v0.1.1) |
30+
| `0.1.0` | [Tag: v0.1.0](https://github.com/segmentio/terraform-docs/tree/v0.1.0) |
31+
32+
33+
## Docker mounts
34+
35+
The working directory inside the Docker container is `/docs/` and should be mounted locally to
36+
where your Terraform module is located.
37+
38+
39+
## Usage
40+
41+
#### Output to stdout
42+
Create markdown output and sent to stdout:
43+
```bash
44+
docker run --rm \
45+
-v $(pwd):/docs \
46+
--sort-inputs-by-required --with-aggregate-type-defaults md .
47+
```
48+
49+
#### Store in file
50+
Create README.md with `terraform-docs` output:
51+
```bash
52+
docker run --rm \
53+
-v $(pwd):/docs \
54+
--sort-inputs-by-required --with-aggregate-type-defaults md . > README.md
55+
```
56+
57+
#### Replace in README.md
58+
Replace current `terraform-docs` blocks in README.md with current one in order to automatically
59+
keep it up to date. For this to work, the `terraform-docs` information must be wrapped with the
60+
following delimiter:
61+
```markdown
62+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
63+
## Inputs
64+
...
65+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
66+
```
67+
68+
```bash
69+
# Save output in variable
70+
DOCS="$(
71+
docker run --rm \
72+
-v $(pwd):/docs \
73+
--sort-inputs-by-required --with-aggregate-type-defaults md .
74+
)"
75+
76+
# Create new README
77+
grep -B 100000000 -F '<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' README.md > README.md.tmp
78+
printf "${DOCS}\n\n" >> README.md.tmp
79+
grep -A 100000000 -F '<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' README.md >> README.md.tmp
80+
81+
# Overwrite old README
82+
mv -f README.md.tmp README.md
83+
```
84+
85+
86+
## Example projects
87+
88+
Find below some example projects how this Docker image is used in CI to verify if the README.md has
89+
been updated with the latest changes generated from `terraform-docs`:
90+
91+
* https://github.com/cytopia/terraform-aws-rds/blob/master/Makefile
92+
93+
1794
## License
1895

1996
**[MIT License](LICENSE)**

0 commit comments

Comments
 (0)