Skip to content

Commit

Permalink
!#5 Fix: settings script of makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
luismayta committed Sep 3, 2017
1 parent c05de8b commit b3cafff
Show file tree
Hide file tree
Showing 16 changed files with 388 additions and 99 deletions.
109 changes: 73 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,66 +1,103 @@
# Makefile for slides-docker4devs.
.PHONY: build deploy lint test functions help
.DEFAULT_GOAL := help

DOCKER_NETWORK = slides-docker4devs_network
PROYECT_NAME = slides-docker4devs

# Configuration.
SHELL = /bin/bash
ROOT_DIR = $(shell pwd)
BIN_DIR = $(ROOT_DIR)/bin
DATA_DIR = $(ROOT_DIR)/var
MESSAGE="༼ つ ◕_◕ ༽つ"
MESSAGE_HAPPY="${MESSAGE} Happy Coding"
SCRIPT_DIR = $(ROOT_DIR)/script

WGET = wget

# Bin scripts
BUILD = $(shell) $(SCRIPT_DIR)/build.sh
CLEAN = $(shell) $(SCRIPT_DIR)/clean.sh
GVM = $(shell) $(SCRIPT_DIR)/gvm.sh
GRIP = $(shell) $(SCRIPT_DIR)/grip.sh
INSTALL = $(shell) $(SCRIPT_DIR)/install.sh
DOCUMENTATION = $(shell) $(SCRIPT_DIR)/documentation.sh
DOWN = $(shell) $(SCRIPT_DIR)/down.sh
PYENV = $(shell) $(SCRIPT_DIR)/pyenv.sh
INSTALL = $(shell) $(SCRIPT_DIR)/install.sh
LINTCODE = $(shell) $(SCRIPT_DIR)/lintcode.sh
LIST = $(shell) $(SCRIPT_DIR)/list.sh
LINT = $(shell) $(SCRIPT_DIR)/lint.sh
TEST = $(shell) $(SCRIPT_DIR)/test.sh
WATCH = $(shell) $(SCRIPT_DIR)/watch.sh
GENERATE = $(shell) $(SCRIPT_DIR)/generate.sh

clean:
$(CLEAN)
STOP = $(shell) $(SCRIPT_DIR)/stop.sh
SETUP = $(shell) $(SCRIPT_DIR)/setup.sh
UP = $(shell) $(SCRIPT_DIR)/up.sh

build: ## Build docker container by env
make clean
@echo $(MESSAGE) "Building environment: ${env}"
$(BUILD) "${env}" && echo $(MESSAGE_HAPPY)

distclean: clean
rm -rf $(ROOT_DIR)/lib
rm -rf $(ROOT_DIR)/*.egg-info
rm -rf $(ROOT_DIR)/demo/*.egg-info
clean: ## clean Files compiled
$(CLEAN)


environment:
environment: ## Make environment for developer
$(PYENV)
$(GVM)
$(INSTALL)


grip:
$(GRIP)
documentation: ## Make Documentation
make clean
$(DOCUMENTATION)

down: ## remove containers docker by env
make clean
@echo $(MESSAGE) "Down Services Environment: ${env}"
$(DOWN) "${env}" && echo $(MESSAGE_HAPPY)

env: ## Show envs available
@echo $(MESSAGE) "Environments:"
@echo "dev"
@echo "test"
@echo "stage"

install:
$(INSTALL)
install: ## Install with var env Dependences
make clean
@echo $(MESSAGE) "Install environment: ${env}"
$(INSTALL) "${env}" && echo $(MESSAGE_HAPPY)

list: ## List of current active services by env
make clean
@echo $(MESSAGE) "List Services: ${env}"
$(LIST) "${env}" && echo $(MESSAGE_HAPPY)

generate:
$(GENERATE)
lint: ## Clean files unnecesary
make clean
$(LINT)

test: ## make test
make clean
$(TEST)

maintainer-clean: distclean
rm -rf $(BIN_DIR)
rm -rf $(ROOT_DIR)/lib/
up: ## Up application by env
make clean
make verify_network &> /dev/null
@echo $(MESSAGE) "Up Application environment: ${env}"
$(UP) "${env}" && echo $(MESSAGE_HAPPY)

restart: ## Reload services
@echo $(MESSAGE) "restart Application environment: ${env}"
docker-compose restart

lintcode:
$(LINTCODE)
ssh: ## Connect to container
docker exec -it $(CONTAINER) bash

stop: ## stop containers docker by env
make clean
@echo $(MESSAGE) "Stop Services: ${env}"
$(STOP) "${env}" && echo $(MESSAGE_HAPPY)

watch:
$(WATCH)
setup: ## Install dependences initial
make clean
$(SETUP)

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

test:
$(TEST)
help: ## Show help text
@echo $(MESSAGE) "Commands"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
33 changes: 15 additions & 18 deletions script/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-

export PROJECT_NAME='slides-docker4devs'
export PYTHON_VERSION=2.7.9
export PYENV_NAME="${PROJECT_NAME}"

export GVM_NAME="${PROJECT_NAME}"
export GVM_PATHS_NAME=(
"src"
"pkg"
"bin"
)
export PROJECT_NAME=slides-docker4devs
export PROJECT_NAME_DEV="${PROJECT_NAME}"-DEV
export PROJECT_NAME_STAGE="${PROJECT_NAME}"-STAGE
export PROJECT_NAME_TEST="${PROJECT_NAME}"-TEST

export GRIP_PORT=6430
export PYTHON_VERSION=3.6.1
export PYENV_NAME="${PROJECT_NAME}"

# Vars Dir
export ROOT_DIR
ROOT_DIR="$(pwd)"
export RESOURCES_DIR="${SOURCE_DIR}/resources"
export RESOURCES_DB_DIR="${RESOURCES_DIR}/db"
export PROVISION_DIR="${ROOT_DIR}/provision/ansible"
export SOURCE_DIR="${ROOT_DIR}"
export ETC_DIR="${SOURCE_DIR}/etc"
export REQUIREMENTS_DIR="${SOURCE_DIR}/requirements"
ROOT_DIR=$(pwd)
export RESOURCES_DIR="$ROOT_DIR/resources"
export RESOURCES_DB_DIR="$RESOURCES_DIR/db"
export PROVISION_DIR="$ROOT_DIR/provision/ansible"
export SOURCE_DIR="${ROOT_DIR}/"
export REQUIREMENTS_DIR="${ROOT_DIR}/requirements/"
export FILE_README="${ROOT_DIR}/README.rst"

export MESSAGE="༼ つ ◕_◕ ༽つ"
19 changes: 19 additions & 0 deletions script/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-

# shellcheck source=/dev/null
[ -r "script/bootstrap.sh" ] && source "script/bootstrap.sh"

cd "${ROOT_DIR}" || echo 'Not Found'

if [ "$1" == "" ]; then
docker-compose build --no-cache
elif [ "$1" == "dev" ]; then
docker-compose -f docker-compose.yml -f docker-compose/dev.yml -p "${PROJECT_NAME_DEV}" build --no-cache
elif [ "$1" == "stage" ]; then
docker-compose -f docker-compose.yml -f docker-compose/stage.yml -p "${PROJECT_NAME_STAGE}" build --no-cache
elif [ "$1" == "test" ]; then
docker-compose -f docker-compose.yml -f docker-compose/test.yml -p "${PROJECT_NAME_TEST}" build --no-cache
elif [ "$1" == "prod" ]; then
docker-compose -p "${PROJECT_NAME}" build --no-cache
fi
15 changes: 12 additions & 3 deletions script/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
# shellcheck source=/dev/null
[ -r "script/bootstrap.sh" ] && source "script/bootstrap.sh"

# Clean

# Code python
{
rm -rf -- **/**/**/*_pycache__
rm -rf -- **/**/**/*.pyc
rm -rf -- **/**/**/*.swp
find . -regex "\(.*__pycache__.*\|*.py[co]\)" -delete
} >> /dev/null 2>&1

# Sphinx
{
rm -rf -- **/**/*__pycache__
rm -rf -- **/**/*.pyc
rm -rf -- **/**/*.swp
rm -rf -- docs/_build/*
} >> /dev/null 2>&1
2 changes: 1 addition & 1 deletion script/grip.sh → script/documentation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# shellcheck source=/dev/null
[ -r "script/bootstrap.sh" ] && source "script/bootstrap.sh"

grip --pass "${GITHUB_API_TOKEN}" "${GRIP_PORT}"
restview "${FILE_README}"
19 changes: 19 additions & 0 deletions script/down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-

# shellcheck source=/dev/null
[ -r "script/bootstrap.sh" ] && source "script/bootstrap.sh"

cd "${ROOT_DIR}" || echo 'Not Found'

if [ "$1" == "" ]; then
docker-compose -p "${PROJECT_NAME}" down --remove-orphans
elif [ "$1" == "dev" ]; then
docker-compose -f docker-compose.yml -f docker-compose/dev.yml -p "${PROJECT_NAME_DEV}" down --remove-orphans
elif [ "$1" == "stage" ]; then
docker-compose -f docker-compose.yml -f docker-compose/stage.yml -p "${PROJECT_NAME_STAGE}" down --remove-orphans
elif [ "$1" == "test" ]; then
docker-compose -f docker-compose.yml -f docker-compose/test.yml -p "${PROJECT_NAME_TEST}" down --remove-orphans
elif [ "$1" == "prod" ]; then
docker-compose -f docker-compose.yml -f docker-compose/prod.yml -p "${PROJECT_NAME}" down --remove-orphans
fi
9 changes: 0 additions & 9 deletions script/generate.sh

This file was deleted.

21 changes: 0 additions & 21 deletions script/gvm.sh

This file was deleted.

13 changes: 11 additions & 2 deletions script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,14 @@
# shellcheck source=/dev/null
[ -r "script/bootstrap.sh" ] && source "script/bootstrap.sh"

pyenv activate "${PYENV_NAME}" >> /dev/null 2>&1 || echo 'Oh Yeah!!'
pip install -r "${REQUIREMENTS_DIR}/dev.txt"
if [ "$1" == "" ]; then
pip install -r requirements.txt
elif [ "$1" == "dev" ]; then
pip install -r "${REQUIREMENTS_DIR}/"dev.txt
elif [ "$1" == "stage" ]; then
pip install -r "${REQUIREMENTS_DIR}/"stage.txt
elif [ "$1" == "test" ]; then
pip install -r "${REQUIREMENTS_DIR}/"test.txt
elif [ "$1" == "prod" ]; then
pip install -r requirements.txt
fi
6 changes: 0 additions & 6 deletions script/linguist.sh

This file was deleted.

4 changes: 1 addition & 3 deletions script/lintcode.sh → script/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@

# shellcheck source=/dev/null
[ -r "script/bootstrap.sh" ] && source "script/bootstrap.sh"

pre-commit install -f --install-hooks
pre-commit run --all-files
pre-commit run --all-files --verbose
19 changes: 19 additions & 0 deletions script/list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-

# shellcheck source=/dev/null
[ -r "script/bootstrap.sh" ] && source "script/bootstrap.sh"

cd "${ROOT_DIR}" || echo 'Not Found'

if [ "$1" == "" ]; then
docker-compose ps
elif [ "$1" == "dev" ]; then
docker-compose -f docker-compose.yml -f docker-compose/dev.yml ps
elif [ "$1" == "stage" ]; then
docker-compose -f docker-compose.yml -f docker-compose/stage.yml ps
elif [ "$1" == "test" ]; then
docker-compose -f docker-compose.yml -f docker-compose/test.yml ps
elif [ "$1" == "prod" ]; then
docker-compose -f docker-compose.yml -f docker-compose/prod.yml ps
fi
3 changes: 3 additions & 0 deletions script/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# shellcheck source=/dev/null
[ -r "script/bootstrap.sh" ] && source "script/bootstrap.sh"

pip install -r "${REQUIREMENTS_DIR}/"setup.txt
pre-commit install
19 changes: 19 additions & 0 deletions script/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-

# shellcheck source=/dev/null
[ -r "script/bootstrap.sh" ] && source "script/bootstrap.sh"

cd "${ROOT_DIR}" || echo 'Not Found'

if [ "$1" == "" ]; then
docker-compose -p "${PROJECT_NAME}" stop
elif [ "$1" == "dev" ]; then
docker-compose -f docker-compose.yml -f docker-compose/dev.yml -p "${PROJECT_NAME_DEV}" stop
elif [ "$1" == "stage" ]; then
docker-compose -f docker-compose.yml -f docker-compose/stage.yml -p "${PROJECT_NAME_STAGE}" stop
elif [ "$1" == "test" ]; then
docker-compose -f docker-compose.yml -f docker-compose/test.yml -p "${PROJECT_NAME_TEST}" stop
elif [ "$1" == "prod" ]; then
docker-compose -f docker-compose.yml -f docker-compose/prod.yml -p "${PROJECT_NAME}" stop
fi
19 changes: 19 additions & 0 deletions script/up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-

# shellcheck source=/dev/null
[ -r "script/bootstrap.sh" ] && source "script/bootstrap.sh"

cd "${ROOT_DIR}" || echo 'Not Found'

if [ "$1" == "" ]; then
docker-compose up --remove-orphans
elif [ "$1" == "dev" ]; then
docker-compose -f docker-compose.yml -f docker-compose/dev.yml -p "${PROJECT_NAME_DEV}" up --remove-orphans
elif [ "$1" == "stage" ]; then
docker-compose -f docker-compose.yml -f docker-compose/stage.yml -p "${PROJECT_NAME_STAGE}" up --remove-orphans
elif [ "$1" == "test" ]; then
docker-compose -f docker-compose.yml -f docker-compose/test.yml -p "${PROJECT_NAME_TEST}" up --remove-orphans
elif [ "$1" == "prod" ]; then
docker-compose -f docker-compose.yml -f docker-compose/prod.yml -p "${PROJECT_NAME}" up --remove-orphans
fi
Loading

0 comments on commit b3cafff

Please sign in to comment.