Skip to content

A collection of build tools for the Mineiros Infrastructure as Code (IaC) library.

License

Notifications You must be signed in to change notification settings

mineiros-io/build-tools

Repository files navigation

Build Status GitHub tag (latest SemVer) license

build-tools

A collection of build tools for the Mineiros Infrastructure as Code (IaC) library.

Introduction

The main part of build-tools is a docker image that comes with install instructions for all necessary tools. Currently, we are installing the following dependencies:

Dependencies

Linters

In addition to the above listed technologies, build-tools ships with some pre-installed linters, that help you to ensure code quality and standards:

Security

This repository ships with some pre-installed open-source software that help you to monitor security:

Getting started

The easiest way to use build-tools is to pull the image from hub.docker.com.

The following command will pull the image from the registry and runs terraform --version inside a container.

docker run --rm \
  mineiros/build-tools:latest \
  terraform --version

Working Directory

The containers working directory is /build which should be your target if you decide to mount any files from your local filesystem.

Terraform Working Directory

Per default Terraform is configured to use /terraform as its working directory. This is configured through the TF_DATA_DIR environment variable and means that the .terraform directory will be removed after the container exits. We recommend creating a named docker volume for the /terraform directory to re-use its content between different runs.

docker run --rm \
  -v ${PWD}:/build \
  -v terraform-working-directory:/terraform
  mineiros/build-tools:latest \
  terraform init

The working directory can be adjusted for a specific container through the TF_DATA_DIR environment variable.

docker run --rm \
  -v ${PWD}:/build \
  -e TF_DATA_DIR:/build
  mineiros/build-tools:latest \
  terraform init

Go Working Directory

Per default, Go is configured to use /go as its working directory. This is configured through the GO_PATH environment variable/ We recommend creating a named docker volume for the /go directory to re-use its content between different runs.

docker run --rm \
  -v ${PWD}:/build \
  -v go-path-directory:/go \
  mineiros/build-tools:latest \
  go test ./test/...

The Go directory can be adjusted for a specific container through the GO_PATH environment variable.

docker run --rm \
  -e GO_PATH=/build \
  -v ${PWD}:/build \
  mineiros/build-tools:latest \
  go test ./test/...

Examples

Please see the following examples for common use-cases.

Terraform init

Mount the current working diretory as a volume and run terraform init to initialize the terraform working environment.

docker run --rm \
  -v ${PWD}:/build \
  mineiros/build-tools:latest \
  terraform init

Work with S3 remote state

Mount the current working directory as a volume, pass AWS access credentials as environment variables and run terraform init. Requires S3 to be configured as the remote state backend.

docker run --rm \
  -v ${PWD}:/build \
  -e AWS_ACCESS_KEY_ID \
  -e AWS_SECRET_ACCESS_KEY \
  -e AWS_SESSION_TOKEN \
  mineiros/build-tools:latest \
  terraform init

Create a Terraform planfile

Mount the current working directory as a volume, pass AWS access credentials as environment variables and run terraform plan --out=plan.tf for creating a plan file that we can use with the terraform apply comand.

docker run --rm \
  -v ${PWD}:/build \
  -e AWS_ACCESS_KEY_ID \
  -e AWS_SECRET_ACCESS_KEY \
  -e AWS_SESSION_TOKEN \
  mineiros/build-tools:latest \
  terraform plan -input=false -out=plan.tf

Apply a Terraform planfile

Mount the current working directory as a volume, pass AWS access credentials as environment variables and run terraform apply -auto-approve -input=false plan.tf for applying changes.

docker run --rm \
  -v ${PWD}:/build \
  -e USER_UID=$(id -u) \
  -e AWS_ACCESS_KEY_ID \
  -e AWS_SECRET_ACCESS_KEY \
  -e AWS_SESSION_TOKEN \
  mineiros/build-tools:latest \
  terraform apply -input=false -out=plan.tf

Run go fmt on mounted source code

Mounts the current working director as a volume and run go fmt recursively.

docker run --rm \
  -v ${PWD}:/build \
  -e USER_UID=$(id -u) \
  mineiros/build-tools:latest \
  go fmt ./...

Run checkov on mounted directory

docker run --rm \                                                                                                                                                                                           
  -v ${PWD}:/build \
  -e USER_UID=$(id -u) \
  mineiros/build-tools:latest \
  checkov --directory ./

Module Versioning

This Module follows the principles of Semantic Versioning (SemVer).

Using the given version number of MAJOR.MINOR.PATCH, we apply the following constructs:

  1. Use the MAJOR version for incompatible changes.
  2. Use the MINOR version when adding functionality in a backwards compatible manner.
  3. Use the PATCH version when introducing backwards compatible bug fixes.

Backwards compatibility in 0.0.z and 0.y.z version

  • In the context of initial development, backwards compatibility in versions 0.0.z is not guaranteed when z is increased. (Initial development)
  • In the context of pre-release, backwards compatibility in versions 0.y.z is not guaranteed when y is increased. (Pre-release)

About Mineiros

Mineiros is a DevOps as a Service company based in Berlin, Germany. We offer commercial support for all of our projects and encourage you to reach out if you have any questions or need help. Feel free to send us an email at [email protected].

We can also help you with:

  • Terraform modules for all types of infrastructure such as VPCs, Docker clusters, databases, logging and monitoring, CI, etc.
  • Consulting & training on AWS, Terraform and DevOps

Reporting Issues

We use GitHub Issues to track community reported issues and missing features.

Contributing

Contributions are always encouraged and welcome! For the process of accepting changes, we use Pull Requests. If you'd like more information, please see our Contribution Guidelines.

Makefile Targets

This repository comes with a handy Makefile. Run make help to see details on each available target.

License

This module is licensed under the Apache License Version 2.0, January 2004. Please see LICENSE for full details.

Copyright © 2020 Mineiros GmbH