From 6e8392174cce41ba6762fff1117d1ca49ba5292a Mon Sep 17 00:00:00 2001 From: jmeridth Date: Thu, 22 Feb 2024 12:20:43 -0600 Subject: [PATCH] chore: setup local development - [x] Makefile - [x] docker-compose.yml - [x] update README.md Signed-off-by: jmeridth --- Makefile | 60 ++++++++++++++++++++++++++++++++++++++++++++++ README.md | 14 +++++++++++ docker-compose.yml | 13 ++++++++++ 3 files changed, 87 insertions(+) create mode 100644 Makefile create mode 100644 docker-compose.yml diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3e5ab01 --- /dev/null +++ b/Makefile @@ -0,0 +1,60 @@ +# -e says exit immediately when a command fails +# -o sets pipefail, meaning if it exits with a failing command, the exit code should be of the failing command +# -u fails a bash script immediately if a variable is unset +ENVIRONMENT := test +PGHOST := localhost +PGPORT := 5432 +PGUSER := myuser +PGPASSWORD := mypassword +SHELL = /bin/bash -eu -o pipefail + +define is_installed +if ! command -v $(1) &> /dev/null; \ +then \ + echo "$(1) not installed, please install it. 'brew install $(1)'"; \ + exit; \ +fi; +endef + +.PHONY : help +help : # Display help + @awk -F ':|##' \ + '/^[^\t].+?:.*?##/ {\ + printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF \ + }' $(MAKEFILE_LIST) + +.PHONY : ruby_installed +ruby_installed: ## check if ruby is installed + @$(call is_installed,ruby) + +.PHONY : bundle +bundle: ruby_installed ## install gems + @bundle install --gemfile spec/Gemfile && cd spec/dummy && bundle install + +.PHONY : setup_db +setup_db: ruby_installed postgres ## setup database + @echo "setting up database" + @cd spec/dummy && bundle exec rake db:create db:migrate --trace RAILS_ENV=${ENVIRONMENT} + +.PHONY : initialize_profiling +initialize_profiling: ruby_installed ## initialize rspec_profiling + @echo "initializing rspec_profiling" + @cd spec/dummy && bundle exec rake rspec_profiling:install RAILS_ENV=${ENVIRONMENT} + +.PHONY : spec +spec : bundle setup_db initialize_profiling ## run specs + @echo "running specs" + @bundle exec --gemfile=spec/dummy/Gemfile rspec + +.PHONY : test +test: spec ## run specs + @echo "running specs" + +.PHONY : docker_installed +docker_installed: ## check if docker and docker-compose are installed + @$(call is_installed,docker) + @$(call is_installed,docker-compose) + +.PHONY : postgres +postgres: docker_installed ## start postgres in docker container + @docker-compose up -d || true diff --git a/README.md b/README.md index 6e66f47..7bcacd7 100644 --- a/README.md +++ b/README.md @@ -218,3 +218,17 @@ To remove the results database, run `bundle exec rake rspec_profiling:uninstall` ## Contributing Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. + +## Local Development + +Local tools needed: + +- docker +- docker-compose +- ruby + +To run the specs: + +```bash +make spec +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d73d232 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.9' + +services: + postgres: + image: postgres:16-alpine + ports: + - 5432:5432 + volumes: + - ~/apps/postgres:/var/lib/postgresql/data + environment: + - POSTGRES_HOST=localhost + - POSTGRES_USER=myuser + - POSTGRES_PASSWORD=mypassword