Skip to content

Commit

Permalink
Adds help target to repo and some initial documentation for makefile …
Browse files Browse the repository at this point in the history
…targets (#4385)
  • Loading branch information
karlbrown-va authored Jun 15, 2020
1 parent ef48440 commit 7fa0186
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
42 changes: 24 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@ DB := "bin/rails db:setup db:migrate"
LINT := "bin/rails lint"
DOWN := down
SECURITY := "bin/rails security"
.DEFAULT_GOAL := ci

.PHONY: default
default: ci

# cribbed from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html and https://news.ycombinator.com/item?id=11195539
help: ## Prints out documentation for available commands
@awk -F ':|##' \
'/^[^\t].+?:.*?##/ {\
printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF \
}' $(MAKEFILE_LIST)

.PHONY: ci
ci:
ci: ## Sets up databases and runs tests for ci
@$(BASH_TEST) "bin/rails db:setup db:migrate ci"

.PHONY: bash
bash:
bash: ## Starts a bash shell inside the docker container
@$(COMPOSE_DEV) $(BASH)

.PHONY: build
build:
build: ## Builds the api
ifeq ($(ENV_ARG), dev)
$(COMPOSE_DEV) build
else
Expand All @@ -39,7 +45,7 @@ endif


.PHONY: db
db:
db: ## Sets up database and runs migrations
ifeq ($(ENV_ARG), dev)
@$(BASH_DEV) $(DB)
else
Expand All @@ -48,65 +54,65 @@ endif


.PHONY: lint
lint:
lint: ## runs the linter
ifeq ($(ENV_ARG), dev)
@$(BASH_DEV) $(LINT)
else
@$(BASH_TEST) $(LINT)
endif

.PHONY: console
console:
console: ## Starts a rails console
@$(BASH_DEV) "bundle exec rails c"

.PHONY: danger
danger:
danger: ## Runs the danger static analysis
@$(BASH_TEST) "bundle exec danger --verbose"

.PHONY: docker-clean
docker-clean:
docker-clean: ## Removes all docker images and volumes associated with vets-api
@$(COMPOSE_DEV) down --rmi all --volumes

.PHONY: down
down:
down: ## Stops all docker services
ifeq ($(ENV_ARG), dev)
@$(COMPOSE_DEV) $(DOWN)
else
@$(COMPOSE_TEST) $(DOWN)
endif

.PHONY: guard
guard:
guard: ## Runs guard
@$(BASH_DEV) "bundle exec guard"

.PHONY: migrate
migrate:
migrate: ## Runs the database migrations
@$(BASH_DEV) "bin/rails db:migrate"

.PHONY: rebuild
rebuild: down
rebuild: down ## Stops the docker services and builds the api
@$(COMPOSE_DEV) build

.PHONY: security
security:
security: ## Runs security scans
ifeq ($(ENV_ARG), dev)
@$(BASH_DEV) $(SECURITY)
else
@$(BASH_TEST) $(SECURITY)
endif

.PHONY: server
server:
server: ## Starts the server (natively)
@$(BASH_DEV) "rm -f tmp/pids/server.pid && bundle exec rails server"

.PHONY: spec
spec:
spec: ## Runs spec tests
ifeq ($(ENV_ARG), dev)
@$(BASH_DEV) "bin/rspec ${SPEC_PATH}"
else
@$(BASH_TEST) "bin/rails spec:with_codeclimate_coverage"
endif

.PHONY: up
up: db
up: db ## Starts the server and associated services with docker-compose
@$(BASH_DEV) "rm -f tmp/pids/server.pid && foreman start -m all=1,clamd=0,freshclam=0"
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ To start, fetch this code:

## Running the app

A Makefile provides shortcuts for interacting with the docker images. To run vets-api and its redis and postgres
dependencies run the following command from within the repo you cloned in the above steps.
A Makefile provides shortcuts for interacting with the docker images.

You can see all of the targets and an explanation of what they do with:

```
make help
```

To run vets-api and its redis and postgres dependencies run the following command from within the repo you cloned
in the above steps.

```
make up
Expand Down

0 comments on commit 7fa0186

Please sign in to comment.