Skip to content

Commit

Permalink
Added Local dev tasks (#79)
Browse files Browse the repository at this point in the history
* Added Local dev tasks

* Remove trunk

* Added bash completion

* Added chamber

* Redo help pattern

* Address PR comments

* Address PR

* Address PR comment for completion

* Address PR comments

* Address PR comments

* Address PR comments

* Address PR comments

* Remote help cache

* Fix help pattern

* Fix help pattern

* Fix problem with make autocompletion for non build harness
  • Loading branch information
goruha authored Aug 14, 2018
1 parent 0070e43 commit b55356b
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 17 deletions.
18 changes: 12 additions & 6 deletions Makefile.helpers
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ EDITOR ?= vim

SHELL = /bin/bash

DEFAULT_HELP_TARGET ?= help
DEFAULT_HELP_TARGET ?= help/short
HELP_FILTER ?= .*

green = $(shell echo -e '\x1b[32;01m$1\x1b[0m')
yellow = $(shell echo -e '\x1b[33;01m$1\x1b[0m')
Expand All @@ -26,18 +27,23 @@ endef
default:: $(DEFAULT_HELP_TARGET)
@exit 0

.PHONY : help
## This help screen
## Help screen
help:
@$(SELF) help/generate MAKEFILE_LIST="Makefile $(BUILD_HARNESS_PATH)/Makefile.helpers"
@printf "Available targets:\n\n"
@$(SELF) -s help/generate | grep -E "\w($(HELP_FILTER))"

## Display help for all targets
help/all:
@$(SELF) help/generate MAKEFILE_LIST="$(MAKEFILE_LIST)"
@printf "Available targets:\n\n"
@$(SELF) -s help/generate

## This help short screen
help/short:
@printf "Available targets:\n\n"
@$(SELF) help/generate MAKEFILE_LIST="Makefile $(BUILD_HARNESS_PATH)/Makefile.helpers"

# Generate help output from MAKEFILE_LIST
help/generate:
@printf "Available targets:\n\n"
@awk '/^[a-zA-Z\-\_0-9%:\\\/]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
Expand Down
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,37 @@ Here are some real world examples:
Available targets:

aws/install Install aws cli bundle
aws/shell Start a aws-vault shell with access to aws api
bash/lint Lint all bash scripts
chamber/install Install chamber
chamber/shell Start a chamber shell with secrets exported to the environment
codefresh/trigger/webhook Trigger a CodeFresh WebHook
completion/install/bash Install completion script for bash
compose/build Build local dev environment
compose/down Stop local dev environment
compose/monitor Show containers resource usage
compose/monitor/follow Monitor in time containers resource usage
compose/purge Purge local dev environment
compose/rebuild Rebuild custom containers for local dev environment
compose/restart Restart local dev environment
compose/top Show top for containers
compose/up Start local dev environment (daemonized)
docker/build Build docker image
docker/clean Cleanup docker. WARNING!!! IT WILL DELETE ALL UNUSED RESOURCES
docker/clean/containers Cleanup docker containers. WARNING!!! IT WILL DELETE ALL UNUSED CONTAINERS
docker/clean/images Cleanup docker images. WARNING!!! IT WILL DELETE ALL UNUSED IMAGES
docker/clean/images/all Cleanup docker images all. WARNING!!! IT WILL DELETE ALL IMAGES
docker/clean/networks Cleanup docker networks. WARNING!!! IT WILL DELETE ALL UNUSED NETWORKS
docker/clean/volumes Cleanup docker volumes. WARNING!!! IT WILL DELETE ALL UNUSED VOLUMES
docker/login Login into docker hub
docs/copyright-add Add copyright headers to source code
geodesic/deploy Run a Jenkins Job to Deploy $(APP) with $(CANONICAL_TAG)
git/aliases-update Update git aliases
git/export Export git vars
git/show Show vars
git/submodules-update Update submodules
github/download-private-release Download release from github
github/download-public-release Download release from github
git/show Show vars
git/submodules-update Update submodules
go/build Build binary
go/build-all Build binary for all platforms
go/clean Clean compiled binary
Expand All @@ -105,6 +123,7 @@ Available targets:
helm/chart/starter/update Update starter
helm/delete/failed Delete all failed releases in a `NAMESPACE` subject to `FILTER`
helm/delete/namespace Delete all releases in a `NAMEPSACE` as well as the namespace
helmfile/install Install helmfile
helm/install Install helm
helm/repo/add Add $REPO_NAME from $REPO_ENDPOINT
helm/repo/add-current Add helm remote dev repos
Expand All @@ -117,14 +136,14 @@ Available targets:
helm/repo/update Update repo info
helm/serve/index Build index for serve helm charts
helm/toolbox/upsert Install or upgrade helm tiller
helmfile/install Install helmfile
help This help screen
help Help screen
help/all Display help for all targets
help/short This help short screen
jenkins/run-job-with-tag Run a Jenkins Job with $(TAG)
make/lint Lint all makefiles
packages/delete Delete packages
packages/install Install packages
packages/install/% Install package (e.g. helm, helmfile, kubectl)
packages/install Install packages
packages/reinstall Reinstall packages
packages/uninstall/% Uninstall package (e.g. helm, helmfile, kubectl)
readme Alias for readme/build
Expand Down
29 changes: 24 additions & 5 deletions docs/targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,37 @@
Available targets:
aws/install Install aws cli bundle
aws/shell Start a aws-vault shell with access to aws api
bash/lint Lint all bash scripts
chamber/install Install chamber
chamber/shell Start a chamber shell with secrets exported to the environment
codefresh/trigger/webhook Trigger a CodeFresh WebHook
completion/install/bash Install completion script for bash
compose/build Build local dev environment
compose/down Stop local dev environment
compose/monitor Show containers resource usage
compose/monitor/follow Monitor in time containers resource usage
compose/purge Purge local dev environment
compose/rebuild Rebuild custom containers for local dev environment
compose/restart Restart local dev environment
compose/top Show top for containers
compose/up Start local dev environment (daemonized)
docker/build Build docker image
docker/clean Cleanup docker. WARNING!!! IT WILL DELETE ALL UNUSED RESOURCES
docker/clean/containers Cleanup docker containers. WARNING!!! IT WILL DELETE ALL UNUSED CONTAINERS
docker/clean/images Cleanup docker images. WARNING!!! IT WILL DELETE ALL UNUSED IMAGES
docker/clean/images/all Cleanup docker images all. WARNING!!! IT WILL DELETE ALL IMAGES
docker/clean/networks Cleanup docker networks. WARNING!!! IT WILL DELETE ALL UNUSED NETWORKS
docker/clean/volumes Cleanup docker volumes. WARNING!!! IT WILL DELETE ALL UNUSED VOLUMES
docker/login Login into docker hub
docs/copyright-add Add copyright headers to source code
geodesic/deploy Run a Jenkins Job to Deploy $(APP) with $(CANONICAL_TAG)
git/aliases-update Update git aliases
git/export Export git vars
git/show Show vars
git/submodules-update Update submodules
github/download-private-release Download release from github
github/download-public-release Download release from github
git/show Show vars
git/submodules-update Update submodules
go/build Build binary
go/build-all Build binary for all platforms
go/clean Clean compiled binary
Expand All @@ -38,6 +56,7 @@ Available targets:
helm/chart/starter/update Update starter
helm/delete/failed Delete all failed releases in a `NAMESPACE` subject to `FILTER`
helm/delete/namespace Delete all releases in a `NAMEPSACE` as well as the namespace
helmfile/install Install helmfile
helm/install Install helm
helm/repo/add Add $REPO_NAME from $REPO_ENDPOINT
helm/repo/add-current Add helm remote dev repos
Expand All @@ -50,14 +69,14 @@ Available targets:
helm/repo/update Update repo info
helm/serve/index Build index for serve helm charts
helm/toolbox/upsert Install or upgrade helm tiller
helmfile/install Install helmfile
help This help screen
help Help screen
help/all Display help for all targets
help/short This help short screen
jenkins/run-job-with-tag Run a Jenkins Job with $(TAG)
make/lint Lint all makefiles
packages/delete Delete packages
packages/install Install packages
packages/install/% Install package (e.g. helm, helmfile, kubectl)
packages/install Install packages
packages/reinstall Reinstall packages
packages/uninstall/% Uninstall package (e.g. helm, helmfile, kubectl)
readme Alias for readme/build
Expand Down
12 changes: 12 additions & 0 deletions modules/aws/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
export AWSCLI_VERSION ?= 1.11.185

WITH_AWS ?= aws-vault exec $(AWS_PROFILE) --

## Install aws cli bundle
aws/install:
pip install --no-cache-dir --disable-pip-version-check awscli==$(AWSCLI_VERSION)

## Start a aws-vault shell with access to aws api
aws/shell: aws/check-shell
$(call assert-unset,AWS_VAULT)
@$(WITH_AWS) bash --rcfile $(BUILD_HARNESS_PATH)/modules/aws/aws.bash.rc

# Ensure that variables required for aws-vault are set
aws/check-shell:
$(call assert-set,AWS_PROFILE)



4 changes: 4 additions & 0 deletions modules/aws/aws.bash.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if [ -f ~/.bashrc ] ; then
source ~/.bashrc
fi
PS1=${PS1}"(aws[${AWS_VAULT}] mode)$ "
15 changes: 15 additions & 0 deletions modules/chamber/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@ CURL ?= curl
CHAMBER_VERSION ?= 2.0.0
CHAMBER ?= chamber

ifdef AWS_VAULT
CHAMBER_AUTH = ""
else
CHAMBER_AUTH = $(WITH_AWS)
endif

WITH_CHAMBER = $(CHAMBER_AUTH) chamber exec $(CHAMBER_SERVICES) --

## Install chamber
chamber/install: packages/install/chamber
@exit 0

## Start a chamber shell with secrets exported to the environment
chamber/shell: chamber/check-shell
$(call assert-unset,IN_CHAMBER_MODE)
$(WITH_CHAMBER) bash --rcfile $(BUILD_HARNESS_PATH)/modules/chamber/chamber.bash.rc

# Ensure that variables required for chamber are set
chamber/check-shell: aws/check-shell
$(call assert-set,CHAMBER_SERVICES)
6 changes: 6 additions & 0 deletions modules/chamber/chamber.bash.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if [ -f ~/.bashrc ] ; then
source ~/.bashrc
fi

PS1=${PS1}"(aws[${AWS_VAULT}] chamber[${CHAMBER_SERVICES}] mode)$ "
export IN_CHAMBER_MODE=true
12 changes: 12 additions & 0 deletions modules/completion/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Flag used to indicate if bash completion rules for make have already been installed
BASH_COMPLETION_FLAG ?= ~/.make.bash.completion

# Target to generate tab completion rules for bash
completion/bash:
@$(SELF) -s $(DEFAULT_HELP_TARGET) | cut -d ' ' -f3 | sed 's/\x1b\[[0-9;]*m//g'

## Install completion script for bash
completion/install/bash:
@[ -f $(BASH_COMPLETION_FLAG) ] || echo "complete -W \"\\\`[[ -f Makefile && -f .build-harness ]] && make completion/bash \\\`\" make" >> ~/.bashrc
@touch $(BASH_COMPLETION_FLAG)
@echo "Complete installed to .bashrc"
39 changes: 39 additions & 0 deletions modules/compose/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
DOCKER_NETWORK ?= $(COMPOSE_PROJECT_NAME)_default

DOCKER_MONITOR_TABLE ?= 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}'

DOCKER_COMPOSE ?= docker-compose

## Start local dev environment (daemonized)
compose/up:
@$(DOCKER_COMPOSE) up -d

## Stop local dev environment
compose/down:
@$(DOCKER_COMPOSE) down

## Restart local dev environment
compose/restart: compose/down compose/up

## Purge local dev environment
compose/purge:
@$(DOCKER_COMPOSE) down -v

## Rebuild custom containers for local dev environment
compose/rebuild: compose/down compose/build compose/up

## Build local dev environment
compose/build:
@$(DOCKER_COMPOSE) build

## Show containers resource usage
compose/monitor:
@$(DOCKER_COMPOSE) ps -q | tr '\n' ' ' | docker stats --format $(DOCKER_MONITOR_TABLE) --no-stream

## Monitor in time containers resource usage
compose/monitor/follow:
@$(DOCKER_COMPOSE) ps -q | tr '\n' ' ' | docker stats --format $(DOCKER_MONITOR_TABLE)

## Show top for containers
compose/top:
@$(DOCKER_COMPOSE) top
12 changes: 11 additions & 1 deletion modules/docker/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
DOCKER:= $(shell which docker)
DOCKER = $(shell which docker)

DOCKER_RUN ?= docker run -i --rm --network=$(DOCKER_NETWORK)
DOCKER_EXEC ?= $(DOCKER) exec -it
CONTAINER_SHELL ?= sh

# It's like ssh for docker
define docker-exec
@[ -n "$1" ] || (echo "Specify container name in $(@)"; exit 1)
@$(DOCKER_EXEC) $1 $2
endef
39 changes: 39 additions & 0 deletions modules/docker/Makefile.cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## Cleanup docker volumes. WARNING!!! IT WILL DELETE ALL UNUSED VOLUMES
docker/clean/volumes:
@echo "Cleanup volumes"
@docker volume prune
@echo "Done"

## Cleanup docker networks. WARNING!!! IT WILL DELETE ALL UNUSED NETWORKS
docker/clean/networks:
@echo "Cleanup networks"
@docker network prune
@echo "Done"

## Cleanup docker images. WARNING!!! IT WILL DELETE ALL UNUSED IMAGES
docker/clean/images:
@echo "Cleanup images"
@docker images prune
@echo "Done"

## Cleanup docker images all. WARNING!!! IT WILL DELETE ALL IMAGES
docker/clean/images/all:
@echo "Cleanup ALL images"
@docker images -q --no-trunc | xargs -I{} docker rmi {}
@echo "Done"


## Cleanup docker containers. WARNING!!! IT WILL DELETE ALL UNUSED CONTAINERS
docker/clean/containers:
@echo "Cleanup containers"
@docker container prune
@echo "Done"

## Cleanup docker. WARNING!!! IT WILL DELETE ALL UNUSED RESOURCES
docker/clean:
@echo "---Cleanup docker---"
@make -s docker/clean/containers || true
@make -s docker/clean/images || true
@make -s docker/clean/volumes || true
@make -s docker/clean/networks || true
@echo "---Done---"

0 comments on commit b55356b

Please sign in to comment.