Skip to content

Commit

Permalink
refactor: configuration make (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
luismayta committed Apr 6, 2021
1 parent 58f2345 commit 43831c4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 39 deletions.
26 changes: 14 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,25 @@ include provision/make/*.mk
help:
@echo '${MESSAGE} Makefile for ${PROJECT}'
@echo ''
@echo 'Usage:'
@echo ' environment create environment with pyenv'
@echo ' setup install requirements'
@echo ' readme build README'
@echo ''
@make docs.help
@make test.help
@make git.help
@make utils.help
@make python.help
@make yarn.help
@make terraform.help
@awk '/^.PHONY: / { \
msg = match(lastLine, /^## /); \
if (msg) { \
cmd = substr($$0, 9, 100); \
msg = substr(lastLine, 4, 1000); \
printf " ${GREEN}%-30s${RESET} %s\n", cmd, msg; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

## Create README.md by building it from README.yaml
.PHONY: readme
readme:
@make terraform.docs
@gomplate --file $(README_TEMPLATE) \
--out $(README_FILE)

## setup dependences of project
.PHONY: setup
setup:
@echo "==> install packages..."
make python.setup
Expand All @@ -94,6 +94,8 @@ setup:
make git.setup
@echo ${MESSAGE_HAPPY}

## setup environment of project
.PHONY: environment
environment:
@echo "==> loading virtualenv ${PYENV_NAME}..."
make python.environment
Expand Down
7 changes: 7 additions & 0 deletions provision/make/docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
.PHONY: docker.help
DOCKER_NETWORK = $(PROJECT)_network

.PHONY: docker
docker: docker.help

.PHONY: docker.help
docker.help:
@echo ' Docker:'
@echo ''
Expand All @@ -20,20 +22,24 @@ docker.help:
@echo ' docker.list list services of docker'
@echo ''

## Run docker args {service} {stage}
.PHONY: docker.run
docker.run:
@if [ -z "${stage}" ]; then \
$(docker-dev) run --rm ${service} bash; \
else \
$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/${stage}.yml run --rm ${service} bash; \
fi

.PHONY: docker.restart
docker.restart:
@if [ -z "${stage}" ]; then \
$(docker-dev) restart; \
else \
$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/${stage}.yml restart; \
fi

.PHONY: docker.build
docker.build:
@echo $(MESSAGE) "Building stage: ${stage} ${service}"
@if [ -z "${stage}" ] && [ -z "${service}" ]; then \
Expand All @@ -46,6 +52,7 @@ docker.build:
$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/${stage}.yml build ${service} ${args}; \
fi

.PHONY: docker.log
docker.log:
@echo $(MESSAGE) "Building environment: ${stage} ${service}"
@if [ -z "${stage}" ] && [ -z "${service}" ]; then \
Expand Down
19 changes: 12 additions & 7 deletions provision/make/git.mk
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
# git
## Show commands help git
.PHONY: git.help


git.help:
@echo ' git:'
@echo ''
@echo ' git show help'
@echo ' git.setup install dependences to application'
@echo ' git.ignore install dependences to application'
@echo ' git.reviews add revieweers to git config'
@echo ' git.setup install dependences to application'
@echo ' git.ignore ignore dependences to application'
@echo ' git.reviews add revieweers to git config'
@echo ''

## Show commands git
.PHONY: git
git:
@if [ -z "${command}" ]; then \
make git.help;\
fi


# setup all actions git ignore.
## Setup all actions git ignore.
.PHONY: git.setup
git.setup:
@echo "==> setup git..."
make git.ignore
make git.reviews

## Generate git ignore of files.
.PHONY: git.ignore
git.ignore:
@echo "==> git ignore generated..."
@$(GI) ${GIT_IGNORES} > .gitignore
@for ignore in ${GIT_IGNORES_CUSTOM} ; do \
echo "$${ignore}" >> .gitignore ; \
done
@echo ${MESSAGE_HAPPY}

## Add reviewers to git config.
.PHONY: git.reviews
git.reviews:
@echo "==> add issues revievers..."
Expand Down
19 changes: 10 additions & 9 deletions provision/make/python.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# python
# python show help commands.
.PHONY: python.help


python.help:
@echo ' python:'
@echo ''
Expand All @@ -13,37 +11,40 @@ python.help:
@echo ' python.setup install dependences to application'
@echo ''

## Show commands python
.PHONY: python
python:
@if [ -z "${command}" ]; then \
make python.help;\
fi


## Run linter
.PHONY: python.lint
python.lint: ## Run linter
python.lint:
@echo "==> lint python..."
@echo ${MESSAGE_HAPPY}

## Fix lint violations
.PHONY: python.fix
python.fix: ## Fix lint violations
python.fix:
@echo "==> fix python..."
@echo ${MESSAGE_HAPPY}

# setup download and install dependence.
## setup download and install dependence.
.PHONY: python.setup
python.setup:
@echo "==> setup python..."
$(PIPENV_INSTALL) --dev --skip-lock
@echo ${MESSAGE_HAPPY}

# environment make for python.
## environment make for python.
.PHONY: python.environment
python.environment:
@echo "==> environment python..."
pipenv --venv || $(PIPENV_INSTALL) --skip-lock
@echo ${MESSAGE_HAPPY}

# python pre-commit make for python.
## python pre-commit make for python.
.PHONY: python.precommit
python.precommit:
@echo "==> install hooks for pre-commit..."
Expand Down
38 changes: 27 additions & 11 deletions provision/make/yarn.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#
# See ./docs/contributing.md
#

## show commands help.
.PHONY: yarn.help
yarn.help:
@echo ' yarn:'
@echo ''
Expand All @@ -13,43 +16,56 @@ yarn.help:
@echo ' yarn.build build or with stage=(prod)'
@echo ''

# setup download and install dependence.
## Show commands yarn.
.PHONY: yarn
yarn:
@if [ -z "${command}" ]; then \
make yarn.help;\
fi
@if [ -n "${command}" ]; then \
mkdir -p public;\
$(docker-yarn-run) yarn ${command};\
fi

## Setup download and install dependence.
.PHONY: yarn.setup
yarn.setup:
@echo "==> setup dependence yarn..."
yarn install
@echo ${MESSAGE_HAPPY}

## Setup environment nvm version node.
.PHONY: yarn.environment
yarn.environment:
@echo "==> enviroment yarn..."
@echo "==> environment yarn..."
nvm use ${NODE_VERSION}
@echo ${MESSAGE_HAPPY}

## Install dependences in docker.
.PHONY: yarn.install
yarn.install:
$(docker-yarn-run) yarn install

## Start yarn docker package.
.PHONY: yarn.start
yarn.start:
$(docker-yarn-run) yarn start

## Build yarn docker package.
.PHONY: yarn.build
yarn.build:
@if [ -z "${stage}" ]; then \
$(docker-yarn-run) yarn build; \
else \
$(docker-yarn-run) yarn build:${stage}; \
fi

## Run yarn dev docker.
.PHONY: yarn.dev
yarn.dev:
$(docker-yarn-run) yarn dev

## Run yarn export with docker.
.PHONY: yarn.export
yarn.export:
$(docker-yarn-run) yarn export

yarn:
@if [ -z "${command}" ]; then \
make yarn.help;\
fi
@if [ -n "${command}" ]; then \
mkdir -p public;\
$(docker-yarn-run) yarn ${command};\
fi

0 comments on commit 43831c4

Please sign in to comment.