diff --git a/.README.md b/.README.md new file mode 100644 index 00000000..7261e465 --- /dev/null +++ b/.README.md @@ -0,0 +1,54 @@ +# Cloud Posse Build Harness [![Build Status](https://travis-ci.org/cloudposse/build-harness.svg)](https://travis-ci.org/cloudposse/build-harness) +{{ (datasource "section").warning }} + +This `build-harness` is a collection of Makefiles to facilitate building Golang projects, Dockerfiles, Helm charts, and more. + +It's designed to work with CI/CD systems such as Travis CI, CircleCI and Jenkins. + +It's 100% Open Source and licensed under [APACHE2](LICENSE). + + +## Usage + +At the top of your `Makefile` add, the following... + +```make +-include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness) +``` + +This will download a `Makefile` called `.build-harness` and include it at run-time. We recommend adding the `.build-harness` file to your `.gitignore`. + +This automatically exposes many new targets that you can leverage throughout your build & CI/CD process. + +Run `make help` for a list of available targets. + +{{ (datasource "make").help }} + +## Real World Examples + +- [`github-authorized-keys`](https://github.com/cloudposse/github-authorized-keys/) - A Golang project that leverages `docker:%`, `go:%`, `travis:%` targets +- [`charts`](https://github.com/cloudposse/charts/) - A collection of Helm Charts that leverages `docker:%` and `helm:%` targets +- [`bastion`](https://github.com/cloudposse/bastion/) - A docker image that leverages `docker:%` and `bash:lint` targets +- [`terraform-null-label`](https://github.com/cloudposse/terraform-null-label/) - A terraform module that leverages `terraform:%` targets + +{{ (datasource "section").help }} +{{ (datasource "section").contributing }} + +Here's how to get started... + +1. `git clone https://github.com/cloudposse/{{ (datasource "git").name }}.git` to pull down the repository +2. `make init` to initialize the [`{{ (datasource "git").name }}`](https://github.com/cloudposse/{{ (datasource "git").name }}/) +3. Review the [documentation](docs/) on compiling + + +{{ (datasource "license").apache2 }} +{{ (datasource "section").about }} + +### Contributors + +| +{{- (datasource "contributor").erik }} | +{{- (datasource "contributor").igor }} | +|---|---| + +{{ (datasource "contributor")._links }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e53e698e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +./terraform \ No newline at end of file diff --git a/Makefile b/Makefile index afab9f67..3c1ee015 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -BUILD_HARNESS_PATH ?= . -OS ?= $(shell uname -s | tr '[:upper:]' '[:lower:]') -SELF ?= make +export BUILD_HARNESS_PATH ?= $(shell 'pwd') +export OS ?= $(shell uname -s | tr '[:upper:]' '[:lower:]') +export SELF ?= make include $(BUILD_HARNESS_PATH)/Makefile.* -include $(BUILD_HARNESS_PATH)/modules/*/* +include $(BUILD_HARNESS_PATH)/modules/*/Makefile* diff --git a/README.md b/README.md index f7332f1d..1029be84 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # Cloud Posse Build Harness [![Build Status](https://travis-ci.org/cloudposse/build-harness.svg)](https://travis-ci.org/cloudposse/build-harness) + -This `build-harness` is a collection of Makefiles to facilitate building Golang projects, Dockerfiles, Helm charts, and more. +This `build-harness` is a collection of Makefiles to facilitate building Golang projects, Dockerfiles, Helm charts, and more. It's designed to work with CI/CD systems such as Travis CI, CircleCI and Jenkins. @@ -21,57 +25,60 @@ This automatically exposes many new targets that you can leverage throughout you Run `make help` for a list of available targets. - ## Makefile Targets ```bash $ make help -Available targets: - - bash:lint Lint all bash scripts - docker:build Build docker image - docker:login Login into docker hub - docs:copyright-add Add copyright headers to source code - docs:toc-update Update table of contents in README.md - geodesic:deploy Run a Jenkins Job to Deploy $(APP) with $(CANONICAL_TAG) - git:aliases-update Update git aliases - git:submodules-update Update submodules - github:download-private-release Download release from github - github:download-public-release Download release from github - go:build Build binary - go:build-all Build binary for all platforms - go:clean Clean compiled binary - go:clean-all Clean compiled binary and dependency - go:deps Install dependencies - go:deps-build Install dependencies for build - go:deps-dev Install development dependencies - go:fmt Format code according to Golang convention - go:install Install cli - go:lint Lint code - go:test Run tests - go:vet Vet code - helm:install Install helm - helm:repo:add-current Add helm remote dev repos - helm:repo:add-remote Add helm remote repos - helm:repo:build Build repo - helm:repo:clean Clean helm repo - helm:repo:fix-perms Fix repo filesystem permissions - helm:repo:info Show repo info - helm:repo:lint Lint charts - helm:serve:index Build index for serve helm charts - help This help screen - jenkins:run-job-with-tag Run a Jenkins Job with $(TAG) - make:lint Lint all makefiles - terraform:get-modules Ensure all modules can be fetched - terraform:get-plugins Ensure all plugins can be fetched - terraform:lint Lint check Terraform - terraform:validate Basic terraform sanity check - travis:docker-login Login into docker hub - travis:docker-tag-and-push Tag & Push according Travis environment variables + Available targets: + +bash:lint Lint all bash scripts +docker:build Build docker image +docker:login Login into docker hub +docs:build Create $OUT file by building it from $IN template file +docs:copyright-add Add copyright headers to source code +docs:deps Install dependencies +geodesic:deploy Run a Jenkins Job to Deploy $(APP) with $(CANONICAL_TAG) +git:aliases-update Update git aliases +github:download-private-release Download release from github +github:download-public-release Download release from github +git:submodules-update Update submodules +go:build Build binary +go:build-all Build binary for all platforms +go:clean Clean compiled binary +go:clean-all Clean compiled binary and dependency +go:deps Install dependencies +go:deps-build Install dependencies for build +go:deps-dev Install development dependencies +go:fmt Format code according to Golang convention +go:install Install cli +go:lint Lint code +go:test Run tests +go:vet Vet code +helm:install Install helm +helm:repo:add-current Add helm remote dev repos +helm:repo:add-remote Add helm remote repos +helm:repo:build Build repo +helm:repo:clean Clean helm repo +helm:repo:fix-perms Fix repo filesystem permissions +helm:repo:info Show repo info +helm:repo:lint Lint charts +helm:serve:index Build index for serve helm charts +help This help screen +jenkins:run-job-with-tag Run a Jenkins Job with $(TAG) +make:lint Lint all makefiles +readme:build Create README.md by building it from .README.md file +readme:init Create basic minimalistic .README.md template file +readme:toc-update Update table of contents in README.md +terraform:get-modules Ensure all modules can be fetched +terraform:get-plugins Ensure all plugins can be fetched +terraform:install Install terraform +terraform:lint Lint check Terraform +terraform:validate Basic terraform sanity check +travis:docker-login Login into docker hub +travis:docker-tag-and-push Tag & Push according Travis environment variables ``` - ## Real World Examples - [`github-authorized-keys`](https://github.com/cloudposse/github-authorized-keys/) - A Golang project that leverages `docker:%`, `go:%`, `travis:%` targets @@ -81,10 +88,9 @@ Available targets: ## Help -**Got a question?** +**Got a question?** File a GitHub [issue](https://github.com/cloudposse/build-harness/issues), send us an [email](mailto:hello@cloudposse.com) or reach out to us on [Gitter](https://gitter.im/cloudposse/). - ## Contributing ### Bug Reports & Feature Requests @@ -93,7 +99,7 @@ Please use the [issue tracker](https://github.com/cloudposse/build-harness/issue ### Developing -If you are interested in being a contributor and want to get involved in developing the `build-harness`, we would love to hear from you! Shoot us an [email](mailto:hello@cloudposse.com). +If you are interested in being a contributor and want to get involved in developing `build-harness`, we would love to hear from you! Shoot us an [email](mailto:hello@cloudposse.com). In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. @@ -107,13 +113,16 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. Here's how to get started... -1. `git clone https://github.com/cloudposse/build-harness.git` to pull down the repository +1. `git clone https://github.com/cloudposse/build-harness.git` to pull down the repository 2. `make init` to initialize the [`build-harness`](https://github.com/cloudposse/build-harness/) 3. Review the [documentation](docs/) on compiling + ## License -[APACHE 2.0](LICENSE) © 2016-2017 [Cloud Posse, LLC](https://cloudposse.com) +[APACHE 2.0](LICENSE) © 2017 [Cloud Posse, LLC](https://cloudposse.com) + +See [LICENSE](LICENSE) for full details. Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -122,7 +131,7 @@ Here's how to get started... to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, @@ -131,28 +140,41 @@ Here's how to get started... KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - ## About -GitHub Authorized Keys is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know at +This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know at -We love [Open Source Software](https://github.com/cloudposse/)! +We love [Open Source Software](https://github.com/cloudposse/)! -See [our other projects][community] or [hire us][hire] to help build your next cloud-platform. +See [our other projects][community] +or [hire us][hire] to help build your next cloud-platform. [website]: http://cloudposse.com/ [community]: https://github.com/cloudposse/ [hire]: http://cloudposse.com/contact/ - + ### Contributors +|[![Erik Osterman][erik_img]][erik_web]
[Erik Osterman][erik_web] |[![Igor Rodionov][igor_img]][igor_web]
[Igor Rodionov][igor_img] | +|---|---| + +[andriy_img]: https://avatars0.githubusercontent.com/u/7356997?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144 +[andriy_web]: https://github.com/aknysh/ + +[erik_img]: http://s.gravatar.com/avatar/88c480d4f73b813904e00a5695a454cb?s=144 +[erik_web]: https://github.com/osterman/ + +[igor_img]: http://s.gravatar.com/avatar/bc70834d32ed4517568a1feb0b9be7e2?s=144 +[igor_web]: https://github.com/goruha/ -| [![Erik Osterman][erik_img]][erik_web]
[Erik Osterman][erik_web] | [![Igor Rodionov][igor_img]][igor_web]
[Igor Rodionov][igor_web] | -|-------------------------------------------------------|------------------------------------------------------------------| +[konstantin_img]: https://avatars1.githubusercontent.com/u/11299538?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144 +[konstantin_web]: https://github.com/comeanother/ - [erik_img]: http://s.gravatar.com/avatar/88c480d4f73b813904e00a5695a454cb?s=144 - [erik_web]: https://github.com/osterman/ - [igor_img]: http://s.gravatar.com/avatar/bc70834d32ed4517568a1feb0b9be7e2?s=144 - [igor_web]: https://github.com/goruha/ +[sergey_img]: https://avatars1.githubusercontent.com/u/1134449?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144 +[sergey_web]: https://github.com/s2504s/ +[valeriy_img]: https://avatars1.githubusercontent.com/u/10601658?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144 +[valeriy_web]: https://github.com/drama17/ +[vladimir_img]: https://avatars1.githubusercontent.com/u/26582191?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144 +[vladimir_web]: https://github.com/SweetOps/ diff --git a/bin/doc_generate.sh b/bin/doc_generate.sh new file mode 100755 index 00000000..7920ed38 --- /dev/null +++ b/bin/doc_generate.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash + +IN=${IN:-".README.md"} +OUT=${OUT:-"README.md"} + +TIMESTAMP=$(date +"%s") +TMP=/tmp/$TIMESTAMP + +mkdir -p $TMP + +declare -A DATASOURCES + +INCLUDED_MODULES=() + +# Merge 2 lists (in format words separated be space in string) +function array-merge { + # Declare an associative array + declare -A tmp + # Store the values of arr3 in arr4 as keys. + for k in $@; do tmp["$k"]=1; done + # Extract the keys. + echo "${!tmp[@]}" +} + +## Get template docs modules from $IN file +## Example of usage +## module ./.README.md +function modules { + grep -oP "(?<=datasource)\s+\".*?\"" $1 | sed 's/[ |\"]//g' | sort | uniq | paste -sd " " - +} + +## Fire event $1 for all modules passed as args +## Example of usage +## fire event "test" "git" "make" +## Will call functions "git-test" and "make-test" if exists +function fire_event { + local event=$1 + local modules=${@:2} + + for module in $modules + do + func="$module-$event" + if [ "$(type -t $func)" = 'function' ]; then + $func + fi + done +} + +## Provde datasource options for modules passed as args +## Example of usage +## datasources "git" "make" +function datasources { + for k in $@; do + echo "--datasource $k=${DATASOURCES[$k]}" + done +} + +## Register modules +for file in $BUILD_HARNESS_PATH/modules/*/docs/*.sh ; do + if [ -f "$file" ] ; then + . "$file" + fi +done + +## Find used modules in $IN file +MODULES=$(modules $IN) + +until [ -z "$MODULES" ] +do + ## Merge modules list with modules from previous iteration + INCLUDED_MODULES=$( array-merge $INCLUDED_MODULES $MODULES) + ## Prepare data for just found modules + fire_event "docs-prepare-data" $MODULES + ## Replace template + $GOMPLATE --file $IN --out $OUT $(datasources $INCLUDED_MODULES) + + ## For all iterations (except first) use $OUT file as $IN template to replace recursive placeholders + IN=$OUT + ## Find modules in $IN file for next interation. + MODULES=$(modules $IN) +done + +## Cleanup prepared data for all used modules +fire_event "docs-cleanup-data" $INCLUDED_MODULES + +rm -rf $TMP + +echo "$OUT doc generated" + + + diff --git a/modules/docs/Makefile b/modules/docs/Makefile new file mode 100644 index 00000000..1e57a2b0 --- /dev/null +++ b/modules/docs/Makefile @@ -0,0 +1,20 @@ +export GOMPLATE ?= $(BUILD_HARNESS_PATH)/vendor/gomplate +GOMPLATE_VERSION ?= v2.2.0 +GOMPLATE_REPO ?= hairyhenderson/gomplate + + +## Install dependencies +docs\:deps: + @make github:download-public-release \ + REPO=$(GOMPLATE_REPO) \ + FILE=gomplate_$(OS)-amd64 \ + VERSION=$(GOMPLATE_VERSION) \ + OUTPUT=$(GOMPLATE) > /dev/null + @chmod +x $(GOMPLATE) + + + +.PHONY : docs\:build +## Create $OUT file by building it from $IN template file +docs\:build: + @$(BUILD_HARNESS_PATH)/bin/doc_generate.sh diff --git a/modules/docs/Makefile.docs b/modules/docs/Makefile.docs deleted file mode 100644 index 6311ea8e..00000000 --- a/modules/docs/Makefile.docs +++ /dev/null @@ -1,4 +0,0 @@ -.PHONY : docs\:toc-update -## Update table of contents in README.md -docs\:toc-update: - @doctoc --notitle --github README.md \ No newline at end of file diff --git a/modules/docs/docs/module.sh b/modules/docs/docs/module.sh new file mode 100644 index 00000000..80444896 --- /dev/null +++ b/modules/docs/docs/module.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +DATASOURCES[contributor]=file://$BUILD_HARNESS_PATH/modules/docs/docs/templates/contributor.yml +DATASOURCES[license]=file://$BUILD_HARNESS_PATH/modules/docs/docs/templates/license.yml +DATASOURCES[section]=file://$BUILD_HARNESS_PATH/modules/docs/docs/templates/section.yml + diff --git a/modules/docs/docs/templates/contributor.yml b/modules/docs/docs/templates/contributor.yml new file mode 100644 index 00000000..af27effb --- /dev/null +++ b/modules/docs/docs/templates/contributor.yml @@ -0,0 +1,43 @@ +--- + andrew: |- + [![Andriy Knysh][andriy_img]][andriy_web]
[Andriy Knysh][andriy_web] + + erik: |- + [![Erik Osterman][erik_img]][erik_web]
[Erik Osterman][erik_web] + + igor: |- + [![Igor Rodionov][igor_img]][igor_web]
[Igor Rodionov][igor_img] + + konstantin: |- + [![Konstantin B][konstantin_img]][konstantin_web]
[Konstantin B][konstantin_web] + + sergey: |- + [![Sergey Vasilyev][sergey_img]][sergey_web]
[Sergey Vasilyev][sergey_web] + + valeriy: |- + [![Valeriy][valeriy_img]][valeriy_web]
[Valeriy][valeriy_web] + + vladimir: |- + [![Vladimir][vladimir_img]][vladimir_web]
[Vladimir][vladimir_web] + + _links: |- + [andriy_img]: https://avatars0.githubusercontent.com/u/7356997?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144 + [andriy_web]: https://github.com/aknysh/ + + [erik_img]: http://s.gravatar.com/avatar/88c480d4f73b813904e00a5695a454cb?s=144 + [erik_web]: https://github.com/osterman/ + + [igor_img]: http://s.gravatar.com/avatar/bc70834d32ed4517568a1feb0b9be7e2?s=144 + [igor_web]: https://github.com/goruha/ + + [konstantin_img]: https://avatars1.githubusercontent.com/u/11299538?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144 + [konstantin_web]: https://github.com/comeanother/ + + [sergey_img]: https://avatars1.githubusercontent.com/u/1134449?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144 + [sergey_web]: https://github.com/s2504s/ + + [valeriy_img]: https://avatars1.githubusercontent.com/u/10601658?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144 + [valeriy_web]: https://github.com/drama17/ + + [vladimir_img]: https://avatars1.githubusercontent.com/u/26582191?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144 + [vladimir_web]: https://github.com/SweetOps/ diff --git a/modules/docs/docs/templates/license.yml b/modules/docs/docs/templates/license.yml new file mode 100644 index 00000000..9b3d8552 --- /dev/null +++ b/modules/docs/docs/templates/license.yml @@ -0,0 +1,24 @@ +--- + apache2: |- + ## License + + [APACHE 2.0](LICENSE) © 2017 [Cloud Posse, LLC](https://cloudposse.com) + + See [LICENSE](LICENSE) for full details. + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. diff --git a/modules/docs/docs/templates/section.yml b/modules/docs/docs/templates/section.yml new file mode 100644 index 00000000..91feaab6 --- /dev/null +++ b/modules/docs/docs/templates/section.yml @@ -0,0 +1,46 @@ +--- +warning: |- + +about: |- + ## About + + This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know at + + We love [Open Source Software](https://github.com/cloudposse/)! + + See [our other projects][community] + or [hire us][hire] to help build your next cloud-platform. + + [website]: http://cloudposse.com/ + [community]: https://github.com/cloudposse/ + [hire]: http://cloudposse.com/contact/ +help: |- + ## Help + + **Got a question?** + + File a GitHub [issue](https://github.com/cloudposse/{{ (datasource "git").name }}/issues), send us an [email](mailto:hello@cloudposse.com) or reach out to us on [Gitter](https://gitter.im/cloudposse/). + +contributing: |- + ## Contributing + + ### Bug Reports & Feature Requests + + Please use the [issue tracker](https://github.com/cloudposse/{{ (datasource "git").name }}/issues) to report any bugs or file feature requests. + + ### Developing + + If you are interested in being a contributor and want to get involved in developing `{{ (datasource "git").name }}`, we would love to hear from you! Shoot us an [email](mailto:hello@cloudposse.com). + + In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. + + 1. **Fork** the repo on GitHub + 2. **Clone** the project to your own machine + 3. **Commit** changes to your own branch + 4. **Push** your work back up to your fork + 5. Submit a **Pull request** so that we can review your changes + + **NOTE:** Be sure to merge the latest from "upstream" before making a pull request! diff --git a/modules/git/docs/module.sh b/modules/git/docs/module.sh new file mode 100644 index 00000000..ac4b45d0 --- /dev/null +++ b/modules/git/docs/module.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +GIT_DATA_FILE=$TMP/git_data.yml + +DATASOURCES[git]=file://$BUILD_HARNESS_PATH/modules/git/docs/templates/git.yml +DATASOURCES[git_data]=file://$GIT_DATA_FILE + +function git_data-docs-prepare-data { +cat << EOF > $GIT_DATA_FILE +--- + url: $(git ls-remote --get-url) + name: $(git ls-remote --get-url | grep -oP "(?<=\/).*(?=.git)") +EOF +} + +function git_data-docs-cleanup-data { + rm -f $GIT_DATA_FILE +} diff --git a/modules/git/docs/templates/git.yml b/modules/git/docs/templates/git.yml new file mode 100644 index 00000000..d2c449ae --- /dev/null +++ b/modules/git/docs/templates/git.yml @@ -0,0 +1,3 @@ +--- +name: |- + {{ (datasource "git_data").name }} diff --git a/modules/make/Makefile b/modules/make/Makefile index 9d31815f..ca232f41 100644 --- a/modules/make/Makefile +++ b/modules/make/Makefile @@ -4,5 +4,3 @@ make\:lint: find . -type f -name 'Makefile*' -type f '!' -name '*.example' -exec \ /bin/sh -c 'echo "==> {}">/dev/stderr; make --include-dir=modules/ --just-print --dry-run --recon --no-print-directory --quiet --silent -f {}' \; > /dev/null @make bash:lint - - diff --git a/modules/make/docs/module.sh b/modules/make/docs/module.sh new file mode 100644 index 00000000..e74d55e4 --- /dev/null +++ b/modules/make/docs/module.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +MAKE_DATA_FILE=$TMP/make_data.yml + +DATASOURCES[make]=file://$BUILD_HARNESS_PATH/modules/make/docs/templates/make.yml +DATASOURCES[make_data]=file://$MAKE_DATA_FILE + +function make_data-docs-prepare-data { +cat << EOF > $MAKE_DATA_FILE +--- +help: |- + $(make -s help | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | sed -e 's/^/ /') +EOF +} + +function make_data-docs-cleanup-data { + rm -f $MAKE_DATA_FILE +} diff --git a/modules/make/docs/templates/make.yml b/modules/make/docs/templates/make.yml new file mode 100644 index 00000000..cd904396 --- /dev/null +++ b/modules/make/docs/templates/make.yml @@ -0,0 +1,9 @@ +--- + help: |- + ## Makefile Targets + + ```bash + $ make help + + {{ (datasource "make_data").help }} + ``` \ No newline at end of file diff --git a/modules/readme/Makefile.docs b/modules/readme/Makefile.docs new file mode 100644 index 00000000..b5e219b7 --- /dev/null +++ b/modules/readme/Makefile.docs @@ -0,0 +1,24 @@ +README_FILE ?= README.md +README_TEMPLATE_NAME ?= .$(README_FILE) + +.PHONY : readme\:toc-update +## Update table of contents in README.md +readme\:toc-update: + @doctoc --notitle --github $(README_FILE) + +.PHONY : readme\:init +## Create basic minimalistic .README.md template file +readme\:init: + @if [ -s ./$(README_TEMPLATE_FILE) ]; then \ + echo "$(README_TEMPLATE_FILE) already exists!"; \ + else \ + cp $(BUILD_HARNESS_PATH)/templates/$(README_TEMPLATE_FILE) ./$(README_FILE) ; \ + echo "$(README_FILE) created!"; \ + fi; + +.PHONY : readme\:build +## Create README.md by building it from .README.md file +readme\:build: + @IN=$(README_TEMPLATE_FILE) \ + OUT=$(README_FILE) \ + make -s docs:build diff --git a/modules/terraform/Makefile b/modules/terraform/Makefile index dcc19f28..19995567 100644 --- a/modules/terraform/Makefile +++ b/modules/terraform/Makefile @@ -1,8 +1,10 @@ TMP ?= /tmp -TERRAFORM ?= $(BUILD_HARNESS_PATH)/terraform +TERRAFORM ?= $(BUILD_HARNESS_PATH)/vendor/terraform TERRAFORM_VERSION ?= 0.10.7 TERRAFORM_URL ?= https://releases.hashicorp.com/terraform/$(TERRAFORM_VERSION)/terraform_$(TERRAFORM_VERSION)_$(OS)_amd64.zip + + ## Install terraform terraform\:install: @[ -x $(TERRAFORM) ] || ( \ diff --git a/modules/terraform/docs/module.sh b/modules/terraform/docs/module.sh new file mode 100644 index 00000000..a501a189 --- /dev/null +++ b/modules/terraform/docs/module.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +TERRAFORM_DOCS_REPO=segmentio/terraform-docs +TERRAFORM_DOCS_VERSION=v0.3.0 +TERRAFORM_DOCS=${BUILD_HARNESS_PATH}/vendor/terraform-docs + +TERRAFORM_DATA_FILE=$TMP/terraform_data.yml + +DATASOURCES[terraform]=file://$BUILD_HARNESS_PATH/modules/terraform/docs/templates/terraform.yml +DATASOURCES[terraform_data]=file://$TERRAFORM_DATA_FILE + + +function terraform-docs-prepare-data { + if [ ! -s $TERRAFORM_DOCS ]; then + REPO=$TERRAFORM_DOCS_REPO \ + FILE=terraform-docs_${OS}_amd64 \ + VERSION=$TERRAFORM_DOCS_VERSION \ + OUTPUT=$TERRAFORM_DOCS \ + make github:download-public-release + + chmod +x $TERRAFORM_DOCS + fi; +} + +function terraform_data-docs-prepare-data { + $TERRAFORM_DOCS json . > $TERRAFORM_DATA_FILE +} +function terraform-docs-cleanup-data { + rm -f $TERRAFORM_DATA_FILE +} + diff --git a/modules/terraform/docs/templates/terraform.yml b/modules/terraform/docs/templates/terraform.yml new file mode 100644 index 00000000..46928123 --- /dev/null +++ b/modules/terraform/docs/templates/terraform.yml @@ -0,0 +1,34 @@ +--- + input: |- + ## Input + + + | Name | Default | Description | + |:------|:---------:|:--------------:| + {{- range $index, $element := (datasource "terraform_data").Inputs }} + | {{ $element.Name }} | + {{- if $element.Default }} + {{- if eq $element.Default.Type "map" }} + {{- "{}" }} + {{- else }} + {{- if eq $element.Default.Type "list" -}} + [] + {{- else -}} + "{{ $element.Default.Literal }}" + {{- end }} + {{- end }} + {{- else -}} + __REQUIRED__ + {{- end }} | + {{- $element.Description | strings.ReplaceAll "\n" " " }}| + {{- end }} + + output: |- + ## Output + + + | Name | Description | + |:------|:------------:| + {{- range $index, $element := (datasource "terraform_data").Outputs }} + | {{ $element.Name }} | {{ $element.Description | strings.ReplaceAll "\n" " " }} | + {{- end }} diff --git a/templates/README.md b/templates/README.md new file mode 100644 index 00000000..45822aec --- /dev/null +++ b/templates/README.md @@ -0,0 +1,16 @@ +## {{ .Env.NAME }} +{{ (datasource "section").warning }} +{{ .Env.DESCRIPTION }} + +{{ (datasource "section").help }} +{{ (datasource "section").contributing }} +{{ (datasource "license").apache2 }} +{{ (datasource "section").about }} + +### Contributors + +| +{{- (datasource "contributor").erik }} | +|---| + +{{ (datasource "contributor")._links }} diff --git a/vendor/.gitignore b/vendor/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/vendor/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file