Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BBL-381 | standalone makefile approach implemented + README.md updated #11

Merged
merged 2 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_DEV: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
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
146 changes: 18 additions & 128 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,137 +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 := /usr/local/go/bin/terraform
TF_DOCKER_IMAGE := binbash/terraform-resources

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 \
--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} .
cp -r ./vendor ./tests/ && rm -rf ./vendor
cp -r ./Gopkg* ./tests/ && rm -rf ./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}/terraform12/terraform12.mk
#include ${MAKEFILES_DIR}/terratest12/terratest12.mk
Loading