Skip to content

Commit

Permalink
chore: implement actions for make (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
luismayta committed Jan 27, 2021
1 parent 923c15f commit 89f9dd0
Show file tree
Hide file tree
Showing 8 changed files with 385 additions and 0 deletions.
101 changes: 101 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#
# See ./docs/contributing.md
#

OS := $(shell uname)

.PHONY: help
.DEFAULT_GOAL := help

HAS_PIP := $(shell command -v pip;)
HAS_PIPENV := $(shell command -v pipenv;)

ifdef HAS_PIPENV
PIPENV_RUN:=pipenv run
PIPENV_INSTALL:=pipenv install
else
PIPENV_RUN:=
PIPENV_INSTALL:=
endif

TEAM := hadenlabs
REPOSITORY_DOMAIN:=github.com
REPOSITORY_OWNER:=${TEAM}
AWS_VAULT ?= ${TEAM}
PROJECT := zsh-goenv
PROJECT_PORT := 3000

PYTHON_VERSION=3.8.0
NODE_VERSION=12.14.1
PYENV_NAME="${PROJECT}"

# Configuration.
SHELL ?=/bin/bash
ROOT_DIR=$(shell pwd)
MESSAGE:=🍺️
MESSAGE_HAPPY:="Done! ${MESSAGE}, Now Happy Hacking"
SOURCE_DIR=$(ROOT_DIR)
PROVISION_DIR:=$(ROOT_DIR)/provision
DOCS_DIR:=$(ROOT_DIR)/docs
FILE_README:=$(ROOT_DIR)/README.md

PATH_DOCKER_COMPOSE:=docker-compose.yml -f provision/docker-compose

DOCKER_SERVICE_DEV:=app
DOCKER_SERVICE_TEST:=app

docker-compose:=$(PIPENV_RUN) docker-compose

docker-test:=$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/test.yml
docker-dev:=$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/dev.yml

docker-test-run:=$(docker-test) run --rm ${DOCKER_SERVICE_TEST}
docker-dev-run:=$(docker-dev) run --rm --service-ports ${DOCKER_SERVICE_DEV}
docker-yarn-run:=$(docker-dev) run --rm --service-ports ${DOCKER_SERVICE_YARN}

include provision/make/*.mk

help:
@echo '${MESSAGE} Makefile for ${PROJECT}'
@echo ''
@echo 'Usage:'
@echo ' environment create environment with pyenv'
@echo ' setup install requirements'
@echo ''
@make docker.help
@make docs.help
@make test.help
@make utils.help
@make python.help
@make yarn.help

setup:
@echo "=====> install packages..."
make python.setup
make python.precommit
@cp -rf provision/git/hooks/prepare-commit-msg .git/hooks/
@[ -e ".env" ] || cp -rf .env.example .env
make yarn.setup
@echo ${MESSAGE_HAPPY}

environment:
@echo "=====> loading virtualenv ${PYENV_NAME}..."
make python.environment
@echo ${MESSAGE_HAPPY}

.PHONY: clean
clean:
@rm -f ./dist.zip
@rm -fr ./vendor

# Show to-do items per file.
todo:
@grep \
--exclude-dir=vendor \
--exclude-dir=node_modules \
--exclude-dir=bin \
--exclude=Makefile \
--text \
--color \
-nRo -E ' TODO:.*|SkipNow|FIXMEE:.*' .
.PHONY: todo
11 changes: 11 additions & 0 deletions provision/make/alias.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# alias

alias: alias.help

alias.help:
@echo ' Alias:'
@echo ''
@echo ' stage stage'
@echo ''

stage: stage
105 changes: 105 additions & 0 deletions provision/make/docker.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Docker
.PHONY: docker.help
DOCKER_NETWORK = $(PROJECT)_network

docker: docker.help

docker.help:
@echo ' Docker:'
@echo ''
@echo ' docker.build build all or one example: make docker.build service={services} args=(--pull|...)'
@echo ' docker.down down services docker-compose'
@echo ' docker.exec exec command in container by {services} {command}'
@echo ' docker.ssh connect by ssh to container'
@echo ' docker.stop stop services by stage'
@echo ' docker.log log {service} {stage}'
@echo ' docker.verify_network verify network'
@echo ' docker.up up services of docker-compose'
@echo ' docker.run run {service} {stage}'
@echo ' docker.restart restart by {stage}'
@echo ' docker.list list services of docker'
@echo ''

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

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

docker.build:
@echo $(MESSAGE) "Building stage: ${stage} ${service}"
@if [ -z "${stage}" ] && [ -z "${service}" ]; then \
$(docker-dev) build ${args}; \
elif [ -z "${stage}" ] && [ -n "${service}" ]; then \
$(docker-dev) build ${service} ${args}; \
elif [ -n "${stage}" ] && [ -z "${service}" ]; then \
$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/${stage}.yml build ${args}; \
elif [ -n "${stage}" ] && [ -n "${service}" ]; then \
$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/${stage}.yml build ${service} ${args}; \
fi

docker.log:
@echo $(MESSAGE) "Building environment: ${stage} ${service}"
@if [ -z "${stage}" ] && [ -z "${service}" ]; then \
$(docker-dev) logs -f ; \
elif [ -z "${stage}" ] && [ -n "${service}" ]; then \
$(docker-dev) logs -f ${service}; \
elif [ -n "${stage}" ] && [ -z "${service}" ]; then \
$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/${stage}.yml logs -f; \
elif [ -n "${stage}" ] && [ -n "${service}" ]; then \
$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/${stage}.yml logs -f ${service} ; \
fi

docker.down:
@echo $(MESSAGE) "Down Services Stage: ${stage}"
@if [ -z "${stage}" ]; then \
$(docker-dev) down --remove-orphans; \
$(docker-test) down --remove-orphans; \
else \
$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/${stage}.yml down --remove-orphans; \
fi

docker.exec:
@echo $(MESSAGE) "Exec Services Stage: ${stage}"
@if [ -z "${stage}" ]; then \
$(docker-dev) exec ${service} ${command} ; \
else \
$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/${stage}.yml exec ${service} ${command} ; \
fi

docker.stop:
@echo $(MESSAGE) "Stop Services: ${stage}"
@if [ "${stage}" == "" ]; then \
$(docker-dev) stop; \
else \
$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/${stage}.yml stop; \
fi

docker.verify_network: ## Verify network
@if [ -z $$(docker network ls | grep $(DOCKER_NETWORK) | awk '{print $$2}') ]; then\
(docker network create $(DOCKER_NETWORK));\
fi

docker.up:
@echo $(MESSAGE) "Up Services: ${stage}"
@if [ -z "${stage}" ]; then \
$(docker-dev) up --remove-orphans; \
else \
$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/${stage}.yml up --remove-orphans; \
fi

docker.list:
@echo $(MESSAGE) "List Services: ${stage}"
@if [ -z "${stage}" ]; then \
$(docker-dev) ps; \
else \
$(docker-compose) -f ${PATH_DOCKER_COMPOSE}/${stage}.yml ps; \
fi
20 changes: 20 additions & 0 deletions provision/make/docs.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# See ./docs/contributing.md
#

docs:
make docs.help

docs.help:
@echo ' Docs:'
@echo ''
@echo ' docs.build Show mkdocs'
@echo ' docs.serve server Make documentation'
@echo ''


docs.build:
$(PIPENV_RUN) mkdocs build

docs.serve:
$(PIPENV_RUN) mkdocs serve
52 changes: 52 additions & 0 deletions provision/make/python.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# python
.PHONY: python.help


python.help:
@echo ' python:'
@echo ''
@echo ' python show help'
@echo ' python.environment make environment for python'
@echo ' python.lint lint python'
@echo ' python.fix fix code'
@echo ' python.precommit precommit install hooks'
@echo ' python.setup install dependences to application'
@echo ''

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


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

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

# 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.
.PHONY: python.environment
python.environment:
@echo "=====> environment python..."
pipenv --venv || $(PIPENV_INSTALL) --python=${PYTHON_VERSION} --skip-lock
@echo ${MESSAGE_HAPPY}

# python pre-commit make for python.
.PHONY: python.precommit
python.precommit:
@echo "=====> install hooks for pre-commit..."
$(PIPENV_RUN) pre-commit install
$(PIPENV_RUN) pre-commit install -t pre-push
@echo ${MESSAGE_HAPPY}
20 changes: 20 additions & 0 deletions provision/make/tests.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
test.help:
@echo ' Tests:'
@echo ''
@echo ' test show help'
@echo ' test.all Run all module test'
@echo ' test.lint Run all pre-commit'
@echo ''

test:
@echo $(MESSAGE) Running tests on the current Python interpreter with coverage $(END)
@if [ -z "${run}" ]; then \
make test.help;\
fi

test.all:
@echo $(MESSAGE) Running tests on the current Python interpreter with coverage $(END)
$(docker-test-run) bash -c "zunit --verbose"

test.lint:
$(PIPENV_RUN) pre-commit run --all-files --verbose
27 changes: 27 additions & 0 deletions provision/make/utils.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# See ./docs/contributing.md
#
.PHONY: utils.help

utils.help:
@echo ' utils:'
@echo ''
@echo ' utils help utils'
@echo ' utils.generate generate key ssh by stage'
@echo ''

utils:
make utils.help

utils.generate:
mkdir -p ${KEYBASE_PROJECT_PATH}/${stage}/{pem,pub,private,openssl}
mkdir -p ${KEYBASE_PROJECT_PATH}/${stage}/pub
mkdir -p ${KEYBASE_PROJECT_PATH}/${stage}/private
mkdir -p ${KEYBASE_PROJECT_PATH}/${stage}/openssl

ssh-keygen -q -m PEM -t rsa -b 4096 -C "admin@${PROJECT}-${stage}.com" -f ${PROJECT}-${stage} -P ""
openssl rsa -in ${PROJECT}-${stage} -outform pem > ${PROJECT}-${stage}.pem
chmod 0600 ${PROJECT}-${stage}.pem
cp -rf ${PROJECT}-${stage}.pem ${KEYBASE_PROJECT_PATH}/${stage}/pem/
cp -rf ${PROJECT}-${stage}.pub ${KEYBASE_PROJECT_PATH}/${stage}/pub/
cp -rf ${PROJECT}-${stage} ${KEYBASE_PROJECT_PATH}/${stage}/private/
49 changes: 49 additions & 0 deletions provision/make/yarn.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# See ./docs/contributing.md
#
yarn.help:
@echo ' yarn:'
@echo ''
@echo ' yarn command=(build|dev|start|export)'
@echo ' yarn.setup Install dependences of project'
@echo ' yarn.install Install dependences'
@echo ' yarn.dev dev project'
@echo ' yarn.start run project'
@echo ' yarn.export export project'
@echo ' yarn.build build or with stage=(prod)'
@echo ''

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

yarn.install:
$(docker-yarn-run) yarn install

yarn.start:
$(docker-yarn-run) yarn start

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

yarn.dev:
$(docker-yarn-run) yarn dev

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 89f9dd0

Please sign in to comment.