I want to run my rails rspec test on docker. If I open Cli via docker desktop and write
-bundle exec rspec spec
my tests run. What I want is, to run my tests with a command in makefile which up my image and run this command
I generally run unit tests on the host before I build Docker containers. I do not include tests inside the image.
gem install bundler:2.2.26
bundle exec rspec
docker build -t myapp:20210824
docker run -d -p 8000:8000 myapp:20210824
In a Makefile context, I'd have these as separate steps, but I would not have these hard depend on each other.
.PHONY: rspec docker-build docker-run
all: rspec docker-build
run: rspec docker-run
DOCKER_TAG := latest
.bundled: Gemfile Gemfile.lock
bundle install
touch "$@"
rspec: .bundled
bundle exec rspec
docker-build: .docker-build
.docker-build:
docker build -t myapp:$(DOCKER_TAG) .
touch "$@"
docker-run: .docker-build
docker run -p 8000:8000 myapp:$(DOCKER_TAG)
clean:
rm -f .bundled .docker-build
Note that this path does not require docker exec or a running container, and you can safely include the spec directory in a .dockerignore file to omit it from the image.