-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
36 lines (30 loc) · 834 Bytes
/
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
# frozen_string_literal: true
namespace :docker do
require 'securerandom'
IMAGE = 'mwpastore/sinja-demo-app'
NAME = SecureRandom.hex(6)
PORT = 4567
def port
%x{
docker inspect --format '{{ (index ( index .NetworkSettings.Ports "#{PORT}/tcp") 0).HostPort }}' #{NAME}
}.chomp
end
task :build do
sh "docker build --build-arg container_port=#{PORT} --no-cache -t #{IMAGE}:latest #{__dir__}"
end
task :test do
sh "docker run --rm -d -P --name #{NAME} #{IMAGE}"
sleep 5
begin
sh "curl -sf -H 'Accept: application/vnd.api+json' -I :#{port}/authors"
ensure
sh "docker stop #{NAME} >/dev/null || true"
end
end
task push: [:build, :test] do
sh "docker push #{IMAGE}:latest"
end
task :run do
sh "docker run --rm -it -p #{PORT}:#{PORT} #{IMAGE}"
end
end