-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMakefile
More file actions
74 lines (60 loc) · 2.12 KB
/
Makefile
File metadata and controls
74 lines (60 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
export COMPOSE_IGNORE_ORPHANS ?= true
export RUBY_VERSION ?= 2.3.1
RUBY_VERSION_MAJOR = $(word 1,$(subst ., ,$(RUBY_VERSION)))
RUBY_VERSION_MINOR = $(word 2,$(subst ., ,$(RUBY_VERSION)))
export BUNDLER_VERSION ?=
ifeq ($(BUNDLER_VERSION),)
ifeq ($(RUBY_VERSION_MAJOR),2)
# Use old bundler for Ruby 2.3-2.6; Ruby 2.7 needs bundler 2.x to avoid resolver bugs
ifeq ($(RUBY_VERSION_MINOR),7)
export BUNDLER_VERSION = 2.4.22
else
export BUNDLER_VERSION = 1.17.3
endif
endif
endif
PROJECT_NAME = $(shell ls *.gemspec | sed 's/\.gemspec//')
export COMPOSE_PROJECT_NAME ?= $(PROJECT_NAME)-$(subst .,_,$(RUBY_VERSION))
default: help
## Show this help message
help:
@echo "\n\033[1;34mAvailable targets:\033[0m\n"
@awk 'BEGIN {FS = ":"; prev = ""} \
/^## / {prev = substr($$0, 4); next} \
/^[a-zA-Z_-]+:/ {if (prev != "") printf " \033[1;36m%-20s\033[0m %s\n", $$1, prev; prev = ""} \
{prev = ""}' $(MAKEFILE_LIST) | sort
@echo
BUILD_ARGS ?=
## Build and pull docker compose images
build: gemfile-lock
docker compose build --pull $(BUILD_ARGS)
## Create a Gemfile.lock specific to the container (i.e., for the ruby version)
gemfile-lock:
mkdir -pv ./docker/ruby-$(RUBY_VERSION)/ && \
echo '' > ./docker/ruby-$(RUBY_VERSION)/Gemfile.lock
## Open shell in a docker container, supports CMD=
bash: build
$(MAKE) run CMD=bash
CMD ?= bash
## Run command in a docker container, supports CMD=
run:
docker compose run --rm runner $(CMD)
## Run tests in a docker container, supports ARGS=
test: build
$(MAKE) test-direct ARGS="$(ARGS)"
## Run tests in a docker container without building, supports ARGS=
test-direct:
$(MAKE) run CMD="bundle exec rspec $(ARGS)"
## Run rubocop in a docker container, supports ARGS=
lint: build
$(MAKE) lint-direct ARGS="$(ARGS)"
## Run rubocop in a docker container without building, supports ARGS=
lint-direct:
$(MAKE) run CMD="bundle exec rake rubocop $(ARGS)"
## Clean up docker compose resources
clean: clean-gemfile-lock
docker compose down --remove-orphans --volumes
## Clean up the container specific Gemfile.lock
clean-gemfile-lock:
rm -v ./docker/ruby-$(RUBY_VERSION)/Gemfile.lock ||:
.PHONY: build bash test