Skip to content

Commit

Permalink
Merge pull request #24 from binbashar/BBL-381-testing-ci
Browse files Browse the repository at this point in the history
BBL-381 | standalone makefile + testing ci
  • Loading branch information
exequielrafaela authored Sep 18, 2020
2 parents a18f9aa + 9a20dce commit d8d2245
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 357 deletions.
28 changes: 25 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,27 @@ jobs:
name: Context Info Cmds
command: pwd && ls -ltra && git branch

- run:
name: Initialize Repo Makefiles
command: |
make init-makefiles
git update-index --assume-unchanged "Makefile"
- run:
name: test1-terraform-format
command: make format-check

- run:
name: Install awscli
command: sudo pip install awscli
command: sudo -H pip install awscli

- run:
name: Configure awscli
command: |
# AWS credentials dir
mkdir --parents /home/circleci/.aws/bb
sudo chown -R $USER:$USER /home/circleci/.aws
# AWS defautl awscli profile
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
Expand All @@ -39,8 +49,8 @@ jobs:
# AWS dev awscli profile
aws configure set role_arn arn:aws:iam::$AWS_ACCOUNT_ID_SHARED:role/DeployMaster --profile $AWS_PROFILE_NAME
aws configure set source_profile default --profile $AWS_PROFILE_NAME
# moving credentials to specific project folder
mkdir --parents /home/circleci/.aws/bb
cp /home/circleci/.aws/credentials /home/circleci/.aws/bb/credentials
cp /home/circleci/.aws/config /home/circleci/.aws/bb/config
Expand All @@ -63,6 +73,12 @@ jobs:
name: Context Info Cmds
command: pwd && ls -ltra && git branch

- run:
name: Initialize Repo Makefiles
command: |
make init-makefiles
git update-index --assume-unchanged "Makefile"
- run:
name: Install awscli
command: sudo pip install awscli
Expand Down Expand Up @@ -114,6 +130,12 @@ jobs:
name: Context Info Cmds
command: pwd && ls -ltra && git branch

- run:
name: Initialize Repo Makefiles
command: |
make init-makefiles
git update-index --assume-unchanged "Makefile"
- run:
name: Release New Version
command: |
Expand All @@ -123,7 +145,7 @@ jobs:
echo "==============================================================================================="
git config --global user.email "$GIT_USER_EMAIL"
git config --global user.name "$GIT_USER_NAME"
make -f Makefile.release release-$VERSION_NUMBER-with-changelog-circleci
make release-$VERSION_NUMBER-with-changelog-circleci
else
echo "==============================================================================================="
echo "Changes in working directory pending to be pushed - please check 'git status' cmd output below "
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ assignees: ''

## Describe the Feature

A clear and concise description of what the bug is.
A clear and concise description of what the bug is.

## Expected Behavior

Expand Down
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Use bullet points to be concise and to the point.

## why
* Provide the justifications for the changes (e.g. business case).
* Provide the justifications for the changes (e.g. business case).
* Describe why these changes were made (e.g. why do these commits fix the problem?)
* Use bullet points to be concise and to the point.

## references
* Link to any supporting github issues or helpful documentation to add some context (e.g. stackoverflow).
* Link to any supporting github issues or helpful documentation to add some context (e.g. stackoverflow).
* Use `closes #123`, if this PR closes a GitHub issue `#123`

15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
!*.circleci
!*.dockeringnore
!*.hosts
!/.gitignore
!.hosts.example
!*.gitignore
!/.chglog
!/.gitallowed
!/.github
Expand All @@ -19,6 +20,7 @@
############
id_rsa
id_dsa
keys/

# OS generated files #
######################
Expand Down Expand Up @@ -79,9 +81,18 @@ Thumbs.db
*.pgpass
*.vagrant

# TF Project files #
# Project files #
####################
#
# Secret Files
#
*secrets.dec.*
#
# Scripts and Makefiles
#
/@bin
!/@bin/scripts
#
# Compiled files
#
*.tfstate
Expand Down
147 changes: 18 additions & 129 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,138 +1,27 @@
.PHONY: help
SHELL := /bin/bash
PROJECT_SHORT := bb

LOCAL_OS_USER_ID := $(shell id -u)
LOCAL_OS_GROUP_ID := $(shell id -g)
LOCAL_OS_SSH_DIR := ~/.ssh
LOCAL_OS_GIT_CONF_DIR := ~/.gitconfig
LOCAL_OS_AWS_CONF_DIR := ~/.aws/${PROJECT_SHORT}

# localhost aws-iam-profile
#LOCAL_OS_AWS_PROFILE := bb-shared-deploymaster
# ci aws-iam-profile
LOCAL_OS_AWS_PROFILE :="bb-dev-deploymaster"
LOCAL_OS_AWS_REGION := us-east-1

TF_PWD_DIR := $(shell pwd)
TF_VER := 0.12.28
TF_PWD_CONT_DIR := "/go/src/project/"
TF_DOCKER_ENTRYPOINT := /bin/terraform
TF_DOCKER_IMAGE := binbash/terraform-awscli-terratest-slim

TERRATEST_DOCKER_ENTRYPOINT := dep
TERRATEST_DOCKER_WORKDIR := /go/src/project/tests

#
# TERRAFORM
#
define TF_CMD_PREFIX
docker run --rm \
-v ${TF_PWD_DIR}:${TF_PWD_CONT_DIR}:rw \
--entrypoint=${TF_DOCKER_ENTRYPOINT} \
-w ${TF_PWD_CONT_DIR} \
-it ${TF_DOCKER_IMAGE}:${TF_VER}
endef

#
# TERRATEST
#
define TERRATEST_GO_CMD_PREFIX
docker run --rm \
-v ${TF_PWD_DIR}:${TF_PWD_CONT_DIR}:rw \
-v ${LOCAL_OS_SSH_DIR}:/root/.ssh \
-v ${LOCAL_OS_GIT_CONF_DIR}:/etc/gitconfig \
-v ${LOCAL_OS_AWS_CONF_DIR}:/root/.aws/${PROJECT_SHORT} \
-e AWS_SHARED_CREDENTIALS_FILE=/root/.aws/${PROJECT_SHORT}/credentials \
-e AWS_CONFIG_FILE=/root/.aws/${PROJECT_SHORT}/config \
-w ${TERRATEST_DOCKER_WORKDIR} \
-it ${TF_DOCKER_IMAGE}:${TF_VER}
endef

define TERRATEST_GO_CMD_BASH_PREFIX
docker run --rm \
-v ${TF_PWD_DIR}:${TF_PWD_CONT_DIR}:rw \
-v ${LOCAL_OS_SSH_DIR}:/root/.ssh \
-v ${LOCAL_OS_GIT_CONF_DIR}:/etc/gitconfig \
-v ${LOCAL_OS_AWS_CONF_DIR}:/root/.aws/${PROJECT_SHORT} \
-e AWS_SHARED_CREDENTIALS_FILE=/root/.aws/${PROJECT_SHORT}/credentials \
-e AWS_CONFIG_FILE=/root/.aws/${PROJECT_SHORT}/config \
-w ${TERRATEST_DOCKER_WORKDIR} \
--entrypoint=bash \
-it ${TF_DOCKER_IMAGE}:${TF_VER}
endef

define TERRATEST_DEP_CMD_PREFIX
docker run --rm \
-v ${TF_PWD_DIR}:${TF_PWD_CONT_DIR}:rw \
-v ${LOCAL_OS_SSH_DIR}:/root/.ssh \
-v ${LOCAL_OS_GIT_CONF_DIR}:/etc/gitconfig \
-w ${TERRATEST_DOCKER_WORKDIR} \
--entrypoint=${TERRATEST_DOCKER_ENTRYPOINT} \
-it ${TF_DOCKER_IMAGE}:${TF_VER}
endef
SHELL := /bin/bash
MAKEFILE_PATH := ./Makefile
MAKEFILES_DIR := ./@bin/makefiles

help:
@echo 'Available Commands:'
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " - \033[36m%-18s\033[0m %s\n", $$1, $$2}'

#==============================================================#
# TERRAFORM #
# INITIALIZATION #
#==============================================================#
version: ## Show terraform version
docker run --rm \
--entrypoint=${TF_DOCKER_ENTRYPOINT} \
-t ${TF_DOCKER_IMAGE}:${TF_VER} version

format: ## The terraform fmt is used to rewrite tf conf files to a canonical format and style.
${TF_CMD_PREFIX} fmt -recursive

format-check: ## The terraform fmt is used to rewrite tf conf files to a canonical format and style.
${TF_CMD_PREFIX} fmt -check -recursive
init-makefiles: ## initialize makefiles
rm -rf ${MAKEFILES_DIR}
mkdir -p ${MAKEFILES_DIR}
git clone https://github.com/binbashar/le-dev-makefiles.git ${MAKEFILES_DIR}
echo "" >> ${MAKEFILE_PATH}
sed -i '/^#include.*/s/^#//' ${MAKEFILE_PATH}

pre-commit: ## Execute validation: pre-commit run --all-files.
pre-commit run --all-files

terraform-docs: ## A utility to generate documentation from Terraform 0.12 modules in various output formats.
docker run --rm \
-v $$(pwd):/data \
cytopia/terraform-docs:0.8.0 \
terraform-docs-012 --sort-inputs-by-required --with-aggregate-type-defaults markdown table .

tflint: ## TFLint is a Terraform linter for detecting errors that can not be detected by terraform plan (tf0.12 > 0.10.x).
docker run --rm \
-v ${LOCAL_OS_AWS_CONF_DIR}:/root/.aws \
-v ${TF_PWD_DIR}:/data \
-t wata727/tflint:0.13.2

tflint-deep: ## TFLint is a Terraform linter for detecting errors that can not be detected by terraform plan (tf0.12 > 0.10.x).
docker run --rm \
-v ${LOCAL_OS_AWS_CONF_DIR}:/root/.aws \
-v ${TF_PWD_DIR}:/data \
-t wata727/tflint:0.13.2 --deep \
--aws-profile=${LOCAL_OS_AWS_PROFILE} \
--aws-creds-file=/root/.aws/credentials \
--aws-region=${LOCAL_OS_AWS_REGION}

#==============================================================#
# TERRATEST #
#==============================================================#
terratest-dep-init: ## dep is a dependency management tool for Go. (https://github.com/golang/dep)
${TERRATEST_DEP_CMD_PREFIX} init
${TERRATEST_DEP_CMD_PREFIX} ensure
sudo chown -R ${LOCAL_OS_USER_ID}:${LOCAL_OS_GROUP_ID} .
rm -rf ./tests/vendor
rm -rf ./tests/Gopkg*

terratest-go-test: ## Run E2E terratests
${TERRATEST_GO_CMD_PREFIX} test -timeout 20m
sudo chown -R ${LOCAL_OS_USER_ID}:${LOCAL_OS_GROUP_ID} .

terratest-go-test-bash: ## Run E2E terratests interactive bash
${TERRATEST_GO_CMD_BASH_PREFIX}

#==============================================================#
# CIRCLECI #
#==============================================================#
circleci-validate-config: ## Validate A CircleCI Config (https://circleci.com/docs/2.0/local-cli/)
circleci config validate .circleci/config.yml
#
## IMPORTANT: Automatically managed
## Must NOT UNCOMMENT the #include lines below
#
#include ${MAKEFILES_DIR}/circleci/circleci.mk
#include ${MAKEFILES_DIR}/release-mgmt/release.mk
#include ${MAKEFILES_DIR}/terraform13/terraform13.mk
#include ${MAKEFILES_DIR}/terratest13/terratest13.mk
Loading

0 comments on commit d8d2245

Please sign in to comment.