11# Set default shell to bash
22SHELL := /bin/bash -o pipefail
33
4- BUILD_TOOLS_VERSION ?= v0.7 .0
4+ BUILD_TOOLS_VERSION ?= v0.11 .0
55BUILD_TOOLS_DOCKER_REPO ?= mineiros/build-tools
66BUILD_TOOLS_DOCKER_IMAGE ?= ${BUILD_TOOLS_DOCKER_REPO}:${BUILD_TOOLS_VERSION}
77
8- # If running in CI
8+ # If running in CI (e.g. GitHub Actions)
9+ # https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables
910#
10- # to disable TF_IN_AUTOMATION in CI set it to empty
11+ # To disable TF_IN_AUTOMATION in CI set it to empty
1112# https://www.terraform.io/docs/commands/environment-variables.html#tf_in_automation
1213#
13- # we are using GNU style quiet commands to disable set V to non-empty e.g. V=1
14+ # We are using GNU style quiet commands to disable set V to non-empty e.g. V=1
1415# https://www.gnu.org/software/automake/manual/html_node/Debugging-Make-Rules.html
1516#
1617ifdef CI
@@ -27,10 +28,15 @@ ifndef NOCOLOR
2728 RESET := $(shell tput -Txterm sgr0)
2829endif
2930
31+ # We are creating docker volumes for /go and /terraform that are unique per
32+ # repository to reuse dependencies between different docker run commands.
33+ VOLUME_PREFIX ?= mineiros_build_tools
34+ VOLUME_SUFFIX ?= $(notdir $(shell git rev-parse --show-toplevel || "build") )
35+ DOCKER_RUN_FLAGS += -v ${VOLUME_PREFIX}-terraform-${VOLUME_SUFFIX}:/terraform
36+ DOCKER_RUN_FLAGS += -v ${VOLUME_PREFIX}-go-${VOLUME_SUFFIX}:/go
37+ DOCKER_RUN_FLAGS += -v ${PWD}:/build
3038DOCKER_RUN_FLAGS += --rm
31- DOCKER_RUN_FLAGS += -v ${PWD}:/app/src
3239DOCKER_RUN_FLAGS += -e TF_IN_AUTOMATION
33- DOCKER_RUN_FLAGS += -e USER_UID=$(shell id -u)
3440
3541DOCKER_SSH_FLAGS += -e SSH_AUTH_SOCK=/ssh-agent
3642DOCKER_SSH_FLAGS += -v ${SSH_AUTH_SOCK}:/ssh-agent
@@ -45,7 +51,13 @@ DOCKER_RUN_CMD = docker run ${DOCKER_FLAGS} ${BUILD_TOOLS_DOCKER_IMAGE}
4551.PHONY : default
4652default : help
4753
48- # # Run pre-commit hooks in build-tools docker container.
54+ # Not exposed as a callable target by `make help`, since this is a one-time shot to simplify the development of this module.
55+ .PHONY : template/adjust
56+ template/adjust : FILTER = -path ./.git -prune -a -type f -o -type f -not -name Makefile
57+ template/adjust :
58+ @find . $(FILTER ) -exec sed -i -e " s,terraform-module-template,$$ {PWD##*/},g" {} \;
59+
60+ # # Run pre-commit hooks inside a build-tools docker container.
4961.PHONY : test/pre-commit
5062test/pre-commit : DOCKER_FLAGS += ${DOCKER_SSH_FLAGS}
5163test/pre-commit :
@@ -55,17 +67,18 @@ test/pre-commit:
5567.PHONY : test/unit-tests
5668test/unit-tests : DOCKER_FLAGS += ${DOCKER_SSH_FLAGS}
5769test/unit-tests : DOCKER_FLAGS += ${DOCKER_AWS_FLAGS}
70+ test/unit-tests : TEST ?= "TestUnit"
5871test/unit-tests :
5972 @echo " ${YELLOW} [TEST] ${GREEN} Start Running Go Tests in Docker Container.${RESET} "
60- $(call go-test,./test/... )
73+ $(call go-test,./test -run $( TEST ) )
6174
6275# # Clean up cache and temporary files
6376.PHONY : clean
6477clean :
6578 $(call rm-command,.terraform)
6679 $(call rm-command,* .tfplan)
67- $(call rm-command,examples /* /.terraform)
68- $(call rm-command,examples /* /* .tfplan)
80+ $(call rm-command,* /* /.terraform)
81+ $(call rm-command,* /* /* .tfplan)
6982
7083# # Display help for all targets
7184.PHONY : help
0 commit comments