This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
60 lines (50 loc) · 1.51 KB
/
Rakefile
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
# frozen_string_literal: true
# TODO: Dockerfile parser should be used.
def workdir
File.readlines('Dockerfile.dev').each do |line|
return line.split(' ')[1] if line =~ /^WORKDIR /
end
end
def volumes
[
"#{Dir.pwd}:#{workdir}",
"#{ENV['HOME']}/.config/flashcards.yml:#{environment[:FLASHCARDS_CONFIG_FILE]}",
"#{ENV['HOME']}/.local/share/flashcards:#{environment[:FLASHCARDS_DATA_DIR]}",
("#{Dir.pwd}/../refined-refinements:/usr/local/bundle/gems/refined-refinements-0.0.2.3" if File.directory?('../refined-refinements')) # TODO: This should use Gemfile.lock parser to determine the version.
]
end
def environment
{
FLASHCARDS_CONFIG_FILE: '/root/.config/flashcards.yml',
FLASHCARDS_DATA_DIR: '/root/.local/flashcards'
}
end
def docker(command)
command = "docker run --rm #{volumes.map { |v| "-v #{v}" }.join(' ')} #{environment.map { |var, value| "-e #{var}:#{value}" }.join(' ')} -it flashcards:dev #{command}"
puts command; exec command
end
desc "Build Docker image"
task :build do
sh "docker build -t flashcards:dev -f Dockerfile.dev ."
end
desc "Run the container"
task :run do
docker(ARGV[1..-1].join(' '))
end
desc "Run shell within the container"
task :sh do
docker('sh')
end
desc "Run the tests"
task :test do
docker('bundle exec rspec')
end
desc "Run Rubocop"
task :rubocop do
sh "rake run 'bundle exec rubocop --auto-correct'"
end
desc "Delete all the Docker containers and images"
task :prune do
sh "docker rm $(docker ps -a -q)"
sh "docker rmi $(docker images -q)"
end