Skip to content

Instantly share code, notes, and snippets.

@vokshirg
Forked from hulous/Makefile
Created May 12, 2022 13:27
Show Gist options
  • Save vokshirg/fc01d1c9630776e74797e83d1a116e8d to your computer and use it in GitHub Desktop.
Save vokshirg/fc01d1c9630776e74797e83d1a116e8d to your computer and use it in GitHub Desktop.
Rails app Docker and docker-compose command abstraction
APPLICATION_NAME = scubadiveslog # main app name or workdir defined in Dockerfile
WEB_CONTAINER_NAME = scuba-web # web container as defined in docker-compose
.DEFAULT_GOAL := help
# Docker stuff
attach: ## Attach running web container to see logs
docker attach $(APPLICATION_NAME)_$(WEB_CONTAINER_NAME)_1
up: ## Run containers
docker-compose up -d
down: ## Stop containers
docker-compose down
serve: ## Run Serve
- make up
- make attach
ps: ## List containers
docker-compose ps
restart_web: ## Restart Web container
docker-compose restart $(WEB_CONTAINER_NAME)
# Build containers
build: ## Build containers
docker-compose build
rebuild: ## Stop containers, delete docker images not used and build container
- make down
- docker system prune -a
- make build
# Rails install tools
bundle: ## Run bundle install
docker-compose run --rm $(WEB_CONTAINER_NAME) bundle install
migrate: ## Run rake db migrate
docker-compose run --rm $(WEB_CONTAINER_NAME) bundle exec rake db:migrate
# Devs console
bash: ## Run bash in web-container
docker-compose run --rm $(WEB_CONTAINER_NAME) bash
console: ## Run Rails console
docker-compose run --rm $(WEB_CONTAINER_NAME) bundle exec rails c
# Code smells tools
guard: ## Run project guard (in running container)
- make up
- docker-compose exec $(WEB_CONTAINER_NAME) bundle exec guard
sniff: ## Run code smelling tools (rubocop only for now)
docker-compose run --rm $(WEB_CONTAINER_NAME) bundle exec rubocop .
tests: ## Run test locally in web container (with failfast and code coverage option)
docker-compose run -e FAILFAST=true -e COVERAGE=true --rm $(WEB_CONTAINER_NAME) bundle exec rspec .
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment